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

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

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.