Sunday, 6 May 2012

Convert videos to VP6 codec format using MENCODER

This post shows how to encode a video file into VP6 codec, using mencoder program.

As a result we will create a FLV (Macromedia flash player) media file (instead of an avi file)

We will get "On2 VP6" video codec driver from a windows dll.

Mencoder is a tool provided by MPlayer to encode movies, and convert between file formats and codecs.


First we obtain mencoder tool.

In debian:
$ sudo aptitude install mencoder

Current mencoder version when this article was written:
Version: 2:1.0~rc4.dfsg1+svn34540-1+b1

Another way to get mencoder could be installing from source code.


Binary codecs come separately from mencoder. We can download them from MPlayer pages:

To see if a codec is supported:

I have an amd64 architecture but I have to download ESSENTIAL CODECS for X86 anyway:
$ wget
$ tar xvjf essential-20071007.tar.bz2

The windows dll we need is this (check it does appear):

Next we place binary codecs in a directory where mplayer or mencoder can access them:
$ sudo mkdir /usr/lib/codecs
$ sudo cp -v essential-20071007/* /usr/lib/codecs/
NOTE: if you installed mplayer from source location could be: /usr/local/lib/codecs


"On VP6 codec" has several configurable options: bitrate, one or two pass, noise reduction, etc.

We are going to compile a windows tool to configure the codec.

This tool comes within mplayer source code:
$ wget
$ tar xvjf mplayer-export-snapshot.tar.bz2

As it is a windows tool and we run a linux based system, wine is needed:
$ sudo aptitude install gcc-4.4 # NOTE: wine compiler complains if gcc version is different from 4.4 for me.
$ sudo aptitude install libwine-dev

$ cd mplayer-export-2012-05-04/TOOLS
$ winegcc vfw2menc.c -o vfw2menc -lwinmm -lole32 # This works in my amd64 architecture.
vfw2menc and executable files will appear.

We execute vfw2menc application to configure the codec:
$ ./vfw2menc -f VP62 -d /usr/lib/codecs/vp6vfw.dll -s onepass.mcf

This will generate a configuration file onepass.mcf

NOTE: Whole path to vp6vfw.dll is needed, if not we get this error:
./ OpenDriver() failed

A dialog window shows:

Select options that suit you:

E.g: bitrate: 300
mode: One pass - best quality

Press OK.

File "onepass.mcf" is now created.


A command like this will do the trick:

$ mencoder source_file.avi -o test.flv -ovc vfw -xvfwopts codec=vp6vfw.dll:compdata=onepass.mcf -oac mp3lame -lameopts cbr:br=64 -af lavcresample=22050 -of lavf -vf yadif,scale=320:240,flip

Lets explain mencoder arguments:

source_file.avi : video source file we are going to convert into VP6 codec.

-o test.flv : mencoder will create test.flv as result file.

-ovc vfw -xvfwopts codec=vp6vfw.dll:compdata=onepass.mcf : video for windows codec and options.
onepass.mcf is the configuration file we just created.

-oac mp3lame -lameopts cbr:br=64 -af lavcresample=22050 : audio codec and options. Some codecs and sample rates are not suited for flv file format.

-of lavf : We create a Macromedia Flash file (flv), instead default avi file.

-vf yadif,scale=320:240,flip : Scale and flip the image, if not we see image upside down.


VP6 codec supports two pass encoding.

We create two configuration files:
$ ./vfw2menc -f VP62 -d /usr/lib/codecs/vp6vfw.dll -s firstpass.mcf
Mode: Two pass - first pass

$ ./vfw2menc -f VP62 -d /usr/lib/codecs/vp6vfw.dll -s secondpass.mcf
Mode: Two pass - second pass - best quality ( or Two pass - second pass - good quality )

Perform first pass encoding:
$ mencoder source_file.avi -o test.flv -ovc vfw -xvfwopts codec=vp6vfw.dll:compdata=firstpass.mcf -oac mp3lame -lameopts cbr:br=64 -af lavcresample=22050 -of lavf -vf yadif,scale=320:240,flip

Two ASCII files will appear by default:
$ ls /tmp

Perform second pass encoding:

$ mencoder source_file.avi -o test.flv -ovc vfw -xvfwopts codec=vp6vfw.dll:compdata=secondpass.mcf -oac mp3lame -lameopts cbr:br=64 -af lavcresample=22050 -of lavf -vf yadif,scale=320:240,flip


$ mplayer -framedrop test.flv
Selected video codec: [ffvp6f] vfm: ffmpeg (FFmpeg VP6 Flash)

FFmpeg is able to reproduce VP6 codec.



Downloading, Compiling and Installing MPlayer on a Ubuntu System

Joining two AVI files with MENCODER

Split a Media Video File (AVI, FLV,...) using Mencoder and Mplayer

0 comentarios: