How to Use FFmpeg Realtime Filter
This article explains how to use the FFmpeg realtime
filter to slow down media processing to real-time speed. You will learn
the basic syntax, practical command-line examples for both audio and
video, and the key differences between the realtime filter
and the global -re input option.
Why Use the Realtime Filter?
By default, FFmpeg processes files as fast as your CPU and GPU allow. While this is ideal for transcoding local files, it causes issues when streaming to a live server (like RTMP or UDP destinations). If you send data too fast, the server may drop packets or crash.
The realtime filter pauses the filtergraph processing to
match the actual playback duration of the media, forcing FFmpeg to run
at exactly 1x speed.
Basic Syntax
The realtime filter can be applied to video streams
using -vf (video filter) and to audio streams using
-af (audio filter).
Video Realtime Filter
To slow down video processing to real-time, add realtime
to your video filter chain:
ffmpeg -i input.mp4 -vf realtime output.mp4Audio Realtime Filter
To slow down audio processing, use the audio equivalent:
ffmpeg -i input.wav -af realtime output.wavCombined Audio and Video
If you are processing both audio and video and want to ensure both are throttled, you can apply the filter to both streams:
ffmpeg -i input.mp4 -vf realtime -af realtime -f mpegts udp://127.0.0.1:1234Advanced Filter Parameters
The realtime filter accepts an optional
limit parameter. This parameter defines the maximum speedup
delay in seconds. If the processing falls behind by more than this
limit, the filter will pause to catch up.
-vf realtime=limit=2In this example, if the processing speed deviates from real-time by more than 2 seconds, the filter adjusts the timing to prevent massive sync issues.
Realtime Filter vs. the
-re Option
FFmpeg also has a global input option called -re (e.g.,
ffmpeg -re -i input.mp4...). While they achieve similar
results, they work differently:
-re(Input Option): Tells FFmpeg to read the input file at the native frame rate. It is simple but can sometimes be imprecise with variable frame rate files or complex filtergraphs.realtime(Filter): Regulates speed at the filtergraph stage (after decoding). This is much more precise when you are generating content dynamically within FFmpeg or using complex custom filter chains.