MY WEBCAM TEST GUIDE

Setting a V4L2 Video Device Format

How to set a V4L2 device's resolution, pixel format and frame rate with v4l2-ctl, how loopback devices differ, and what video format changes mean for webcam audio.

The short answer

On Linux, you set a V4L2 device's capture format with v4l2-ctl and its --set-fmt-video option. You give it a width, a height and a pixel format, such as MJPG or YUYV. Three conditions limit this. The driver only accepts combinations the device actually supports, and it may quietly substitute the nearest one. The setting usually does not persist after the device is closed or another application reconfigures it. And a device that is already streaming will typically refuse the change. For a webcam microphone, the key point is that V4L2 handles video only. Changing the video format does not reconfigure the microphone, and a loopback (virtual) camera carries no audio at all.

Basic commands

Start by identifying the device node, then list what it supports before setting anything. v4l2-ctl is part of the v4l-utils package on most distributions.

# List video devices and their nodes
v4l2-ctl --list-devices

# Show supported pixel formats, resolutions and frame intervals
v4l2-ctl -d /dev/video0 --list-formats-ext

# Set resolution and pixel format
v4l2-ctl -d /dev/video0 --set-fmt-video=width=1280,height=720,pixelformat=MJPG

# Request a frame rate (frames per second)
v4l2-ctl -d /dev/video0 --set-parm=30

# Confirm what the driver actually applied
v4l2-ctl -d /dev/video0 --get-fmt-video
v4l2-ctl -d /dev/video0 --get-parm

Always run the get commands after a set command. V4L2 drivers are allowed to adjust a requested format to the closest supported value instead of returning an error. A command that appears to succeed can still leave you with a different resolution or frame rate than you asked for.

Why a format change may not take effect

  • Device busy: if a conferencing app, browser or other program is streaming from the device, format changes are commonly rejected until that stream stops.
  • Unsupported combination: a resolution may only be offered in one pixel format, or only at certain frame rates. Check --list-formats-ext for the exact combinations.
  • Overridden by the application: many programs negotiate their own format when they open the camera, which replaces whatever you set beforehand.
  • Wrong node: one physical webcam can expose several /dev/video nodes, and some of them carry metadata rather than video. Use the node that lists capture formats.

How loopback devices differ

A loopback device, usually created with the v4l2loopback kernel module, has no hardware behind it. Its format is generally determined by the program writing frames into it, such as OBS, ffmpeg or GStreamer, rather than by running v4l2-ctl against it. Applications that read from the device see whatever format the producer has established. Until a producer starts, some applications may not recognize the device as a usable camera.

To control the output format of a virtual camera, set it in the producing program. For example, set the output resolution in OBS, or the output size and pixel format in an ffmpeg or GStreamer pipeline. The v4l2loopback project also ships a helper utility, v4l2loopback-ctl, that can fix certain properties on the device. Its available options differ between versions, so check its built-in help on your system rather than relying on a specific syntax.

# Example: feed a loopback device from a real camera with ffmpeg,
# choosing the output pixel format explicitly
ffmpeg -f v4l2 -input_format mjpeg -video_size 1280x720 -i /dev/video0 \
       -pix_fmt yuv420p -f v4l2 /dev/video10

What this means for capturing speech

A webcam's built-in microphone appears to Linux as a separate audio device, typically a USB Audio Class device. It is managed through ALSA and a sound server such as PipeWire or PulseAudio, not through V4L2. As a result, v4l2-ctl cannot select, configure or test the microphone, and a format change does not change the microphone's sample rate (how many times per second the audio signal is measured). To find the microphone, use audio tools instead.

# List ALSA capture hardware
arecord -l

# List sound-server input sources (PipeWire or PulseAudio)
pactl list sources short

# PipeWire overview, if wpctl is installed
wpctl status

Two practical side effects are worth knowing. They are general principles, not results measured for any particular camera.

  • USB bandwidth: uncompressed formats such as YUYV at high resolutions use far more USB bandwidth than compressed MJPG. When a camera and other devices share a USB bus, heavy video traffic can contribute to capture problems. Switching to MJPG or a lower resolution is a reasonable step if you hear dropouts. It is a troubleshooting step, not a guaranteed fix.
  • Audio-video sync: a virtual camera pipeline adds processing between the camera and the conferencing app, while the microphone audio goes to the app directly. That extra processing can make the video lag behind the speech. Whether the delay is noticeable depends on the pipeline, and no measurements were available for this guide.

When you route video through a loopback device, select the webcam microphone, or another microphone, separately as the audio input in your conferencing or recording application. The virtual camera will not supply it.

Evidence gaps

No device-specific evidence was supplied for this guide. The commands above reflect the documented general behavior of v4l2-ctl and v4l2loopback, not tests of particular webcams. Which formats, frame rates and audio sample rates your hardware supports can only be confirmed by running the listing commands on your own system.