Your webcam, microphone or desktop has a device name FFmpeg needs, and it is almost never the name you'd guess. This guide is a repeatable way to discover the device backends in FFmpeg, identify the right Linux device name, and make a short capture test. The examples use the Ubuntu package ffmpeg 6.1.1-3ubuntu5+esm13 through /usr/bin/ffmpeg. Allow about 20 minutes if you already have a camera, microphone or X11 desktop to test.
You need a shell and the ffmpeg package. Hardware access is normally unprivileged, but your user must be allowed to open the relevant device or audio session. Do not add sudo by reflex: it can make a test pass as root while leaving the real service account unable to capture.
Start with the binary and package version. This is read-only and needs no elevated privileges:
$ command -v ffmpeg
/home/linuxbrew/.linuxbrew/bin/ffmpeg
$ /usr/bin/ffmpeg -version | sed -n '1,2p'
ffmpeg version 6.1.1-3ubuntu5+esm13 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 13 ...
$ dpkg-query -W -f='${Package} ${Version}\n' ffmpeg
ffmpeg 7:6.1.1-3ubuntu5+esm13
On this host, the shell finds a separate Linuxbrew FFmpeg 8.0.1 first. That build reports a different device list, so the rest of this guide uses /usr/bin/ffmpeg explicitly. On your machine, use the path belonging to the package and manpage you intend to operate: two FFmpeg builds on one PATH is a classic source of "but it worked on the other machine".
Checkpoint: record the path and version you will use. If /usr/bin/ffmpeg does not exist, stop and inspect your package installation rather than mixing documentation from another build.
FFmpeg treats an input device like a demuxer and an output device like a muxer. The D and E columns in -devices mean demuxing and muxing support respectively:
$ /usr/bin/ffmpeg -hide_banner -devices
Devices:
D. = Demuxing supported
.E = Muxing supported
...
DE alsa ALSA audio output
DE fbdev Linux framebuffer
D lavfi Libavfilter virtual input device
DE pulse Pulse audio output
DE video4linux2,v4l2 Video4Linux2 output device
D x11grab X11 screen capture, using XCB
The exact list depends on how FFmpeg was built. A backend being listed does not prove hardware is present or that your user can open it. The local build advertises V4L2 and X11 as input-capable, while the labels also show output support for some backends.
For device-specific options, ask the binary instead of guessing:
$ /usr/bin/ffmpeg -hide_banner -h demuxer=video4linux2
$ /usr/bin/ffmpeg -hide_banner -h demuxer=alsa
$ /usr/bin/ffmpeg -hide_banner -h demuxer=x11grab
This is also the quickest way to spot a version mismatch. Options are set with the device format, then before the input file: -f DEVICE -option value -i INPUT.
ALSA names the capture target as hw:CARD[,DEV[,SUBDEV]]. The card number or identifier comes first; device and subdevice are optional. Inspect the kernel's current list without changing audio state:
$ sed -n '1,80p' /proc/asound/cards
$ sed -n '1,120p' /proc/asound/devices
$ /usr/bin/ffmpeg -hide_banner -sources alsa
Auto-detected sources for alsa:
null [Discard all samples (playback) or generate zero samples (capture)] (none)
Your output will differ. The null source above is not a microphone. If a real card is listed, use its identifier rather than assuming card 0 is the desired input. The manpage gives a sample ALSA capture command:
$ /usr/bin/ffmpeg -f alsa -sample_rate 48000 -channels 2 -i hw:CARD,DEV -t 5 audio-test.wav
Replace CARD,DEV with a real identifier from your host. The local device help and manpage specify a default sample rate of 48000 Hz and two channels for this build. This command writes a new file, so choose a disposable path. It does not need root in a normal desktop session.
Warning: opening an ALSA device can take exclusive access, depending on the device and its mixer configuration. Stop other recording or playback software if the open fails, and do not terminate an unrelated audio service just to make a test work.
Video4Linux2 devices normally appear as /dev/video0, /dev/video1 and so on. First confirm what exists and who owns it:
$ ls -l /dev/video*
$ /usr/bin/ffmpeg -hide_banner -f video4linux2 -list_formats all -i /dev/video0
The second command lists formats and exits; it does not create a recording. Replace the device path with an existing node. Its output tells you whether the camera accepts raw or compressed input, including the sizes and frame rates that matter for a real capture.
Once you have chosen a supported mode, make a short file:
$ /usr/bin/ffmpeg -f video4linux2 -input_format mjpeg -video_size 1280x720 -framerate 30 -i /dev/video0 -t 5 camera-test.mkv
Only keep -input_format mjpeg, the size and the rate if the format listing confirms them. If the camera rejects those values, remove the options and start from its defaults. A permissions error points to the device's group or udev policy: check membership and policy with your administrator, and do not make /dev/video0 world-writable as a shortcut.
x11grab captures an X11 desktop or region. It is not a Wayland capture method. Check that the DISPLAY environment variable is set and use a five-second test first:
$ printf 'DISPLAY=%s\n' "${DISPLAY:-unset}"
$ /usr/bin/ffmpeg -f x11grab -video_size 1280x720 -framerate 10 -i "${DISPLAY:-:0}+0,0" -t 5 screen-test.mkv
The input name combines the display with the top-left offset. The device's defaults include a 0,0 capture offset, a default frame rate of ntsc, and mouse capture enabled. Set the size and rate explicitly so a test does not unexpectedly record a large desktop at a higher rate. Use -draw_mouse 0 when the pointer should not appear.
For a window or interactively selected region, check the installed x11grab help for -window_id and -select_region. These options are X11-specific. If DISPLAY is unset or the session is Wayland-only, this command is expected to fail; do not treat that failure as a missing FFmpeg package.
Inspect a successful test with ffprobe:
$ /usr/bin/ffprobe -hide_banner camera-test.mkv
$ /usr/bin/ffprobe -hide_banner audio-test.wav
Look for the expected stream type, dimensions or sample rate, and a duration close to five seconds. The files are ordinary outputs, so remove only the test files you created when you have finished:
$ rm -- camera-test.mkv audio-test.wav screen-test.mkv
That removal is irreversible. If you need the samples for diagnosis, copy them to an approved location first. Nothing in this guide changes a service, device permission, boot setting or persistent FFmpeg configuration.
-devices showed which input and output backends this build supports.ffprobe reported the expected stream.