Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need ffmpeg to open webcam (logitech c910) in MJPEG mode, because the webcam can give ~24 using MJPEG "protocol" and only ~10 fps using the YUYV. Can i choose between them using ffmpeg command line?

xx@(none) ~ $ v4l2-ctl --list-formats
    Index       : 0
    Type        : Video Capture
    Pixel Format: 'YUYV'
    Name        : YUV 4:2:2 (YUYV)

    Index       : 1
    Type        : Video Capture
    Pixel Format: 'MJPG' (compressed)
    Name        : MJPEG

My current command line:

ffmpeg -y -f alsa -i hw:3,0 -f video4linux2 -r 20 -s 1280x720 -i /dev/video0 -acodec libfaac -ab 128k -vcodec libx264 /tmp/web.avi

ffmpeg produces corrupted h264 stream when i record from webcam, but normal h264 strem when i record from x11grab. Another codecs (mjpeg, mpeg4) works well with webcam... But this is another story.

update Full ffmpeg's console output: (you can see it opens video device in YUV mode, but the device can provide MJPEG outpud also).

share|improve this question
Please add the complete ffmpeg console output. I have an idea of what the issue may be, but it's only a guess without the console output. – LordNeckbeard Oct 28 '12 at 20:23 – pavelkolodin Oct 28 '12 at 21:19
up vote 7 down vote accepted

You can list additional information about what your webcam can output with v4l2-ctl --list-formats-ext. You can also show webcam information with ffmpeg using the -list_formats input option:

$ ffmpeg -f video4linux2 -list_formats all -i /dev/video0
[video4linux2,v4l2 @ 0x1fb7660] Raw       :   yuyv422 :     YUV 4:2:2 (YUYV) : 640x480 160x120 176x144 320x176 320x240 352x288 432x240 544x288 640x360
[video4linux2,v4l2 @ 0x1fb7660] Compressed:     mjpeg :                MJPEG : 640x480 160x120 176x144 320x176 320x240 352x288 432x240 544x288 640x360

This webcam from my example can support both a raw and compressed format, and you can tell ffmpeg which one you want with the -input_format input option. This example will copy the video stream (no re-encoding):

ffmpeg -f video4linux2 -input_format mjpeg -i /dev/video0 -c:v copy output.mkv

See the video4linux2 input device documentation for other options.

As for your command I recommend adding -pix_fmt yuv420p as an output option. Otherwise ffmpeg may select 4:2:2 as shown in your output and I don't know any non-FFmpeg based players that can handle that.

See the FFmpeg and x264 Encoding Guide, specifically the CRF section, if you want to adjust the output quality.

Do not use AVI as an output container format when encoding to H.264 that contains b-frames. MP4 or MKV (Matroska) are better choices.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .