Skip to content
11 min read

The isolation that was already the default: an ffmpeg tee onfail flag that isolates nothing

One encoder, two outputs: a compressed leg the audience hears and a raw PCM leg a speech recogniser hears. The raw leg carries onfail=ignore so it can fail alone. It cannot — on a single-slave tee the flag has nothing to continue with, and in the build we measured it was already the default anyway.

Vyacheslav Pankratov· Fullstack Developer
Cover art for “The isolation that was already the default: an ffmpeg tee onfail flag that isolates nothing”
On this page

TL;DR: Our encoder produces two outputs off one decode — a compressed leg the audience receives and a raw PCM leg a speech recogniser receives over a pipe. The raw leg is wrapped in an ffmpeg tee onfail=ignore so that a dead recogniser cannot take the broadcast down with it. Twenty-four trials of a harness say it takes the broadcast down anyway, for two independent reasons: a tee with one slave has nothing left to continue with when that slave fails, and in the build we measured, ignore was already the default — so writing it never changed anything, anywhere.

The sentence that started this was one I wrote myself, in a planning document, a day before I checked it: "the tee is configured to ignore failure, so recognition can die without touching the broadcast." It reads like a fact. It was a reading of a flag name.

Two outputs off one decode

The shape is common enough that you have probably built it. One process ingests a live stream, and two things need the audio: the audience, and a speech recogniser producing captions or a translation. You do not want to decode twice, and you do not want the recogniser pulling from the delivery path, so you take a second output off the same decode.

Ours is a single ffmpeg with three outputs — video, delivered audio, and the recogniser's audio:

-map 0:a:0? -c:a libopus -application lowdelay -b:a 64k -f rtp <audio_rtp>
-map 0:a:0? -c:a pcm_s16le -ar 16000 -ac 1 \
  -f tee "[select=a:f=s16le:onfail=ignore]pipe:3"

The second one is read by the spawning process off file descriptor 3 and forwarded to the recogniser over a websocket. Two legs, one decode:

Delivery leg Recogniser leg
Codec Opus, 64 kbps, lowdelay pcm_s16le, uncompressed
Sample rate not reduced by us — whatever the encoder's input carries 16 kHz, set explicitly
Channels whatever the source sent 1 — downmixed
Transport RTP a pipe on fd 3
On failure takes the stream down supposed to fail alone

Why the two legs stop corroborating each other

Worth stating before the failure, because it is the part that survives even when everything works.

The legs diverge after decode, which bounds the claim in a useful direction: a defect in the source hits both, so a garbled input produces a garbled transcript and garbled audio together. What stops corroborating is everything introduced after the split — and that is not nothing.

The recogniser leg is resampled to 16 kHz by an explicit flag, so it keeps nothing above 8 kHz — where sibilance lives. The delivery leg carries no such flag: it is whatever the encoder's input has, Opus-encoded. Everything above 8 kHz in the source therefore exists for the audience and not for the transcript, and a transcript that confuses s and f is telling you about the recogniser's leg, not about what anyone heard. How much content that is depends on the source, which is a property of the upstream encoder and not of anything in this repository — so the size of the gap is not ours to state, only its existence.

The other direction needs no such caveat, because of -ac 1. The recogniser's leg is a mono downmix; the delivery leg keeps the source's channel count. A defect isolated to one channel — one dead microphone in a stereo pair, one channel inverted — reaches the audience intact and reaches the recogniser averaged against the good channel. The transcript comes back clean. The clean transcript is not evidence.

This is the half that overlaps with an argument we have made before, in live captions without the latency: tap a copy, never the path. This encoder satisfies that half honestly — it is a genuine second output, not a fork of the delivery path. What follows is the audit of the other half.

What happens when the recogniser's consumer dies?

The flag says onfail=ignore. FFmpeg's tee muxer documentation says what it means, and the manual page shipped in the same package as the binary we run says it more plainly:

onfail — Specify behaviour on output failure. This can be set to either abort (which is default) or ignore. abort will cause whole process to fail in case of failure on this slave output. ignore will ignore failure on this output, so other outputs will continue without being affected.

So: check it. Our harness (rig/teeonfail/, committed with the results.txt every number below comes from) runs one ffmpeg per trial with the same shape — two outputs off one decode, the same codecs and sample rates, the tee's slave on pipe:3 read by the harness process itself, so that "the consumer died" is a destroyed read end of a real pipe rather than a closed file. At one second in, the consumer dies. The measurement is whether the other leg reaches the end of a fifteen-second input.

Three trials per arm, and the arms exist to separate what the answer is caused by:

Arm Tee spec Exit Reached
single-ignore one slave, onfail=ignore — what we ship 224 1.5 s of 15
single-default one slave, flag omitted 224 1.5 s of 15
two-ignore two slaves, first onfail=ignore 0 15 s
two-default two slaves, flag omitted 0 15 s
two-abort two slaves, first onfail=abort 224 1.5 s of 15
single-ignore-alive what we ship, consumer left running 0 15 s

Every arm gave the same answer in all three trials. The last row is the negative control and it is the row that makes the rest mean anything: the production configuration, with nothing killed, runs to completion. The deaths above it are a broken guarantee, not a broken harness.

  1. A tee slave fails mid-writethe pipe's reader is gone
  • A sibling slave is still alivethe only case where onfail is read at all
    1. Consult this slave's onfailignore, or abort
    2. Continue with 1/2 slavesexit 0
  • It was the only slaveAll tee outputs failed — the policy is never reached, exit 224

Two reasons the flag does nothing, and you have to fix both

