Opened 3 years ago

Last modified 3 years ago

#7596 new enhancement

ffmpeg ignores v4l2 device prefs and selects a non-optimal format

Reported by: Cole Mickens Owned by:
Priority: wish Component: avdevice
Version: unspecified Keywords: v4l2
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no



  1. Set a v4l2 format preference.
  2. Use ffmpeg or mpv to open the v4l2 device.
  3. ffmpeg will use the correct resolution, but incorrect pixelformat

This results in a sub-optimal format being used, resulting in potentially highly unfortunate end-results for the user.


  1. ffmpeg would respect the preferences set for the device in v4l2
  2. ffmpeg would choose the more optimal resolution/format for the best result

In my case, since ffmpeg respects the resolution, but not the pixelformat, it winds up operating at the best 1080p YUYV profile, which is 5FPS. (compare to 1080p MJPEG which is 30FPS).

$ v4l2-ctl -d 4 --set-fmt-video=width=1920,height=1080,pixelformat=1

$ v4l2-ctl -d 4 --get-fmt-video
Format Video Capture:
	Width/Height      : 1920/1080
	Pixel Format      : 'MJPG' (Motion-JPEG)
	Field             : None
	Bytes per Line    : 0
	Size Image        : 4147200
	Colorspace        : sRGB
	Transfer Function : Default (maps to sRGB)
	YCbCr/HSV Encoding: Default (maps to ITU-R 601)
	Quantization      : Default (maps to Full Range)
	Flags             : 

$ mpv av://v4l2:/dev/video4
Playing: av://v4l2:/dev/video4
 (+) Video --vid=1 (rawvideo 1920x1080 5.000fps)
[autoconvert] Converting yuyv422 -> yuv422p
VO: [gpu] 1920x1080 yuv422p
V: 00:00:02 / 00:00:03 (87%)

$ ffmpeg -f v4l2 -i /dev/video4 -c:v copy out.mkv

Input #0, video4linux2,v4l2, from '/dev/video4':
  Duration: N/A, start: 23757.859585, bitrate: 165888 kb/s
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1920x1080, 165888 kb/s, 5 fps, 5 tbr, 1000k tbn, 1000k tbc

$ ffmpeg -f v4l2 -input_format mjpeg -i /dev/video4 -c:v copy out.mkv

Input #0, video4linux2,v4l2, from '/dev/video4':
  Duration: N/A, start: 23792.047911, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj422p(pc, bt470bg/unknown/unknown), 1920x1080, 30 fps, 30 tbr, 1000k tbn, 1000k tbc

Change History (1)

comment:1 by Carl Eugen Hoyos, 3 years ago

Component: undeterminedavdevice
Keywords: v4l2 added
Priority: normalwish
Type: defectenhancement

To make this a valid ticket please test current FFmpeg git head and provide the FFmpeg command line you tested together with the complete, uncut console output.

Note: See TracTickets for help on using tickets.