Ch. 17 · FFmpeg Filters in Practice

한국어日本語
7 min

Audio Filter Basics and a Filter Checklist

The basics of handling volume, sample rate, and channels with -af, and a checklist (color range, SAR, pixel format, and so on) to run through after building a filter chain.

Audio follows the same decode → filter → encode flow as video. You write a filter chain with -af (or -filter:a), and the comma and colon rules are the same (Filtergraph syntax). You won't use it as often as video filters, but a few of these are handy to know in practice.

Commonly used audio filters

FilterWhat it doesExample
volumeMultiplies the volume or adjusts it in dBvolume=3dB, volume=0.5
loudnormNormalizes to a loudness (LUFS) target. The two-pass approach, measure then correct, is more accurateSee Chapter 12
aresampleConverts the sampling ratearesample=48000
aformatSpecifies sample format and channel layoutaformat=channel_layouts=stereo
adelayDelays the audio in millisecondsadelay=500|500 (per-channel values)
atempoChanges playback speed while keeping pitchatempo=1.25
amixMixes several audio inputs into one (-filter_complex)[0:a][1:a]amix=inputs=2[a]

The options and allowed ranges of each filter (for example, the ratio range of atempo) can differ by FFmpeg version, so check with ffmpeg -h filter=<name>.

Raise the volume and set 48 kHz stereo (video is copied as-is)
ffmpeg -i input.mp4 -c:v copy \
  -af "volume=3dB,aresample=48000,aformat=channel_layouts=stereo" \
  -c:a aac -b:a 160k output.mp4
  • Match loudness with loudnorm, not volume: volume=3dB just boosts every sound equally; it doesn't match a target loudness. To match broadcast or streaming loudness standards, see LUFS and loudnorm. If you boost too far, peaks can overflow and cause distortion (clipping).
  • 5.1 → stereo downmix: A plain -ac 2 works too, but there are many accounts of the center channel (dialogue) sounding quiet. You can set the downmix coefficients yourself with the pan filter. Always listen to check whether the dialogue gets quieter before deciding.
  • atempo changes the duration, so if you don't match it with the video speed, sync drifts (the video speed is matched with setpts).
  • Each container accepts different audio codecs. When choosing the codec to re-encode with after the filter, check Audio compatibility by container.

A checklist after building a filter chain

When you chain several filters, it's hard to tell by eye alone what state the resulting file is in. Get in the habit of checking the items below with ffprobe and playback. It gathers the common mistakes covered in this chapter in one place.

CheckSymptomVerify / fix
Are the pixel dimensions even?Encoder error, or edges get cut offscale=-2:H, make crop's w and h even
Is the SAR what you intended?The picture looks stretched in some playersCheck sample_aspect_ratio with ffprobe, scale=iw*sar:ih,setsar=1
Is the color range right?Blacks that look lifted (gray instead of true black), or excessive contrastscale=in_range=…:out_range=…, watch out for yuvj formats
Are the color tags (matrix, primaries, transfer) right?Washed-out color, different saturationCheck color_space/primaries/transfer with ffprobe; BT.709 is typical for HD
Is the pixel format playback-compatible?Won't play on some devices or browsersformat=yuv420p at the end of the chain (if needed)
Frame rate and field orderJittery motion, combingThe fps value, idet and ffprobe field_order
Audio sync and channelsAudio is late or comes out of only one sideCheck playback after filtering, check the channel count

The principles of color tags and color range are in Chapter 1 (color gamut) and Chapter 14 (why colors look washed out), and measurement pitfalls are in Chapter 11 (Measurement pitfalls).

Check the key properties of the result file in one go
ffprobe -v error -select_streams v:0 \
  -show_entries stream=codec_name,pix_fmt,width,height,sample_aspect_ratio,display_aspect_ratio,r_frame_rate,field_order,color_range,color_space,color_primaries,color_transfer \
  -of default=nw=1 output.mp4
If a filter looks suspicious, remove them one at a time

If the result looks wrong, remove filters starting from the last one, one at a time, and render the same section (10 seconds) again. You'll quickly narrow down which filter caused the problem. You can also run with -f null - output to quickly check just the speed and errors. When you combine filters with a hardware encoder, frames may have to move back and forth between GPU memory and CPU memory (Hardware encoders), so check whether there is a hardware version of the filter under a different name.

aresamplearesample filter

A filter that changes the audio sampling rate.

volumevolume filter

A filter that multiplies the audio volume or adjusts it in dB. Different from loudnorm, which matches a target loudness.

atempoatempo filter

A filter that changes audio playback speed while keeping pitch.

pix_fmtPixel format

A name for a frame's color representation, chroma subsampling, and bit depth. Example: yuv420p.

Check yourself

You want to match broadcast loudness (LUFS). Why isn't volume=3dB enough?

Check yourself

A video built with several chained filters won't play on some devices. What should you check first?