Recording video from a webcam in Ubuntu


First of all, run this to see what resolutions and frame rates the webcam supports in YUYV (yuyv422) mode:

export GST_DEBUG="*v4l2*:5"
gst-launch-0.10 -v v4l2src num-buffers=1 ! fakesink
export GST_DEBUG=""
For the Logitech Quickcam Pro 9000, for example, this information is in there somewhere:
get frame interval for 800x600, YUYV
adding discrete framerate: 25/1
adding discrete framerate: 20/1
adding discrete framerate: 15/1
adding discrete framerate: 10/1
adding discrete framerate: 5/1
get frame interval for 1600x1200, YUYV
adding discrete framerate: 5/1

To record the video, use this:
ffmpeg -f video4linux2 -s 800x600 -r 25 -i /dev/video0 -vcodec libx264 -cqp 0 out.mp4

Adjust the -s and -r parameters to set appropriate resolution and frame rate, respectively:
ffmpeg -f video4linux2 -s 1600x1200 -r 5 -i /dev/video0 -vcodec libx264 -cqp 0 out.mp4

Increase the -cqp parameter to reduce both quality and output file size.

If necessary, those MP4 files can be edited directly with avidemux.

To record to DV for editing, try this:

ffmpeg \
-f video4linux2 -s 800x600 -r 25 -i /dev/video0 \
-f oss -i /dev/dsp2 \
-s 720x480 -ar 48000 -ac 2 out.dv