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.mp4

In 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:

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.mp4

Practical 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:1234

Realtime Filter vs. the -re Option

FFmpeg also has a global input option called -re which reads the input at the native frame rate.