One: with a single slave there is nothing to continue with. The tee's own log line says it — All tee outputs failed — where the two-slave arms say Slave muxer #0 failed: Broken pipe, continuing with 1/2 slaves. The per-slave policy is consulted only when the tee still has a survivor. When the failing slave is the only slave, the tee returns the error whatever its policy says, the output task terminates, and ffmpeg exits. single-ignore and single-default are identical because in that configuration the flag is not reached.

That is not our inference from the log line. The 2016 patch that introduced onfail handles the no-survivors case before it consults any slave's policy, logs exactly that string, and returns the error. The behaviour is upstream and deliberate; what was wrong was our expectation of it.

Two: in this build, ignore was already the default. two-ignore and two-default are also identical — both survive. The only spelling that changes the outcome is the one nobody writes: two-abort dies. That is the reverse of the manual quoted above, which is why the manual is quoted above rather than paraphrased — and the same patch sets the default to abort in the source, so this is not a stale sentence in one man page.

We tested that against a second failure mode before believing it, because a default could plausibly apply at open time and not at write time. It does not split: a slave whose path cannot be opened at all is also ignored by default and aborts only when told to.

open-default   exit 0   Slave muxer #0 failed: No such file or
                        directory, continuing with 1/2 slaves.
open-abort     exit 254 Slave muxer #0 failed, aborting.

This is version-bound and the bound is load-bearing. All of the above is ffmpeg 7.1.1-1ubuntu1.3 on Linux 6.14, ten years after the patch that documents the opposite default. Behaviour that diverges from its own manual and from the commit that introduced it is exactly the kind that moves between versions and between packagers — we did not chase where it moved, because that is a question about ffmpeg and this is an article about our configuration. The useful takeaway is not "the default is ignore". It is that we could not have known which it was for our build without running it, and neither can you.

What it costs when it fires

Nothing about this is subtle downstream. ffmpeg exits, the spawning service sees a non-manual close, and the close handler treats it as an encoder crash: it asks the ingest to reconnect. That path allows two attempts, and on the third it emits a processing error and stops the stream.

So the leg we isolated is not merely un-isolated. It is a hard dependency: a failure confined to the recogniser's pipe ends the broadcast, on a path whose whole purpose was to prevent exactly that.

The guard is aimed at a death this topology cannot produce

The pipe’s reader is the same process that spawned the encoder, so for the read end to break that process must already be gone. Meanwhile the failure this legdoesproduce — slow, not dead — has no guard at all: every chunk goes straight to a socket with no ready-state check and no buffered-bytes check. Fixing the flag without fixing that leaves the likely failure exactly where it was.

The failure it guards against is not the one this topology produces

Here is where honesty costs the article its cleanest ending.

The reader of that pipe is the same Node process that spawned ffmpeg. For the read end to break, that process must be gone — and if it is gone, ffmpeg is an orphaned child and the broadcast is over regardless. The death the flag guards against is one this deployment can barely produce.

Which would be a comfortable place to stop, except that the failures this leg does produce have no guard at all:

  • The recogniser's socket has no send-side check. Every PCM chunk goes straight to socket.send(chunk) with no test of the socket's state and no test of how much is already buffered. Other gateways in the same codebase check the socket's ready state before sending; this one does not. When the recogniser is slow or gone, this leg has no way to say so and no way to push back.
  • The raw stream has a data handler and no error handler. The child process gets an error listener; the pipe carrying the recogniser's audio gets only data. An unhandled error event on a Node stream is an uncaught exception, so the one leg with no error listener is the leg whose failure would take the process down rather than be logged.

So the shape of the mistake is not "a flag that does not work". It is a guard aimed at a rare death while the likely failure — slow, not dead — went unwatched. That is the version of this worth carrying to your own pipeline, because the flag name will be different and the shape will not be.

What to change

If you have a tee with one slave, it is not a tee. Either give it something to continue with — a second slave that cannot fail — or drop the tee and accept that the leg is not isolated, and write that down where the next reader will look. Silence reads as isolation.

Then say what the default is on your build, in a comment, next to the flag. Not because our answer travels, but because ours did not match the manual, and yours might not match ours.

And put the guard where the failure is. For this leg that means a bounded queue in front of the socket with a drop policy, which is a decision we have written about at length in which utterance you never say — the same choice, one layer up.

FAQ

Is onfail=ignore broken? No. It does exactly what the code says: it lets a tee keep going when it has other slaves left. The mistake was ours — asking a per-slave policy to protect a slave that had no siblings, and never checking which way the default fell on our build.

Why not just check for All tee outputs failed in the logs? You could, and it is better than nothing. But the encoder's log line arrives in the same stream as routine codec chatter, and by the time it appears the process is already terminating. A monitor that notices the guarantee failed is not the same thing as a guarantee.

Would a separate process for the recogniser leg fix it? It fixes this specific coupling, at the price of another process to supervise and a second decode or an intermediate transport. Whether that trade is worth it depends on how much a lost transcript costs you relative to a lost broadcast — which is a question about your product, not your pipeline.

How would I find this in my own stack before it bites? Kill the consumer and watch what the producer does. That is the whole method. It took eight arms and about two and a half minutes to run, against a belief that had been written down and trusted.

Three things worth taking away

  1. A flag name is not a guarantee. Ours was read, believed, quoted in a planning document and never exercised. The cost of exercising it was three trials.
  2. Isolation needs a survivor. A per-branch failure policy on a branch with no siblings has nothing to fall back to, and the configuration that looks most explicitly defensive can be the one doing nothing.
  3. Check the default on the build you ship. A documented default and an observed default are two different facts, and only one of them runs in production.

If you have a pipeline where one leg is supposed to be able to fail alone, that is a cheap thing to have looked at.

Was this helpful?

// Build it

Running this in production?

Audio has no idle — silence is something you generate, a 20 ms hole is audible, and anything that talks must choose what it will never say. Tell us where the sound goes wrong; we reply within a day with a concrete next step.