Webcam recording and mencoder

It is really hard to find proper arguments of mencoder to record not only image, but also sound. Here is my solution. Forcechan=2 is a key.

mencoder tv:// -tv \
-ofps 15 -oac mp3lame -lameopts cbr:br=32 -ovc lavc -lavcopts \
vbitrate=92 -o ./encoded.avi

This code works on Linux Ubuntu Feisty Fawn 7.04 with Linux4Video v1 with sound from SoundBlaster Live! with ALSA (on /dev/dsp) with standard recording settings in ALSA mixer (Mic is capturing). ~/.mplayer/mencoder.conf is empty. Kernel module is gspca compiled on my own from the freshest source and copied into directory of original Ubuntu's gspca.ko (/lib/modules/2.6.22-14-generic/ubuntu/media/gspcav1/gspca.ko)
You can change framerate up to 25, video bitrate to 800 and sound bitrate to 128 or greater to get excellent quality.
VLC is quite good too, but only for network streaming. Recording to local file causes lack of audio-video synchronisation.
According to VLC manual you can run it from command line as follow:

vlc v4l:// :v4l-vdev="/dev/video0" :v4l-adev="/dev/dsp" \ :v4l-norm=3 :v4l-frequency=-1 --sout \ '#transcode{vcodec=mp4v,acodec=mpga,vb=800,ab=128}:standard{access=http,mux=ogg,dst=}'

where all v4l are video and audio sources and sout is output stream. transcoding is definition how to change stream's encoding from source's format to desired, chosen by you.
Much more options on VLC site.

Leave VLC and use ffmpeg :-)

For MPEG-2 clips type:

mencoder tv:// -tv \
driver=v4l:device=/dev/video0:width=320:height=240:adevice=/dev/dsp:forceaudio:forcechan=2 \
-of mpeg -ofps 15 -oac mp3lame -lameopts cbr:br=64 -ovc lavc \
-lavcopts vcodec=mpeg2video:vbitrate=512:aspect=320/240 -o ./encoded.mpeg

-of sets output format, default AVI.

To set limited recording time add to the command -frames xxx, where xxx is number of seconds x fps (15 in this case): -frames 900 for one minute clip.

No comments: