How to Use the FFmpeg Realtime Filter
This article provides a quick overview and practical guide on how to
use the realtime filter in FFmpeg. You will learn what the
filter does, its basic syntax, how it compares to the traditional
-re input option, and how to apply it to your video and
audio processing workflows to emulate real-time streaming.
What is the Realtime Filter?
By default, FFmpeg processes media files as fast as your CPU and GPU hardware allow. While this is ideal for file transcoding, it causes issues when broadcasting a live stream from a pre-recorded file, as the data is sent too quickly for the ingestion server.
The realtime filter solves this by pausing the
processing pipeline matching the actual playback speed of the media.
Basic Syntax
The realtime filter can be used for both video
(-vf) and audio (-af) streams, or within a
complex filtergraph (-filter_complex).
To apply the filter to a video stream, use the following basic command:
ffmpeg -i input.mp4 -vf realtime -f mpegts udp://127.0.0.1:1234To apply it to both audio and video streams using a complex filtergraph:
ffmpeg -i input.mp4 -filter_complex "[0:v]realtime[v];[0:a]realtime[a]" -map "[v]" -map "[a]" -f flv rtmp://live.server.com/app/stream_keyFilter Options
The realtime filter accepts a limit
parameter, which defines the maximum pause time in seconds.
limit: (Default: 2.0) If the processing delay or pause exceeds this limit, the filter will not attempt to slow down the stream further. This prevents excessive buffering if there is a sudden lag in the processing pipeline.
Example using the limit parameter:
ffmpeg -i input.mp4 -vf "realtime=limit=1.5" -f mpegts udp://127.0.0.1:1234Realtime Filter vs. the -re Option
Historically, the -re flag (inserted before the input
file) was the standard way to read inputs at native frame rates.
However, the realtime filter offers distinct
advantages:
- Precision: The
realtimefilter is applied at the filtering stage of the pipeline rather than the demuxing stage. This results in more precise pacing, especially when dealing with complex filter chains. - Selectivity: While
-reapplies globally to the entire input file, therealtimefilter can be placed at specific points in your filtergraph, allowing you to speed up or slow down certain segments of your processing before throttling the output rate.