wiki:Smooth-Streaming-Encoding

Encoding Smooth Streaming videos

back


Encoding multi bit rate H264 video with X264

The important part when generating multiple bit rate video files is that the chunks need to be aligned on exactly the same (key-)frames. The X264 encoder provides a two-pass encoding option. The output of the first pass is used for all the second pass encodings, this way we make sure that the keyframes are aligned.

A good balance between efficiency and switching latency is to insert keyframes every 2 seconds (--min-keyint) with a maximum of 4 seconds (--keyint).

Our demo video is Blender's Big Buck Bunny. The original movie is 1920 x 1080 (1080p / full HD) and using the Smooth Streaming Multi-Bitrate Calculator gives us the following table:

Bit rate (Kbps)Resolution
45001920 x 1080
20081096 x 616
896624 x 352
400356 x 200

The example below generates 4 encodings in 4500, 2008, 896 and 400 Kbps.

set X264_OPTIONS=--progress --threads 4 --min-keyint 50 --keyint 100 --bframes 0
x264 %X264_OPTIONS -o bbb_4500000.mp4 --pass 1 --bitrate 4500 bbb0.avs
x264 %X264_OPTIONS -o bbb_4500000.mp4 --pass 2 --bitrate 4500 bbb0.avs
x264 %X264_OPTIONS -o bbb_2008000.mp4 --pass 2 --bitrate 2008 bbb1.avs
x264 %X264_OPTIONS -o bbb_896000.mp4 --pass 2 --bitrate 896 bbb2.avs
x264 %X264_OPTIONS -o bbb_400000.mp4 --pass 2 --bitrate 400 bbb3.avs

The input files are AVISynth scripts. The first bbb0.avs script loads the video, the second bbb.avs script rescales the video to a lower resolution, the third bbb.avs rescales the video even further, etc...

bbb1.avs

QTInput("big_buck_bunny_1080p_h264.mov", audio=false)
BicubicResize(1096, 616)
ConvertToYV12()

Thanks to Dark Shikari for the two pass idea.

Deploying and generating the manifest

Deploying the video consists of two steps. First we simply copy the video files to the directory 'bbb.ism' in the webserver's document root and rename the extension from '.mp4' to '.ismv'.

The second step is to generate the manifest file.

mp4split -i "$(DOCUMENT_ROOT)/bbb.ism/manifest" -o "$(DOCUMENT_ROOT)/bbb.ism/manifest"

Smooth Streaming and B-Frames

The current version of the Fragmented MP4 Parser Implementation (you can find it in the Microsoft Expression Encoder SP1 template SL2Standard) ignores the 'sample-composition-time-offset' field in the 'trun' atom. Unfortunately that means that video files using B-frames are not decoded correctly. This will be fixed in the next release of the parser.

Next

Last modified 13 years ago Last modified on 06/19/09 14:02:07