Skip to main content

Introduction

FFmpeg supports various input devices for capturing live audio and video from hardware sources. Input devices are implemented in the libavdevice library and registered in alldevices.c.

Usage

Specify input devices using the -f option followed by the device format:
ffmpeg -f [device] -i [device_name] output.mp4

Video Input Devices

v4l2 (Video4Linux2)

Capture video from Video4Linux2 devices on Linux. Platform: Linux Examples:
# List available devices
ffmpeg -f v4l2 -list_devices true -i dummy

# Capture from webcam
ffmpeg -f v4l2 -i /dev/video0 output.mp4

# Specify resolution and framerate
ffmpeg -f v4l2 -video_size 1280x720 -framerate 30 -i /dev/video0 output.mp4

# List supported formats
ffmpeg -f v4l2 -list_formats all -i /dev/video0
Common Options:
  • video_size - Set frame size
  • framerate - Set frame rate
  • pixel_format - Set pixel format
  • input_format - Set input format

dshow (DirectShow)

Capture from DirectShow devices on Windows. Platform: Windows Examples:
# List video devices
ffmpeg -list_devices true -f dshow -i dummy

# Capture from webcam
ffmpeg -f dshow -i video="Integrated Webcam" output.mp4

# Capture with specific resolution
ffmpeg -f dshow -video_size 1280x720 -framerate 30 -i video="Integrated Webcam" output.mp4

# List device options
ffmpeg -f dshow -list_options true -i video="Integrated Webcam"
Common Options:
  • video_size - Frame size
  • framerate - Frame rate
  • pixel_format - Pixel format
  • rtbufsize - Buffer size for real-time capture

avfoundation

Capture from AVFoundation devices on macOS. Platform: macOS / iOS Examples:
# List devices
ffmpeg -f avfoundation -list_devices true -i ""

# Capture from default webcam
ffmpeg -f avfoundation -i "0" output.mp4

# Capture with specific settings
ffmpeg -f avfoundation -framerate 30 -video_size 1280x720 -i "0" output.mp4

# Capture video and audio
ffmpeg -f avfoundation -i "0:0" output.mp4
Common Options:
  • framerate - Frame rate
  • video_size - Frame size
  • pixel_format - Pixel format
  • capture_cursor - Capture cursor
  • capture_mouse_clicks - Capture mouse clicks

gdigrab

Capture Windows screen using GDI. Platform: Windows Examples:
# Capture entire desktop
ffmpeg -f gdigrab -i desktop output.mp4

# Capture specific window
ffmpeg -f gdigrab -i title="Window Title" output.mp4

# Capture region
ffmpeg -f gdigrab -offset_x 100 -offset_y 100 -video_size 640x480 -i desktop output.mp4

# Capture with cursor
ffmpeg -f gdigrab -draw_mouse 1 -i desktop output.mp4
Common Options:
  • offset_x, offset_y - Capture offset
  • video_size - Capture size
  • framerate - Frame rate
  • draw_mouse - Show mouse cursor (0 or 1)
  • show_region - Show capture region

xcbgrab

Capture X11 screen using XCB. Platform: Linux (X11) Examples:
# Capture entire screen
ffmpeg -f x11grab -i :0.0 output.mp4

# Capture with offset and size
ffmpeg -f x11grab -video_size 1280x720 -framerate 30 -i :0.0+100,100 output.mp4

# Follow mouse
ffmpeg -f x11grab -follow_mouse centered -video_size 640x480 -i :0.0 output.mp4
Common Options:
  • video_size - Capture size
  • framerate - Frame rate
  • draw_mouse - Show mouse cursor
  • follow_mouse - Follow mouse: centered, position
  • select_region - Interactive region selection

fbdev (Framebuffer)

Capture from Linux framebuffer device. Platform: Linux Examples:
ffmpeg -f fbdev -i /dev/fb0 output.mp4

kmsgrab

Capture from Linux KMS/DRM. Platform: Linux Examples:
ffmpeg -f kmsgrab -i - -vf 'hwmap=derive_device=vaapi,scale_vaapi=1280:720' output.mp4

android_camera

Capture from Android camera. Platform: Android Examples:
ffmpeg -f android_camera -i 0:0 output.mp4
Capture from Blackmagic DeckLink cards. Platform: Cross-platform Examples:
# List devices
ffmpeg -f decklink -list_devices 1 -i dummy

# Capture from DeckLink
ffmpeg -f decklink -i 'DeckLink Studio' output.mp4
Common Options:
  • list_devices - List available devices
  • list_formats - List supported formats
  • format_code - Video format code

vfwcap

Video for Windows capture. Platform: Windows (legacy) Examples:
ffmpeg -f vfwcap -i 0 output.mp4

lavfi (Libavfilter Virtual Device)

Generate test patterns and virtual video sources. Platform: Cross-platform Examples:
# Generate test pattern
ffmpeg -f lavfi -i testsrc=duration=10:size=1280x720:rate=30 output.mp4

# Generate color
ffmpeg -f lavfi -i color=c=blue:s=1280x720:d=5 output.mp4

# Generate sine wave pattern
ffmpeg -f lavfi -i sine output.mp4

Audio Input Devices

alsa (Advanced Linux Sound Architecture)

Capture audio on Linux. Platform: Linux Examples:
# List devices
arecord -L

# Capture from default device
ffmpeg -f alsa -i default output.mp3

# Capture from specific device
ffmpeg -f alsa -i hw:0,0 output.wav

# Specify sample rate and channels
ffmpeg -f alsa -ar 48000 -ac 2 -i default output.wav
Common Options:
  • sample_rate / ar - Sample rate
  • channels / ac - Number of channels

pulse (PulseAudio)

Capture audio from PulseAudio. Platform: Linux Examples:
# List sources
pactl list sources

# Capture from default source
ffmpeg -f pulse -i default output.mp3

# Capture from specific source
ffmpeg -f pulse -i alsa_input.pci-0000_00_1f.3.analog-stereo output.wav
Common Options:
  • sample_rate - Sample rate
  • channels - Number of channels
  • fragment_size - Audio fragment size

oss (Open Sound System)

Capture audio using OSS. Platform: Linux, BSD Examples:
ffmpeg -f oss -i /dev/dsp output.wav

sndio

Capture audio using sndio. Platform: OpenBSD Examples:
ffmpeg -f sndio -i default output.wav

jack (JACK Audio Connection Kit)

Capture from JACK audio server. Platform: Linux, macOS Examples:
ffmpeg -f jack -i ffmpeg output.wav
Common Options:
  • channels - Number of channels

openal

Capture audio using OpenAL. Platform: Cross-platform Examples:
ffmpeg -f openal -i 'Microphone' output.wav

dshow (DirectShow Audio)

Capture audio on Windows. Platform: Windows Examples:
# List audio devices
ffmpeg -list_devices true -f dshow -i dummy

# Capture from microphone
ffmpeg -f dshow -i audio="Microphone" output.mp3

# Capture both video and audio
ffmpeg -f dshow -i video="Webcam":audio="Microphone" output.mp4

avfoundation (Audio)

Capture audio on macOS. Platform: macOS Examples:
# List audio devices
ffmpeg -f avfoundation -list_devices true -i ""

# Capture from microphone
ffmpeg -f avfoundation -i ":0" output.mp3

# Capture video and audio
ffmpeg -f avfoundation -i "0:0" output.mp4

Specialized Input Devices

iec61883

Capture from FireWire/IEEE 1394 devices. Platform: Linux Examples:
ffmpeg -f iec61883 -i auto output.mp4

libdc1394

Capture from IIDC/DCAM 1394 devices. Platform: Linux Examples:
ffmpeg -f libdc1394 -i /dev/video1394/0 output.mp4

libcdio

Read audio CDs. Platform: Cross-platform Examples:
ffmpeg -f libcdio -i /dev/cdrom track01.wav

Device Selection Tips

Linux

  • Video: Use v4l2 for webcams, x11grab for screen capture
  • Audio: Use pulse (PulseAudio), alsa, or jack

Windows

  • Video: Use dshow for webcams, gdigrab for screen capture
  • Audio: Use dshow

macOS

  • Video/Audio: Use avfoundation
  • Screen capture: Use avfoundation with screen input

Common Capture Scenarios

Webcam + Microphone (Windows)

ffmpeg -f dshow -i video="Integrated Webcam":audio="Microphone" \
  -c:v libx264 -preset fast -crf 23 -c:a aac -b:a 128k output.mp4

Webcam + Microphone (Linux)

ffmpeg -f v4l2 -i /dev/video0 -f pulse -i default \
  -c:v libx264 -preset fast -crf 23 -c:a aac -b:a 128k output.mp4

Webcam + Microphone (macOS)

ffmpeg -f avfoundation -i "0:0" \
  -c:v libx264 -preset fast -crf 23 -c:a aac -b:a 128k output.mp4

Screen Capture (Windows)

ffmpeg -f gdigrab -framerate 30 -i desktop \
  -c:v libx264 -preset ultrafast -crf 18 screen.mp4

Screen Capture (Linux)

ffmpeg -f x11grab -framerate 30 -video_size 1920x1080 -i :0.0 \
  -c:v libx264 -preset ultrafast -crf 18 screen.mp4

Screen Capture (macOS)

ffmpeg -f avfoundation -capture_cursor 1 -i "1:" \
  -c:v libx264 -preset ultrafast -crf 18 screen.mp4

Performance Tips

Reduce Latency

  • Use smaller buffer sizes: -rtbufsize 100M
  • Lower frame rates for screen capture
  • Use hardware encoding when available

Minimize CPU Usage

  • Use faster encoding presets: -preset ultrafast
  • Lower resolution or frame rate
  • Use hardware acceleration

Troubleshooting

# List all available input devices
ffmpeg -devices

# Show device capabilities
ffmpeg -f [device] -list_options true -i [device_name]

# Test capture without encoding
ffmpeg -f [device] -i [device_name] -f null -

See Also

Build docs developers (and LLMs) love