How to Use the arealtime Filter in FFmpeg

This guide explains how to use the arealtime filter in FFmpeg to throttle audio processing to real-time speed. You will learn what the arealtime filter does, why it is essential for live streaming applications, and how to implement it in your FFmpeg command-line workflows with practical examples.

What is the arealtime Filter?

The arealtime filter is an audio filter in FFmpeg that slows down the processing of audio data to match real-time playback speed (wall-clock time). By default, FFmpeg processes media files as fast as your CPU allows. While high-speed processing is ideal for rendering or transcoding files, it can overwhelm streaming servers or cause synchronization issues during live broadcasts.

The arealtime filter acts as a buffer, releasing audio frames only when their presentation timestamps (PTS) match the actual elapsed time.

When to Use arealtime vs. the -re Option

FFmpeg has a global input option, -re, which reads input at the native frame rate. While -re works well for simple demuxing, it applies to the entire input demuxer and can sometimes be inaccurate in complex filtergraphs or when dealing with variable frame rates.

You should use arealtime (often alongside its video counterpart, realtime) when: * You are using complex filtergraphs (-filter_complex) where input-level throttling is insufficient. * You only want to throttle specific audio streams while letting others process at maximum speed. * You need precise, filter-level control over the timing of your output stream.

Basic Syntax and Examples

The arealtime filter does not require any mandatory arguments to function at normal 1x speed.

Example 1: Streaming Audio in Real-Time

To stream a local audio file to an icecast server or a UDP address in real-time, apply the -af (audio filter) flag followed by arealtime:

ffmpeg -i input.mp3 -af arealtime -f mpegts udp://127.0.0.1:12345

Example 2: Synchronizing Audio and Video in a Filtergraph

When streaming video and audio together, you must throttle both streams. Use the realtime filter for video and the arealtime filter for audio within a complex filtergraph:

ffmpeg -i input.mp4 -filter_complex "[0:v]realtime[v];[0:a]arealtime[a]" -map "[v]" -map "[a]" -f flv rtmp://your-live-server/live/stream

In this command: * [0:v]realtime[v] processes the video stream at real-time speed. * [0:a]arealtime[a] processes the audio stream at real-time speed. * The -map options ensure the throttled streams are sent to the RTMP output destination.

Available Parameters

The arealtime filter supports one optional parameter:

Example 3: Running at Custom Speed

If you want to stream audio at 1.5x real-time speed, use the following syntax:

ffmpeg -i input.wav -af "arealtime=speed=1.5" -f mpegts udp://127.0.0.1:12345