Skip to content

Preparing multibitrate files

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

The following contains detailed instructions on adaptive streaming setup and multi-bitrate file creation.

Installing tools

It is necessary to install ffmpeg and codecs. Note that the installation process differs depending on your OS.

Installation instructions for Windows

  1. Download ffmpeg from https://ffmpeg.org/download.html
  2. Follow the installation guide.
  3. Download and install K-Lite Mega Codec Pack:

http://www.codecguide.com/download_k-lite_codec_pack_mega.htm 4. Once the installer launches, select the fullest complete installation option ("Lots of stuff").

In case you have Windows 8.1, it is necessary to perform the following:

  1. Press the Windows + Pause key combination.
  2. Click on the Advanced system settings.
  3. Click on the Environment Variables button.
  4. Proceed to the System Variables.
  5. Find the Path line.
  6. Insert C:\ffmpeg;C:\ffmpeg\bin; to the beginning of the value.

Installation instructions for Ubuntu Linux

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 using ffmpeg from your Linux distro. It could be too old for transcoding h264, too old to work with our guides (or any other guides that rely on modern ffmpegs), or some other issues may occur.

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

Constructing an ffmpeg command to get multi-bitrate video

Suppose you have a video file h.m4v with two audio tracks (English and Russian) and two sets of subtitles (e.g., English and Russian).

First of all, you'll want to find out what streams this file contains. To do this, type in the console:


ffmpeg -i h.m4v

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


 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 (e.g., eng and rus).

Your target file, which is intended for adaptive bitrate streaming, should have the same stream structure with more video streams. For example, it must have 3 different video quality options to choose from.

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

The following example showcases the ffmpeg command construction process.

The first line should look like this:


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

Note that the \ symbol in Linux represents the line feed. For Windows, it is necessary to use the ^ symbol. Thus, the line should look like this:


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

By executing this command, you will convert a file found at the address that is specified after the -i key.

The following explains how to export the streams to the output video file. For instance, the 0:0 stream needs to be converted to 3 video streams of different quality. Hence, the command line should look like this: -map 0:0 -map 0:0 -map 0:0 — in case you want to take the same 0:0 stream three times. Each of the remaining streams (0:1, 0:2, 0:3, 0:4) simply needs to be copied once. Thus, the command line should look like this: -map 0:1 -map 0:2 -map 0:3 -map 0:4.

Altogether, the command should look like :


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

The following showcases how you can take care of encoding.

Important: Note that the original file contains video and audio streams with the same set. However, further on, each stream type will have its own number starting from 0. For instance, v:0 represents the first video, while a:1 represents the second audio.

-c:v:0 libx264 -b:v:0 1800k -metadata:s:v:0 language=eng \ — captures the first video stream, encodes it to x264 with the bitrate of the source file, and marks its language as English.

-c:v:1 libx264 -b:v:1 150k -metadata:s:v:1 language=eng \ — captures the second video stream, encodes it to x264 with the bitrate 150k, and marks its language as English.

-c:v:2 libx264 -b:v:2 100k -metadata:s:v:2 language=rus \ — captures the third video stream, encodes it to the bitrate 100k, marks its language as Russian.

You must re-encode not only additional tracks, but also the original track. So that they are synchronized, with the identical GOP structure, which is essential for adaptive streaming.

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.

These commands 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 \

Hence, your command lines should look like this:


ffmpeg -i "/home/user/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 libx264 -b:v:0 1800k -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 \

Use the following command to specify the synchronization options and the target file to write the encoded video to:

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

Altogether, the command should look like this:


ffmpeg -i "/home/user/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 libx264 -b:v:0 1800k -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/user/temp/h2.m4v"

Below is one more example of creating a multi-bitrate file using ffmpeg, for a file bunny.mp4:

ffmpeg -i bunny.mp4 \
-map 0:0 -c:v copy \
-map 0:0 -c:v libx264 -b:v 150k  \
-map 0:0 -c:v libx264 -b:v 100k \
-map 0:1 -c:v libx264 -b:v 50k \
-map 0:1 -c:a copy \
-map 0:1 -c:a copy \
-y out.mp4

Encoding a video segment

Sometimes you need to encode only a specific segment of your video stream. To do this, use the following parameters: -ss 00:00:00 -t 00:05:00. The value of the ss parameter specifies the start of the segment in seconds. The value of the t represents the segment's duration.

These parameters can be used with other commands. For instance:


ffmpeg -i "/home/user/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 libx264 -b:v:0 1800k -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/user/temp/h2.m4v"

This is the aforementioned encoding command, but applied only to the first 5 seconds of the video clip.

Changing resolution for video streams with lowered bitrate

Sometimes, you might need to lower the resolution of the video stream along with the bitrate. To do this, use the following parameter: -filter:v:3 scale=320:240 It should be added to the stream-specific line of your command (the same way as with the bitrate and subtitles in the previous examples).

"-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.

The following showcases how to use this parameter. For example, it is necessary to take the command lines from the previous examples and add the fourth video stream ("-c:v:3") with the resolution width 320 ("scale=320:-1"). Thus, you should put "-map 0:0" four times, which corresponds to four video streams.


ffmpeg -i "/home/user/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 libx264 -b:v:0 1800k -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/user/temp/h2.m4v"

Converting files for web streaming

Flussonic supports the following Containers and codecs. If your video file is encoded with a different codec, it will not play via Flussonic. For example, the file might have an old codec like Xvid or MPEG4-Video that is no longer supported by new versions of browsers. In such cases, file transcoding is required.

To convert any file to H.264, in the console change the directory to where you've put this file, and run the command:

ffmpeg -i input_file.avi -c:v libx264 -g 100 -c:a aac -f mp4 output_file.mp4

Similarly, to convert any file to H.265/HEVC:

ffmpeg -i input_file.avi -c:v libx265 -g 100 -c:a aac -f mp4 output_file.mp4