How to Use FFmpeg Realtime Filter for Real-Time Speed
This article explains how to use the realtime filter in
FFmpeg to throttle processing speed to match real-time playback. You
will learn the basic syntax, see practical command-line examples, and
understand how to configure the filter parameters to prevent FFmpeg from
processing media files faster than their actual duration.
Understanding the Realtime Filter
By default, FFmpeg processes media files as fast as your system’s CPU and GPU allow. While this is ideal for transcoding files, it causes issues when streaming live feeds or outputting to local playback devices.
The realtime filter (and its audio counterpart
arealtime) pauses the filtergraph processing to match the
actual wall-clock time. This ensures that the frames are output at their
native playback speed.
Basic Syntax
To apply the filter, you add it to your video or audio filter chains
using the -vf (video filter) and -af (audio
filter) flags:
ffmpeg -i input.mp4 -vf realtime -af arealtime output.mp4In this command: * -vf realtime slows down the video
stream processing to 1x playback speed. * -af arealtime
slows down the audio stream processing to 1x playback speed.
Common Parameters
The realtime filter accepts optional parameters to
customize its behavior:
limit: Defines the maximum pause time in seconds. If the difference between the processing time and the actual time exceeds this limit, the filter stops pausing. The default is2.0seconds.speed: Adjusts the speed factor. The default is1.0(real-time). A value of2.0will process at double speed, while0.5will process at half speed.
Example with Parameters
To process a video at exactly half-speed (0.5x real-time) with a pause limit of 5 seconds, use the following command:
ffmpeg -i input.mp4 -vf realtime=speed=0.5:limit=5 -an output.mp4Practical Streaming Example
The most common use case for the realtime filter is
streaming a local file to an RTMP or UDP destination. Without
throttling, FFmpeg would push the data too fast, causing the streaming
server to drop frames or buffer.
ffmpeg -i input.mp4 -vf realtime -af arealtime -c:v libx264 -preset veryfast -c:a aac -f mpegts udp://127.0.0.1:1234Realtime Filter vs. the -re Option
FFmpeg also has a global input option called -re which
reads the input at the native frame rate.
-reis applied to the input reader before the files are decoded. It is simple to use but can be inaccurate if your decoding process is slow or if you are using complex filtergraphs.realtimeis applied inside the filtergraph. It measures time at the exact point where the filter is placed, making it much more accurate for complex processing pipelines, transcoding, and generating generative video.