Archived:MEncoder-V4L

From LinuxTVWiki
Revision as of 00:24, 16 April 2006 by Liontooth (talk | contribs) (Useful guides)
Jump to: navigation, search

Useful guides

Mencoder usage on a slow x86

This is the command line I use for recording PAL (UK), using a simple capture card, and an old PC (PIII 700mhz):

 sudo nice --10 mencoder tv:// -v -tv \
 driver=v4l2:width=576:height=576:input=1:device=/dev/video0:immediatemode=0:forceaudio:outfmt=yv12 \
 -o outfile.avi -ovc lavc -lavcopts vcodec=mjpeg:aspect=4/3 -aspect 4:3 -noautoexpand -oac pcm \
 -endpos 00:30:00

I use sudo to ensure that the recording process gets priority over most other processes (via the nice --10). The width of 576 is the maximum that my box can process without dropping frames. The width isn't as important as the height, as the capture card should be able to convert it from 768 -> 576 without losing quality. All the options used are tuned for speed, without dropping too much quality.

If this still takes more cpu speed than you've got, but you've got lots of disk space, you can capture the raw video and uncompressed audio. Substitute these options:

-ovc raw -vf format=yv12 -oac pcm

Once captured I re-encode, as mjpeg with the above options will use around 4gig of disk space per hour of recording. Here's the re-encode line I use, but you'll probably want to play around with it to get what you want. This part of the process can take as long as necessary, and typically takes my box about 16 hours to process a 2 hour plus capture (with a double pass):

 nice -+19 mencoder infile.avi -ffourcc DIVX -noskip -ovc lavc \
 -lavcopts vcodec=mpeg4:vbitrate=1000:mbd=1:v4mv:dia=4:vqmin=2:vqmax=31:vpass=1:turbo:aspect=4/3 \
 -aspect 4:3 -sws 10 -vf crop=560:560:12:8,scale=800:-2,denoise3d,harddup \
 -oac mp3lame -lameopts cbr:br=128:mode=0 -o /dev/null
 nice -+19 mencoder infile.avi -ffourcc DIVX -noskip -ovc lavc \
 -lavcopts vcodec=mpeg4:vbitrate=1000:mbd=1:v4mv:dia=4:vqmin=2:vqmax=31:vpass=2:aspect=4/3 \
 -aspect 4:3 -sws 10 -vf crop=560:560:12:8,scale=800:-2,denoise3d,harddup \
 -oac mp3lame -lameopts cbr:br=128:mode=0 -o outfile.new.avi

By using 2 passes I get the quality as good as the above options allow, however mencoder allows you to make as many passes as you see fit (vpass=3). Your crop= and scale= parameters will probably be different to mine, as you should crop the black bars at the top/bottom and sides of your captured image. A good way of finding out what crop= options to use is:

 mplayer -ss 60 -vf cropdetect

This starts viewing at the 60 second mark, and outputs to the terminal the crop= parameters required:

 crop area: X: 7..575  Y: 72..503  (-vf crop=560:432:12:72) ??,?% 0 0 86%

For more advice on using mencoder I recommend taking a look at the Encoding with MEncoder chapter in the MPlayer - The Movie Player documentation (other languages are available).

Pete J


Specifying an ALSA device other than default

To determine which sound devices you have on your system, use

 cat /proc/asound/pcm

The devices you can use for capture will have the word "capture" in their description. Note that you will have to "mangle" the device name in order for mencoder to accept it: since the tv:// options in mencoder are separated by colons, you can't call a PCM device hw:1.0 - the correct form is

  adevice=hw.1,0

--Matija 13:22, 28 February 2006 (CET)


Correcting NTSC framerate

In some recent versions of mencoder, the default framerate for ntsc with the following command comes out as 29 instead of 29.97:

 mencoder -tv driver=v4l2:width=720:height=480:norm=ntsc -ovc lavc -lavcopts vcodec=mpeg4:vhq -oac mp3lame \
 -lameopts cbr:br=128 -endpos 30 -o outfile.mpg tv:// > /dev/null

This is using Christian Marillat's unofficial package of mencoder for Debian amd64, mencoder_1.0-pre7-0.0_amd64.deb and may or may not apply to other versions.

The fact that the framerate is slightly off is not noticeable in playback, and has been the case for at least three months, from January 2005. What is new is that the latest mencoder version usefully reports "Skipping frame!" once a second during recording. The workaround is to set the framerate explicitly with -fps 29.97.

In addition, in the most recent version of mencoder, the default codec for mpeg is FMP4, while it used to be DIVX. To reset it to DIVX, use the -ffourcc DIVX option.

The full command gives great results as before, overriding the poor defaults:

 mencoder -tv driver=v4l2:width=720:height=480:norm=ntsc -ffourcc DIVX -fps 29.97 -ovc lavc \ 
 -lavcopts vcodec=mpeg4:vhq -oac mp3lame -lameopts cbr:br=128 -endpos 30 -o outfile.mpg tv:// > /dev/null

For unofficial packages of mencoder for Debian, see Christian Marillat's Debian Repositories.

I don't have a TV card on a x86 machine or other platforms and can't report on whether the same tweaks are required there.

Dave