Encoding - Mencoder, FFmpeg, x264, Vorbis, Webm

Nigtly Builds : - http://firefogg.org/nightly/


First Pass:
mencoder -ovc x264 -x264encopts bitrate=700:me=umh:partitions=all:subq=6:frameref=5:8x8dct:bframes=3:b_pyramid:weight_b:pass=1 -o /dev/null -nosound /mnt/win_e/Entertainment/Movies/new/Malayalam/Rakilipatte/cd2_5.avi

Second Pass
mencoder -ovc x264 -x264encopts bitrate=700:me=umh:partitions=all:subq=6:frameref=5:8x8dct:bframes=3:b_pyramid:weight_b:pass=2 -oac mp3lame -lameopts mode=3:vbr=3:br=96 /mnt/win_e/Entertainment/Movies/new/Malayalam/Rakilipatte/cd2_4.avi -o 2_5.avi

use "-srate 44100" if requied

Single Pass encoding:
C:\Program Files\MediaCoder\codecs\mencoder.exe" -ovc x264 -x264encopts crf=26:me=umh:partitions=all:subq=6:frameref=5:8x8dct:bframes=3:b_pyramid:weight_b -o output.avi -oac mp3lame -lameopts
mode=3:vbr=3:br=96 -srate 44100 "f:\randaraMaasam 123.avi"

Screen Capture.
XVidCap Screen Capture is used for taking sequence of screen dump (*.xwd) files
first these files are converted to png format. like:

convert img_*.xwd img_%04d.png && rm -rf ./*.xwd

Then all these are encoded to form the .avi file like
mencoder "mf://*.png" -mf fps=4 -ovc copy -o ./video.avi

Multipluxing video and audio file
mencoder <videofile> -audiofile <audiofile> -ovc copy -oac copy -o <outputfile>

synchonize audio and video using delay

use mkvmerge to mix audio track. use -A to remove audio from the file.
mkvmerge -o movie.mkv -A movie.avi audio-q3.ogg

extract/dump track
Windows : mencoder vcd://2 -cdrom-device h:/ -ovc copy -oac copy -o c:\srirkish2.avi
Linux : mplayer vcd://2 -cdrom-device /dev/hdc

dumping to file:
mplayer dvd://1 -dumpstream -dumpfile track1.vob
Windows: mplayer dvd://2 -dvd-device g:/ -dvd 1 -dumpstream -dumpfile track1.vob
(here dvd://2 says that use second track, windows drive is g: and -dvd title is 1)
for further reference

extracting only a particular audio track
mplayer ${RIPPATH}movie.vob -aid ${AID} -dumpaudio -dumpfile ${RIPPATH}audio${AID}.ac3
ffmpeg -i MVI_6146.AVI -vn -acodec copy test.wav

FFMpeg Encoding:
"C:\ffmpeg\ffmpeg.exe" -i "C:\Temp\randaraMaasam122.avi" -vcodec libx264 -flags +loop -g 250 -crf 26 -refs 6 -bf 3 -me_method umh -coder 1  -subq 6 -partitions +parti4x4+parti8x8+partp8x8+partb8x8 -flags2 +bpyramid+wpred+mixed_refs+dct8x8 "C:\randaraMaasam122.mp4"

docoumenation at http://ffmpeg.x264.googlepages.com/ found very useful, infact i used this information to arrive at above settings.

In above case, audio is left to default. but you can specify it as below.

C:\ffmpeg\ffmpeg.exe -i "C:\Temp\randaraMaasam122.avi" -vcodec libx264 -flags +loop -g 250 -crf 26 -refs 6 -bf 3 -me_method umh -coder 1  -subq 6 -partitions +parti4x4+parti8x8+partp8x8+partb8x8 -flags2 +bpyramid+wpred+mixed_refs+dct8x8 -acodec libvorbis -aq 0 "C:\Desktop\randaraMaasam122.mp4"

if you want your audio in FAAC, replace libvorbis with libfaac. thats it.

you can remove the sub title traks by adding one more parameter like : -sn

i don't care about the time it takes to encode but size and quality matters.

ffmpeg.exe -i "C:\Temp\randaraMaasam122.avi" -vcodec libx264 -flags +loop -g 250 -crf 26 -refs 6 -bf 16 -b_strategy 2-me_method umh -coder 1  -subq 6 -partitions +parti4x4+parti8x8+partp8x8+partb8x8 -flags2 +bpyramid+wpred+mixed_refs+dct8x8 -acodec libfaac -aq 0 "C:\randaraMaasam122.mkv"

ffmpeg can be used along with libtheora also. but i could not get much chance to work extensively on this.
c:\Softwares\FFmpeg\ffmpeg.exe -i P1030356.MOV -vcodec libtheora -g 250 -acodec libvorbis -aq 0 P1030356.mkv

ffmpeg can be used to dump vob files.
c:\Softwares\ffmpeg.exe -i D:\VIDEO_TS\VTS_01_1.VOB -f avi -acodec libmp3lame -ab 128k -vcodec copy cd2_1.avi

new versions of ffmpeg is found brocken for many parameters for libx264 where you may have to pass full set of parameters like:
ffmpeg -i <inputfile> -vcodec libx264 -crf 26  -flags +loop -g 250 -refs 6 -bf 16 -b_strategy 2 -me_method umh -coder 1  -subq 6 -partitions +parti4x4+parti8x8+partp8x8+partb8x8 -flags2 +bpyramid+wpred+mixed_refs+dct8x8 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 -directpred 1 -flags2 +fastpskip -dts_delta_threshold 1  -acodec libvorbis -aq 0 <outputfile>

To extract a portion, we can use -ss and -to
ffmpeg -i KathiruKathiru.mp4 -ss 0 -to 1:20  KathiruKathiru.mp3

a good reference of ffmpeg is available here : http://howto-pages.org/ffmpeg/

Expert Mode: Using x246 directly.
many times you may not have the latest FFMpeg compiled with latest libraries or you may want to use advanced feature/tweekings available only in the encoder libary not in FFmpeg.
in that case swith to expert mode yourself :).
here you can use the tools like x264 directly to encode the video and oggenc to encode the audio,

1. Extract the Video and Audio to seperate files.
mplayer -ao null -nosound -vo yuv4mpeg file.avi 
//this extract the video to stream.yuv file.

or do it in a single shot
mplayer  -ao pcm -vo yuv4mpeg 1.avi
now 2 files will be generated like audiodump.wav and stream.yuv
for extrating a specific pice use -ss end -endpos options.

use deinterlacing filter like
-vf pp=fd 
when the input is DVD or other source where interlacing creates horizontal lines.

but this may not work as you expect, so better i suggest phantom edit feature using Edit Decision List (or EDL) of Mplayer. See highlighted below
mplayer -edl edl.txt MVI_6179.AVI -ao pcm:file=in.wav -vo yuv4mpeg:file=in.y4m

or you can keep the output into specific files instead of default files like in.wav and in.yuv
mplayer -ao pcm:file=in.wav -vo yuv4mpeg:file=in.y4m input.avi

2. Encode the video using your favorite tool (to favorite format)
x264 in.y4m --crf 26 --ref 6  -o test.mkv
or in more expert mode
x264 in.y4m --crf 26 --ref 6 --mixed-refs 1 --bframes 3 --b-pyramid 1 --weightb 1 --subme 7 trellis 2 --analyse all --8x8dct 1 --no-fast-pskip 1 --no-dct-decimate 1 --me umh --merange 64 --filter -2,-1 --direct auto -o test.mkv
or in a simpler way
x264 in.y4m --crf 26 --profile high --preset placebo -o test.mkv
for further reading, please refer wiki

3. Encode the audio also to desired format.
oggenc --managed -q -1 in.wav

4. merge the video and audio using merge tool
mkvmerge -o out.mkv test.mkv in.ogg

so in windows i created a bat file with above lines and attached below. get it

using ffmpeg2theora
ffmpeg2theora -K 250 -v 3 --optimize -a 0 P1030356.MOV
ffmpeg2theora -K 250 --two-pass --soft-target -V 1024 -v 3 --optimize -a 0 input.avi

using theora sample encoder
~/theora/examples/.libs/encoder_example in.y4m -o in.ogv

oggenc.exe "Thalamayanju Ganamapoornam 2.wav" -q 0

Audio conversion using FFmpeg:
ffmpeg.exe -i c:\Awakening.wma c:\Awakening.mp3

Converting audio to opus
ffmpeg -i mazhaneer.mp3 -acodec libopus mazhaneer.ogg

Comparision of Mencoder and FFmpeg
FFmpeg offers more control over the settings. for example using FFmpeg you can directly put the output into a .mkv container
but mencoder offers only avi container. this is a big shortcoming.

creating webm video:

Jobin Augustine,
Jul 14, 2009, 5:24 AM