Flussonic Media Server documentation

Transcode files

Adaptive bitrate streaming ensures good viewing experience for users with different connection speeds. In order to set up adaptive streaming, you will need to create a multi-bitrate mp4 file and request a manifest file for it. Flussonic will do the rest.

See below for detailed instructions on adaptive streaming setup and multi-bitrate file creation.

Installing utilities Anchor Anchor x2

You will need to have ffmpeg and codecs installed. The installation process differs from OS to OS.

Installation instructions under Windows Anchor Anchor x2

First, download ffmpeg from http://ffmpeg.zeranoe.com/builds/ and unpack, for instance, to C:\ffmpeg. Next, add new directories (in our example, C:\ffmpeg and C:\ffmpeg\bin) to the system path.

In Windows 8.1, press Windows+Pause, click Advanced system settings, push the Environment Variables button, then in the System Variables pane find the Path line and insert С:\ffmpeg;С:\ffmpeg\bin; at the beginning of the value.

Then download and install K-Lite Mega Codec Pack: http://www.codecguide.com/download_k-lite_codec_pack_mega.htm Once the installer launches, select the fullest complete installation option ("Lots of stuff").

Installation instructions under Ubuntu Linux Anchor Anchor x2

We recommend to use pre-built ffmpeg from this site: http://johnvansickle.com/ffmpeg Or any other pre-built binary from the official web site: https://www.ffmpeg.org/download.html

We don't recommend ffmpeg from your Linux distro, because usually it's too old for transconding h264, or too old to work with our guides (or any other guides that rely on modern ffmpegs), or there is still some other trouble.

Once the codecs installation is complete, your computer is ready to encode video.

Constructing a ffmpeg command Anchor Anchor x2

Let's say you have a video file h.m4v with two audio tracks (English and Russian) and two sets of subtitles (also English and Russian).

First you need to find out what streams the file contains. To this end, type in the console:

ffmpeg -i h.m4v

You will get a screenful of text, but the part you are looking for is this:

 Stream #0:0(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1331:1000 DAR 2662:1125], 1800 kb/s, 23.98 fps, 23.98 tbr, 25k tbn, 180k tbc
    Metadata:
      creation_time   : 2013-01-14 14:46:26
      handler_name    :
    Stream #0:1(rus): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, s16, 127 kb/s
    Metadata:
      creation_time   : 2013-01-14 14:47:59
      handler_name    :
    Stream #0:2(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, s16, 127 kb/s
    Metadata:
      creation_time   : 2013-01-14 14:48:19
      handler_name    :
    Stream #0:3(rus): Subtitle: mov_text (tx3g / 0x67337874)
    Metadata:
      creation_time   : 2013-01-14 14:48:38
      handler_name    :
    Stream #0:4(eng): Subtitle: mov_text (tx3g / 0x67337874)
    Metadata:
      creation_time   : 2013-01-14 14:48:38
      handler_name    :

Each stream section displays a stream number (0:0,0:1,0:2,0:3,0:4), stream type (video, audio, subtitles) and language (in our example, eng and rus).

The file you will create will have the same stream structure with more video streams. Let's say the video file you need should have 3 different video quality options to choose from.

3 video streams + 2 audio streams + 2 subtitle streams = 7 streams total.

Now, let's construct the command for ffmpeg.

The first line would be:

ffmpeg -i "/home/olegchir/temp/h.m4v" \

Note the \ symbol. Under Linux, this is line feed. In Windows, the ^ symbol is used, so the line should look like this:

ffmpeg -i "/home/olegchir/temp/h.m4v" ^

This entire line means that you are going to convert the file found at the address specified after the -i key.

Next, you must export the streams to the resulting video file. The 0:0 stream needs to be converted to 3 video streams of different quality. The code to enter is: -map 0:0 -map 0:0 -map 0:0 - that is, you are taking the 0:0 stream three times. Each of the remaining streams (0:1, 0:2, 0:3, 0:4) simply needs to be copied over once. So enter the following: -map 0:1 -map 0:2 -map 0:3 -map 0:4.

Together the first two lines should look like this:

ffmpeg -i "/home/olegchir/temp/h.m4v" \
-map 0:0 -map 0:0 -map 0:0 -map 0:1 -map 0:2 -map 0:3 -map 0:4 \

Next, you need to take care of encoding.

Important note: while within the original file all streams of different types have similar designations (video and audio are parts of the same set), further on each stream type has its own ordinal sequence starting from 0. That is, the first video stream is designated as v:0, and the second audio would be a:1.

-c:v:0 copy -metadata:s:v:0 language=eng \ - take the first video stream, copy as is and mark its language as English -c:v:1 libx264 -b:v:1 150k -metadata:s:v:1 language=eng \ - take the first video stream, encode as x264 with the bitrate 150k, mark its language as English -c:v:2 libx264 -b:v:2 100k -metadata:s:v:2 language=eng \ - the same as the previous but with the bitrate 100k

If you put copy on the 2nd position (after specifying the stream), no encoding is taking place and the stream gets copied over as is. Copy all audio and video without changes:

