Record Video and Audio from WebCam with Mencoder

Sometimes we want to record video and audio from a webcam, in my case I can use my PV-GS39 as a webcam, so when I connect it, my GNU/Linux box create automagically 2 new devices:

  • /dev/video2 This is the v4l device.
  • /dev/dsp1 This is the audio provided by the microphone of the camera.

We can test that this devices work correctly, to do this, we need mplayer and cat. First we test the audio, to do this just take everything that came from cam mic and send to our soundcard:

testmic.sh
cat /dev/dsp1 > /dev/dsp

We can stop the above code by pressing Control + C. Now test the video stuff:

testvid.sh
mplayer tv:// -tv device=/dev/video2

And you can see what your cam views. Remember that /dev/video2 and /dev/dsp1 can be change depending on the machine and the cam, check it before complain about this little doc.

Now, the interesting stuff it's to record everything that came from the cam. To do that we can use mencoder.

The next line must work to record video and audio from your webcam:

record_video_audio.sh
mencoder -tv fps=30:driver=v4l2:buffersize=16:norm=NTSC:input=0:volume=40:amode=1:quality=100:width=320:height=240:device=/dev/video2:adevice=/dev/dsp1:audiorate=44100:immediatemode=0:forceaudio tv:// -o test.avi -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=490:keyint=18 -ofps 13.8 -fps 30 -vf lavcdeint -oac mp3lame -lameopts cbr:br=96:mode=0 -noskip

Yes, a long long long line. But it's easy to understand if you look closer.

…the explanation of the parameters passed to mencoder will be right here soon…

 
 geektips/record_webcam.txt · Last modified: 2010/03/06 19:11 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Driven by DokuWiki