Configure FFmpeg asrc and vsrc Fallback Test Signals

This article explains how to configure FFmpeg’s audio source (asrc) and video source (vsrc) filters to generate synthetic fallback test signals. You will learn the exact syntax and configurations needed to produce reliable placeholder audio and video streams, ensuring your broadcast or stream remains active with a standard test pattern and tone if your primary input source fails.

Understanding FFmpeg Source Filters

FFmpeg includes built-in virtual input devices and filters under the Libavfilter library (lavfi) that can generate video and audio programmatically. These are highly useful for creating fallback loops, testing bandwidth, or debugging AV synchronization issues.

To use these filters, you must specify the virtual input format -f lavfi before defining the source configuration.

Configuring Video Fallback Sources (vsrc)

The two most common video test sources are testsrc (a moving color test pattern with a timer) and smptebars (standard engineering color bars).

1. Standard Test Pattern (testsrc)

This configuration generates a 1080p stream at 30 frames per second:

ffmpeg -f lavfi -i testsrc=size=1920x1080:rate=30 -t 10 video_fallback.mp4

2. SMPTE Color Bars (smptebars)

This generates standard broadcasting color bars, which are ideal for static fallback screens:

ffmpeg -f lavfi -i smptebars=size=1280x720:rate=29.97 -t 10 static_fallback.mp4

3. Solid Color Screen (color)

If you require a simple black or blue screen as a fallback, use the color source:

ffmpeg -f lavfi -i color=c=black:s=1920x1080:r=30 -t 10 black_fallback.mp4

Configuring Audio Fallback Sources (asrc)

To prevent audio decoders from failing during a stream drop, you can generate a continuous synthetic tone or white noise.

1. Sine Wave Tone (sine)

The sine filter generates a steady audio tone. This configuration creates a standard 1000 Hz reference tone at a 48 kHz sample rate:

ffmpeg -f lavfi -i sine=frequency=1000:sample_rate=48000 -t 10 audio_fallback.wav

2. White Noise (anoise)

If a constant tone is too disruptive, you can generate pink or white noise to indicate a fallback state:

ffmpeg -f lavfi -i anoise=color=white:sample_rate=44100 -t 10 noise_fallback.wav

Creating a Combined Audio/Video Fallback Stream

To use these sources as a complete fallback signal, you must combine both the audio and video filters into a single command. It is critical to match the resolution, frame rate, and audio sample rate of your primary stream so that switching to the fallback stream is seamless.

Run the following command to generate a combined fallback stream containing SMPTE color bars and a 440 Hz (A4) audio tone:

ffmpeg -f lavfi -i smptebars=size=1920x1080:rate=30 \
       -f lavfi -i sine=frequency=440:sample_rate=48000 \
       -c:v libx264 -pix_fmt yuv420p \
       -c:a aac -b:a 128k \
       -shortest fallback_signal.mp4

Parameter Breakdown: