Monday, February 27, 2012

MEncoder - Hardsubbing Video

MEncoder is an alternative tools for encoding video/audio and it is comparative to ffmpeg.

However, FFMPEG does not have a feature that easily help you on hardsub to video.

There are actually 3 common ways of viewing subtitles

Softsub - With an external subtitle file such as .srt file, you can view your video with a player (such as VLC) and such player will display your subtitle in the .srt file in real time. No external video processing is required

Hardsub - It means that subtitles are burnt into the video. After hardsub is done, you does not need an subtitle file for displaying subtitle. However, external video processing are often required. The video processing usually take a long time due to re-encoding of your video frames.

Subtitle Stream - This mainly applied to mp4 file. This technique actually put subtitles into your file as a separate stream. Certain video player (such as VLC) understand subtitle stream and can display them during playback. While this technique does require external video processing, it is different from Hardsub. Subtitle stream does not involve re-encoding. It is a process of putting the subtitles into the video file container format. Thus, it is way faster than hardsub. Software such as My MP4Box uses this technique.

Since subtitles stream is faster than hardsub, why do we use hardsub? The reason is simple. Not all video player support subtitle stream. Hardsub is supported for all video device as long as it support the video codec that encode the video frames.

Enough to theory, let's go back to MEncoder.

You can get binary source for MEncoder from

Just get the correct version for your PC.

Below is a sample command for encoding your mp4 files with a subtitle file in H.264 baseline profile, level 3.0 and without B-Frame

mencoder.exe "input.mp4" -o "output_with_sub.mp4" -of lavf -oac copy -fafmttag 0x706D -ovc x264 -x264encopts nocabac:level_idc=30:bframes=0:profile=baseline -sub ""

The above command take an input.mp4 (H.264 with AAC) and create an output_with_sub.mp4 with subtitle.rt in H.264 and copy the AAC audio.

Some break down of the above command

-o ---> output file

-oac ---> output audio codec

-ovc ---> output video codec

-x264encopts  ---> x264 encoder option in the format of key:value.

nocabac  ---> No context based adaptive arithmatic coding (iPhone need this)

level_idc=30  ---> H.264 level 3.0 (iPhone only up to level 3.0)

bframes=0  ---> No B-frame. (iPhone does not support B-Frame)

profile=baseline  ---> Force encoder to use baseline profile. (iPhone support baseline profile only)

-sub ---> subtitle file

-of ----> output file format

Note: When copying an AAC audio, mencoder requires you to specify -fafmttag. So far, this setting work for me -oac copy -fafmttag 0x706D

See this for further understanding 

1 comment:

  1. I have no words for this great post such a awe-some information i got gathered. Thanks to Author.
    html5 audio player


PuTTY - Keeping session alive

If you have some VPN tunnels that timeout based on activity, you could try the following setting if you are using PuTTY 1) Open PuTTY and...