I need ffmpeg to open webcam (Logitech C910) in MJPEG mode, because the webcam can give ~24 fps using the MJPEG "protocol" and only ~10 fps using the YUYV. Can I choose between them using the 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: http://pastebin.com/Hzem6CKF (you can see it opens video device in YUV mode, but the device can provide MJPEG outpud also).


2 Answers 2


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 raw (yuyv422) and compressed (mjpeg) formats, and you can tell ffmpeg which one you want with the -input_format input option.


Stream copy the MJPEG video stream (no re-encoding):

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

Re-encode the raw webcam video to H.264:

ffmpeg -f v4l2 -input_format yuyv422 -i /dev/video0 -c:v libx264 -vf format=yuv420p output.mp4

Same as above but manually choose frame rate and video size (v4l2-ctl --list-formats-ext for available frame rate and video sizes):

ffmpeg -f v4l2 -input_format yuyv422 -framerate 30 -video_size 640x480 -i /dev/video0 -c:v libx264 -vf format=yuv420p output.mp4
  • See the video4linux2 input device documentation for more options.

  • If the frame rate being output is lower than expected then add more light: the webcam may be lowering the frame rate to get longer exposures in a dim environment.

ffmpeg -t 60 -f video4linux2 -input_format mjpeg -i /dev/video0 -c:v libx264 -strict -2 /DataVolume/share/Public/v/outputs.mp4
  • 4
    Welcome to Super User! Can you expand on this? In particular, what information does it have that LordNekbeard's doesn't? :)
    – bertieb
    Commented Apr 16, 2018 at 12:00
  • No need for -strict -2 unless: 1) your ffmpeg is horribly outdated, and 2) you are encoding AAC audio.
    – llogan
    Commented Apr 16, 2018 at 18:06

You must log in to answer this question.

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