← Blog · · 2 min read

ffmpeg: -t 0 before an anullsrc input means no limit, not zero seconds

Our video pipeline has a small silence() helper. It writes a lead-in of silence before each voice line. One script asked for lead: 0. The helper formatted that as -t 0.000, placed it before the -i of an anullsrc source, and ffmpeg started writing silence with no end. The WAV grew to 185 GB, the disk filled, and the job died.

The cause: when -t 0 is given as an input option on an anullsrc source, ffmpeg does not treat it as zero seconds. It treats it as no duration limit. With -fs as a cap, the runaway run stops at the cap and still exits 0.

We reproduced it on ffmpeg 9.0.2 (macOS, arm64). Every run was capped with -fs 20M so the unbounded cases stop at 20 MB:

buggy_lead0                rc=0 bytes= 20185166 duration_s=210.261333 wall_s=0.13
   $ ffmpeg -hide_banner -nostdin -y -t 0.000 -f lavfi -i anullsrc=r=48000:cl=mono -fs 20M <out>.wav

That run produced 210 s of 48 kHz mono silence in 0.13 s before it hit the cap. Without -fs, nothing stops it except the disk.

Where you put the zero matters:

output_side_t0             rc=0 bytes=       78 duration_s=N/A        wall_s=0.06
   $ ffmpeg -hide_banner -nostdin -y -f lavfi -i anullsrc=r=48000:cl=mono -t 0 -fs 20M <out>.wav
sine_filter_d0             rc=0 bytes= 20185166 duration_s=228.855873 wall_s=0.12
   $ ffmpeg -hide_banner -nostdin -y -f lavfi -i sine=d=0 -fs 20M <out>.wav
anullsrc_filter_d0         rc=0 bytes=       78 duration_s=N/A        wall_s=0.06
   $ ffmpeg -hide_banner -nostdin -y -f lavfi -i anullsrc=r=48000:cl=mono:d=0 -fs 20M <out>.wav

So -t 0 as an output option and anullsrc=...:d=0 both give an empty 78-byte file. sine=d=0 runs without limit, the same as the input-side -t 0. Different sources and positions handle zero in different ways, so it is safer never to pass a zero duration at all.

The fix is to clamp the duration to a small positive minimum:

MIN_SILENCE = 0.04


def silence_fixed(path_name, lead):
    lead = max(float(lead), MIN_SILENCE)
    return run(path_name, ["-t", f"{lead:.3f}", "-f", "lavfi",
                           "-i", "anullsrc=r=48000:cl=mono"])

With that change, lead 0 writes a 3,918-byte file that lasts 0.040000 s. Lead 0.5 gives the same size and duration as before (48,078 bytes, 0.5 s).

Two takeaways:

  1. Never pass a zero duration to an ffmpeg lavfi source. Clamp it, or skip the call when the duration is zero.
  2. Add -fs to generated-audio commands as a backstop. A run stopped by -fs also exits 0, so check the output size or duration afterwards.

How this was made: a short note drafted by an AI agent (Claude) from our own engineering logs; numbers are checked against those logs before publishing.