-c:a:0 copy -metadata:s:a:0 language=rus \
-c:a:1 copy -metadata:s:a:1 language=eng \
-c:s:0 copy -metadata:s:s:0 language=rus \
-c:s:1 copy -metadata:s:s:1 language=eng \

Your command should look like this:

ffmpeg -i "/home/olegchir/temp/h.m4v" \
-map 0:0 -map 0:0 -map 0:0 -map 0:1 -map 0:2 -map 0:3 -map 0:4 \
-c:v:0 copy -metadata:s:v:0 language=eng \
-c:v:1 libx264 -b:v:1 150k -metadata:s:v:1 language=eng \
-c:v:2 libx264 -b:v:2 100k -metadata:s:v:2 language=eng \
-c:a:0 copy -metadata:s:a:0 language=rus \
-c:a:1 copy -metadata:s:a:1 language=eng \
-c:s:0 copy -metadata:s:s:0 language=rus \
-c:s:1 copy -metadata:s:s:1 language=eng \

Now specify the synchronization options and the target file to write the encoded video to:

-async 1 -vsync 1 \
"/home/olegchir/temp/h2.m4v"

All together, the command should look like this:

ffmpeg -i "/home/olegchir/temp/h.m4v" \
-map 0:0 -map 0:0 -map 0:0 -map 0:1 -map 0:2 -map 0:3 -map 0:4 \
-c:v:0 copy -metadata:s:v:0 language=eng \
-c:v:1 libx264 -b:v:1 150k -metadata:s:v:1 language=eng \
-c:v:2 libx264 -b:v:2 100k -metadata:s:v:2 language=eng \
-c:a:0 copy -metadata:s:a:0 language=rus \
-c:a:1 copy -metadata:s:a:1 language=eng \
-c:s:0 copy -metadata:s:s:0 language=rus \
-c:s:1 copy -metadata:s:s:1 language=eng \
-async 1 -vsync 1 \
"/home/olegchir/temp/h2.m4v"

Encoding a video segment Anchor Anchor x2

Sometimes you need to encode only a specific segment of your video stream. To this end, the following parameters are used: -ss 00:00:00 -t 00:05:00. The fist number (the value of ss) specifies the start of the segment in seconds. The second number gives the segment's duration.

These parameters can be combines with many others. For instance:

ffmpeg -i "/home/olegchir/temp/h.m4v" \
-ss 00:00:00 -t 00:05:00 \
-map 0:0 -map 0:0 -map 0:0 -map 0:1 -map 0:2 -map 0:3 -map 0:4 \
-c:v:0 copy -metadata:s:v:0 language=eng \
-c:v:1 libx264 -b:v:1 150k -metadata:s:v:1 language=eng \
-c:v:2 libx264 -b:v:2 100k -metadata:s:v:2 language=eng \
-c:a:0 copy -metadata:s:a:0 language=rus \
-c:a:1 copy -metadata:s:a:1 language=eng \
-c:s:0 copy -metadata:s:s:0 language=rus \
-c:s:1 copy -metadata:s:s:1 language=eng \
-async 1 -vsync 1 \
"/home/olegchir/temp/h2.m4v"
This is the encoding command discussed earlier, but applied only to the first 5 seconds of the video clip.

Changing resolution for video streams with lowered bitrate Anchor Anchor x2

Sometimes you might need to lower the resolution of the video stream along with the bitrate. The following parameter does this job: -filter:v:3 scale=320:240 It should be added to the stream-specific line of code the same way as with the bitrate and subtitles in the previous examples.

Let's see in detail what is going on here. "-filter" means a certain filter is going to be specified, ":v:3" is the number that the video stream will be designated once it gets new resolution, "scale" is the name of the filter (ffmpeg supports various filters; this particular one changes resolution), "320:240" is the new resolution. Note that if we know the desired width, the height can be specified simply as -1, i. e., "320:-1". This keeps the ratio automatically.

Now let's see what it looks like in reality. Take the code from the previous examples and add the fourth video stream ("-c:v:3") with the resolution width 320 ("scale=320:-1"). Note that now you need to write "-map 0:0" four times because you have four video streams.

ffmpeg -i "/home/olegchir/temp/h.m4v" \
-ss 00:00:00 -t 00:05:00 \
-map 0:0 -map 0:0 -map 0:0 -map 0:0 -map 0:1 -map 0:2 -map 0:3 -map 0:4 \
-c:v:0 copy -metadata:s:v:0 language=eng \
-c:v:1 libx264 -b:v:1 150k -metadata:s:v:1 language=eng \
-c:v:2 libx264 -b:v:2 100k -metadata:s:v:2 language=eng \
-c:v:3 libx264 -b:v:3 100k -metadata:s:v:3 language=eng -filter:v:3 scale=320:-1 \
-c:a:0 copy -metadata:s:a:0 language=rus \
-c:a:1 copy -metadata:s:a:1 language=eng \
-c:s:0 copy -metadata:s:s:0 language=rus \
-c:s:1 copy -metadata:s:s:1 language=eng \
-async 1 -vsync 1 \
"/home/olegchir/temp/h2.m4v"