List V4L2 Webcam Resolutions and Formats with FFmpeg

Finding the supported resolutions, pixel formats, and framerates of a USB webcam on Linux is a fundamental step when setting up video capture or streaming. This guide demonstrates how to use the versatile FFmpeg command-line tool to query and list these device capabilities directly from the Video4Linux2 (V4L2) subsystem.

To list the supported resolutions and pixel formats of a V4L2 webcam, run the following FFmpeg command in your terminal:

ffmpeg -f v4l2 -list_formats all -i /dev/video0

Command Breakdown

  • -f v4l2: Instructs FFmpeg to use the Video4Linux2 demuxer, which is the standard framework for handling video devices on Linux.
  • -list_formats all: Tells the demuxer to list all available video formats, resolutions, and frame rates supported by the camera hardware.
  • -i /dev/video0: Specifies the input device. /dev/video0 is typically the default path for the first connected webcam. If you have multiple cameras, change this path to match your target device (e.g., /dev/video1).

Understanding the Output

When you run this command, FFmpeg will output a list of supported formats to the terminal. The output will look similar to this:

[video4linux2,v4l2 @ 0x55f1a9b240] Raw       :     yuyv422 :           YUYV 4:2:2 : 640x480 320x240
[video4linux2,v4l2 @ 0x55f1a9b240] Compressed:       mjpeg :                Motion-JPEG : 640x480 1280x720 1920x1080
  • Raw / Compressed: Indicates whether the pixel format is uncompressed (like yuyv422) or compressed (like mjpeg or h264).
  • Format Identifier: The short name used by FFmpeg and V4L2 (e.g., yuyv422, mjpeg).
  • Resolutions: The list of resolutions supported by that specific pixel format (e.g., 1920x1080, 1280x720).

Troubleshooting

If you do not know the path of your webcam, you can list all connected video devices by running:

ls /dev/video*

Ensure your user has the necessary permissions to access the webcam (typically by being a member of the video group) or run the FFmpeg command with sudo if you encounter permission denied errors.