Skip to content

mono MP3 → E-AC-3 bridge: the first-segment prime scan never gets an encoded audio packet, muxerFailed at every start position including 0.00s #396

Closed as not planned

Description

@kskchaitanya1993

Summary

A plain SD MKV with mono MP3 audio cannot be played on the native route at all. The mp3 → E-AC-3 bridge is selected, the first segment cut is deferred because no audio sample entry can be built, the forward prime scan does not find one, the pump exits muxerFailed, both rebuilds fail identically, the revive cap is reached and the session ends with:

Source audio cannot be muxed (code -22)

Reproduced nine times out of nine, at nine different start positions including 0.00s, on the same file. The software route plays the same file perfectly.

This looks distinct from the three neighbours, and I have tried to rule each out below rather than assume:

Environment

  • AetherEngine 6.27.1
  • iPad mini (6th generation), iOS 26.5 (23F77)
  • Host: our Flutter app, own video_player backend; AetherEngine as rung 1, libVLC as rung 2
  • Route: native / loopback (canHardwareDecode codec=27 640x272 -> true)

Source media (ffprobe)

Matroska over HTTP from an Xtream-style IPTV origin, 358,378,434 B. Absolute byte ranges are
honoured (206); the origin does not honour suffix ranges, which the engine notices once
and stops asking for — pump tail prefetch rejected after 1676ms: Content-Range: bytes -65536/358378434 does not describe the 65536B asked for; not asking this origin again this session. Mentioning it only to be complete: it is the same on every run, including the ones
where the software route plays the file to the end.

0  h264     video  640x272  High/L2.1  yuv420p  23.976 fps  tel  (default)
1  mp3      audio  mono  44100 Hz   40 kb/s   tel  (default)   <- selected
2  mp3      audio  mono  24000 Hz   32 kb/s   tam
3  mp3      audio  mono  24000 Hz   32 kb/s   hin
4  subrip   sub                               eng  (default)
duration 7070.189s, overall bitrate ~405 kb/s

What the engine does

[AetherEngine] dispatch: codec=27 → native
[HLSVideoEngine] video codecpar: codec=27 640x272 profile=100 level=21 fieldOrder=1 extradata=44B head=01640015ffe1001c
[HLSVideoEngine] segment plan: keyframe-aligned, 2152 IRAPs → 1690 segments [firstKeyframePts=0 (0.000s) videoStream.start_time=0 format.start_time=0us plan[0].startSeconds=0.000]
[HLSVideoEngine] audio: codec=mp3 (bridge required), decoding + EAC3 re-encode
[AudioBridge] init: mode=surroundCompat srcCodec=86017 sampleRate=44100 sourceChannels=1 encoderChannels=1 bitRate=128 kbps (source=container, container=1, decoder=1)
[HLSSegmentProducer] init OK (baseIndex=0, segments=1674, targetDur=4.000s, srcVideoTb=1/1000) audio=bridge inTb=1/44100
[HLSVideoEngine] prepared: codec=avc1.640015,ec-3 resolution=640x272 fps=23.976 range=SDR DV=none segments=1674 duration=7070.2s
[AetherEngine] #321: effective video route = loopback

The failure, from 0.00s

[HLSSegmentProducer] video gate open: actual=0 anchorPts=0 target=-9223372036854775808 desired=0 shift=0 videoPID=0 reconstructed=false
[HLSSegmentProducer] first video pkt: dts=0 pts=0 duration=41 size=1060 (fallback=41 in srcVideoTb)
[HLSSegmentProducer] audio gate open: actual=9 target=0 desired=0 shift=0 gapMs=0.0
[HLSSegmentProducer] #65 ledger seg-0 base=0 itemAxis=0.000s sourceStart=0.000s planSource=0.000s drift=0.000s shift=0.000s
[HLSSegmentProducer] #65 ledger seg-1 base=0 itemAxis=20.771s sourceStart=20.771s planSource=10.427s drift=10.344s shift=0.000s
[HLSSegmentProducer] AE#222 seg-0.m4s cut deferred: audio sample entry needs a parsed packet and none has been muxed; scanning forward for a prime frame
[HLSSegmentProducer] pump finished: reason=muxerFailed packetsRead=1308 packetsWritten=500 lastError=0 elapsed=526ms cacheCount=0
[HLSVideoEngine] #99 VOD pump died with muxerFailed; rebuilding producer + muxer at 0.00s -> seg0 (attempt 1/2)
… identical, elapsed=19ms …
[HLSVideoEngine] #99 VOD pump died with muxerFailed; rebuilding producer + muxer at 0.00s -> seg0 (attempt 2/2)
… identical, elapsed=15ms …
[HLSVideoEngine] #99 VOD muxerFailed revive cap reached (3 failures, cap 2); giving up (source not muxable in this session)

Two things stand out to us, offered as observation rather than diagnosis:

  1. The source audio is right there. gapMs=0.0, first audio packet at 9 ms. Whatever is missing is downstream of the demuxer — the bridge's encoded E-AC-3 output, not a source packet.
  2. The scan does travel. seg-1 lands at sourceStart=20.771s against planSource=10.427s, a 10.3 s drift, so roughly twenty seconds of media went by without an audio sample entry ever being available.

Every attempt, same file

Nine sessions, nine start positions, nine identical outcomes. packetsWritten/packetsRead is 0.37–0.38 throughout.

startPosition anchor seg packetsRead packetsWritten first attempt
0.00 s seg-0 1308 500 526 ms
2214.00 s seg-545 584 221 400 ms
2483.00 s seg-611 602 228 763 ms
2932.00 s seg-720 1025 389 447 ms
3331.00 s seg-809 811 305 487 ms
5295.00 s seg-1306 713 270 650 ms
5658.00 s seg-1398 589 222 496 ms
5867.00 s seg-1451 414 155 489 ms
5908.00 s seg-1460 494 185 429 ms

Both rebuilds always read exactly the same packet counts as the first attempt and fail in 12–23 ms, so as in #222 the retry re-enters the same configuration rather than changing the decision that caused the failure.

Two things we checked so you don't have to

  • The software route plays this file completely. Same URL, same 6.27.1, on the iOS simulator, which has no VideoToolbox decoder — codec=27 not hardware-decodable by VideoToolbox; routing to the software path so it plays instead of a black screen (#2): 683 frames in 30 s, route=software, all three audio tracks named and selectable, subtitle selection works. So demux and decode of this file are fine; the failure is confined to the loopback muxer path.
  • Mono 44.1 kHz E-AC-3 into fragmented MP4 is not inherently impossible. Standalone, ffmpeg -f lavfi -i sine=…:sample_rate=44100 -ac 1 -c:a eac3 -b:a 128k -movflags +empty_moov+default_base_moof+frag_keyframe+delay_moov -f mp4 produces a valid eac3 / 44100 / 1ch track. We are not claiming that is the same code path — only that the encoder configuration AudioBridge reports is one ffmpeg will accept.

Impact for us

Low, and we are not blocked: our ladder demotes to libVLC and the viewer gets a picture. We are reporting it because mono MP3 in MKV is ordinary IPTV catalogue material rather than an exotic shape, and because a source the software route plays end to end is worth having on the native route too.

Happy to run any diagnostic build against this file, or to try a synthetic reproduction if you would like one — a three-track mono-MP3 MKV should be straightforward to generate.


🤖 Written and posted by Claude Code on behalf of @ksktech-dev.

Activity

  1. superuser404notfound commented on Aug 18, 2026

    @superuser404notfound
    Owner

    Thanks for this, and for ruling out #222, #366 and #99 before filing. All three checks were the right ones and all three answers hold up, which saved a wrong start.

    Reproduced 1:1

    Fixture: a mono MP3 44.1 kHz MKV whose audio payloads the decoder cannot make a frame of. The session comes out line for line the same, including the two rebuilds finishing in 2 to 3 ms with identical packet counts and the terminal Source audio cannot be muxed (code -22).

    Observation 1 was exactly right, and it is the entire failure

    What is missing is the bridge's encoded output, not a source packet. FFmpeg's mp4 muxer can only build an AC-3/E-AC-3 sample entry from a packet it has PARSED, and on a bridged source those packets come from the bridge's encoder. It emitted none for the whole of segment 0. Everything after that follows mechanically: the cut defers (the #222 guard doing its job), the pump exits muxerFailed, the revive cap ends the session, and the sentence that reaches the viewer names the muxer and the source, which are the two subsystems that were fine.

    Observation 2 needs one correction, because it points somewhere else

    The scan did not travel. scanForAudioMoovPrimeFrame is scoped to single-demuxer stream-copy audio and returns without looking on a bridged session: there is nothing in the source to scan for, since the frames the muxer needs come out of the encoder. The line promising a forward scan was printed unconditionally, so it announced an action that never happened, on the one path where the interesting question had no log line at all. That is fixed.

    The seg-1 ledger line is not the scan either. It is the video cutter reaching plan index 1, which is what REQUESTS the segment-0 cut. So the 10.3 s gap between planSource and the actual keyframe is a separate property of that file (the plan's boundaries come from the container index, the cutter waits for a real IRAP) and is unrelated to the audio. What the two lines together do establish is your conclusion: about 20.8 s of media went by with no audio sample entry ever becoming available.

    A synthetic reproduction would not help, though thanks for offering

    I built the three-track mono-MP3 MKV first. It plays. Mono 44.1 kHz MP3 through the surroundCompat bridge produces a valid ec-3 / 44100 / 1 ch track on the native route, both with a 4 s first segment and with a 20.8 s one. So neither mono, nor 44.1 kHz, nor a long first segment is the trigger. Something specific to that file's audio is, and only that file can say what.

    What is on main now (9870892c, PR #397)

    The reason neither of us can name the failing step from your log is that there is no step to read. Every stage between a source packet and an encoded frame ends in a return or in a loop that stops on a negative code: a packet avcodec_send_packet rejects, while avcodec_receive_frame(...) >= 0 (which reads as "drain what is there" and behaves as "drop the reason there is nothing"), four early returns in the resampler, avcodec_receive_packet breaking on any negative code. Per packet that is right, one bad frame must not end a session. In aggregate it made a bridge that emitted nothing for a whole segment indistinguishable from one that had simply not been asked yet.

    • AudioBridge now counts each of those arms and keeps the decoder's own error code instead of discarding it.
    • The deferred cut prints that account instead of announcing a scan it does not run.
    • Zero decoded frames ends the session immediately. A restart rebuilds the muxer and re-opens the encoder, both downstream of a failing decoder, which is why your three attempts read identically. Frames decoded with nothing emitted is the encoder side, which a rebuild does heal, and keeps its revive.
    • New PlaybackErrorKind.audioBridgeProducedNoOutput for the failure, replacing vodSourceFailed. For a ladder that matters: vodSourceFailed reads as "the source is gone" and is a reason to stop, while here the source is neither gone nor unreadable and a second engine that decodes the track itself plays the file. This one is a demote.

    It is on main; say the word if a tagged build is easier to vendor and I will cut one.

    One discriminator, and it needs no new build at all

    Both routes open the mp3 decoder identically: avcodec_parameters_to_context followed by avcodec_open2(ctx, codec, nil), no options, in AudioDecoder and in AudioBridge alike.

    So: on the software route, does that file actually produce sound? The report says the three tracks are named and selectable, which is a demuxer statement rather than a decoder one.

    • Audible on software: the same decoder made frames out of the same bytes, so the failing arm sits downstream of the decode inside the bridge, and the counters will say which.
    • Silent on software: the audio in that MKV is not decodable by this libavcodec build, which for an Xtream-style remux usually means a mis-declared track, and the engine's remaining job is the one it now does, saying so instead of blaming the muxer.

    With the build, one line settles it, either at the deferred cut or as [AudioBridge] ERROR: AE#396 ..., in this shape:

    fed=795 decoded=0 enqueued=0 emitted=0 rejected=795 lastDecodeError=Invalid data found when processing input (-1094995529)
    

    decoded=0 is a decoder verdict. decoded>0 emitted=0 is the encoder. Frames decoded with enqueued=0 is the resampler.

    Leaving this open: the change makes the failure legible and stops it costing three attempts, it does not yet make that file play. That needs the arm named.

  2. superuser404notfound commented on Aug 18, 2026

    @superuser404notfound
    Owner

    Tagged: 6.31.0, so this can be vendored as a pin rather than off main.

    .package(url: "https://github.com/superuser404notfound/AetherEngine", from: "6.31.0")

    Minor rather than patch because of the new PlaybackErrorKind.audioBridgeProducedNoOutput; nothing else in the public API moved, and healthy bridged playback is unchanged.

    The cheap question still stands ahead of any run: on the software route, does that file actually produce sound, or do the three tracks only list and select?

  3. kskchaitanya1993 commented on Aug 21, 2026

    @kskchaitanya1993
    Author

    Resolved, and it was not a defect in the engine — our app was linking a second FFmpeg over yours. Sorry for the noise. Your 6.31.0 counters found it in a single run, and there is one thing in here that is genuinely yours, at the bottom.

    The counters answered it immediately

    [HLSVideoEngine] AE#396 the moov was never buildable because the audio bridge emitted nothing this session: fed=2418 decoded=2418 enqueued=2785536 emitted=0
    

    fed == decoded on every packet, 2,785,536 samples into the resampler. The encoder arm, by your own table — which also retires the cheap question: the decoder was never involved, so "audible on software" could not have discriminated anything.

    It was never that file

    source audio result
    the reported file mp3 mono 44.1 kHz fed=2418 decoded=2418 enqueued=2785536 emitted=0
    a different film mp3 stereo 44.1 kHz fed=2757 decoded=2757 enqueued=3176064 emitted=0
    your fixture shape, rebuilt here 3× mp3 mono, 44.1/24/24 kHz fed=687 decoded=687 enqueued=791424 emitted=0
    synthetic pcm_s16le 48 kHz stereo fed=840 decoded=840 enqueued=860160 emitted=0
    synthetic opus 48 kHz stereo fed=894 decoded=894 enqueued=857928 emitted=0

    Not mono, not 44.1 kHz, not mp3, not that origin — the last three were served from a local server that answers absolute ranges cleanly. Every bridged source on that build emitted nothing. Nothing of ours is needed to reproduce it; the third row is

    ffmpeg -f lavfi -i "testsrc2=size=640x272:rate=24000/1001:duration=120" \
           -f lavfi -i "sine=frequency=440:sample_rate=44100:duration=120" \
           -f lavfi -i "sine=frequency=660:sample_rate=24000:duration=120" \
           -f lavfi -i "sine=frequency=880:sample_rate=24000:duration=120" \
           -map 0:v -c:v libx264 -profile:v high -level 2.1 -pix_fmt yuv420p -g 48 -b:v 300k \
           -map 1:a -map 2:a -map 3:a -c:a libmp3lame -ac 1 \
           -b:a:0 40k -ar:a:0 44100 -b:a:1 32k -ar:a:1 24000 -b:a:2 32k -ar:a:2 24000 \
           -metadata:s:a:0 language=tel -metadata:s:a:1 language=tam -metadata:s:a:2 language=hin \
           -disposition:a:0 default  fixture.mkv

    and the last two are the same video with -c:a pcm_s16le or -c:a libopus. The container and the source codec are irrelevant; the trigger is entirely host-side.

    What it was

    The line that gave it away is one neither of us was reading:

    [HLSVideoEngine] flac bridge encoder absent from this FFmpeg build, cascading to eac3
    

    It is not absent from yours. Libavcodec.framework as shipped is 62.28.102, its configure ends --enable-encoder=flac --enable-encoder=eac3, and both encoders' encoder-only AVOptions are in that binary. The engine was not asking your libavcodec.

    Our app also shipped MediaBridge, an older FFmpeg→HLS path of our own, whose FFmpeg was -force_loaded as a static archive into the executable — so its symbols became ordinary external definitions, and a definition in a .o beats a dylib for every other object in the same link:

    $ nm -m Runner | grep _avcodec_find_encoder
    (__TEXT,__text) external _avcodec_find_encoder      <- ours, Lavc61.19.101
    

    That build has --enable-encoder=eac3 and no --enable-encoder=flac — exactly and only the combination the engine reported. AetherEngine expects libavcodec 62 and was executing against 61.

    The control, before we touched anything: the file from this issue, unchanged, on our tvOS app, which links the same engine and had no second FFmpeg —

    [AudioBridge] init: mode=surroundCompat encoder=flac sampleRate=44100 sourceChannels=1 bitRate=VBR
    [HLSVideoEngine] prepared: codec=avc1.640015,fLaC 640x272 segments=1674 duration=7070.2s
    [NativeAVPlayerHost] #1 item.audioTrack codec='flac' enabled=true sr=44100 ch=1 (readyToPlay)
    

    FLAC bridge, playing, packetsWritten=4076 muxCuts=39 at t=30s. Same engine, same file, same 6.32.0.

    Fixed on our side

    MediaBridge had already been superseded by AetherEngine and switched off in our code — it was doing no work and still linking a whole FFmpeg — so we deleted it rather than contained it. The engine now binds its own dylibs, and the file plays on the native route:

    engine=aether route=loopback backend=native  encoder=flac  avc1.640015,fLaC
    VideoToolbox H264 (HW), 104 position advances, no AE#396, no muxerFailed
    

    Close this as invalid whenever suits.

    One thing we ran into that we could not fix upstream of ourselves

    Removing our static copy turned out not to be enough on its own, and this is the part we would value your view on. Before we corrected the link order, the engine still did not reach your dylib — it bound MobileVLCKit's:

    $ otool -L Runner
    13:  @rpath/MobileVLCKit.framework/MobileVLCKit      <- also exports avcodec_*
    27:  @rpath/Libavcodec.framework/Libavcodec (62.28.102)   <- yours
    
    $ nm -m Runner | grep _avcodec_find_encoder
    (undefined) external _avcodec_find_encoder (from MobileVLCKit)
    

    libVLC beside AetherEngine is a fairly ordinary shape for the fallback ladder your API is built around, and CocoaPods puts it earlier in the link than a vendored framework. We fixed ours by forcing your frameworks ahead of it, which works, but it is a workaround we only found because we already knew what to look for.

    Two ideas, offered rather than asked for — you will have context we do not, and either may be more trouble than it is worth:

    1. Would a libavcodec version check at init be worth adding? avcodec_version and avcodec_configuration appear zero times in the shipped binary, so as far as we can tell the engine has no way to notice it is running against a different major. Comparing the compile-time LIBAVCODEC_VERSION_MAJOR with the runtime avcodec_version() would have pointed us at this in the first minute instead of after five fixtures and two devices. If you did add it, the same value might be worth carrying into flac bridge encoder absent from this FFmpeg build — that line reads as a statement about your build, and in our case it was really the first symptom of the wrong build being loaded.

    2. Is namespacing the vendored FFmpeg symbols feasible? It would remove the failure mode entirely rather than leaving each host to discover it. We appreciate this is a much larger change than the first, and possibly not one you want.

    Happy either way, and thank you for the counters — they are what made this findable at all.

    Your correction about scanForAudioMoovPrimeFrame returning without looking on a bridged session, and about the seg-1 ledger line being the cutter rather than the scan, both hold. The deferred-cut line printing the bridge account instead of announcing a scan it does not run is what made any of this legible.


    This comment was drafted and posted automatically by Claude, working on behalf of @kskchaitanya1993.

  4. superuser404notfound commented on Aug 22, 2026

    @superuser404notfound
    Owner

    That is a complete diagnosis, and the control is what makes it one: the same file, the same engine, the same 6.32.0, on a build with no second FFmpeg, playing. Nothing left to argue with.

    Both of the ideas were worth having. The first is built and out.

    The check is in, in 6.34.1

    .package(url: "https://github.com/superuser404notfound/AetherEngine", from: "6.34.1")

    Every session now opens with the FFmpeg that answered:

    [FFmpeg] libavcodec 62.28.102, libavformat 62.6.100, libavutil 60.13.100, libswresample 6.0.100
    

    and when a major does not match the headers the engine compiled against, that line becomes an ERROR: naming the mismatch, the two shapes that cause it, the probes, and the configure line of the libavcodec that answered. On the build described here it would have read:

    ERROR: AetherEngine is executing against a different FFmpeg than it was built against:
    libavcodec compiled against 62.x, loaded 61.19.101. A second FFmpeg sorts ahead of
    AetherEngine's frameworks in this executable's link (a static archive force-loaded into the
    binary, or another dependency exporting the same symbols, libVLC among them).
    `nm -m <executable> | grep _avcodec_find_encoder` names the binary that wins and
    `otool -L <executable>` shows the order; link AetherEngine's frameworks first, or remove the
    second copy. [...] Loaded libavcodec configuration: --enable-encoder=eac3 [...]
    

    Two things beyond the suggestion. All four linked libraries are checked, not just libavcodec: libavutil is the one that really matters, because a major shift there moves struct layouts, so that failure is a crash rather than a silence, and it would have been read as an engine crash. And the healthy line is emitted too, since "which FFmpeg answered" is not reconstructible afterwards from a log that stayed quiet.

    The second half of the suggestion is in as well. The cascade message now reads flac bridge encoder absent from libavcodec 61.19.101, NOT the 62.x this engine was built against, so a sentence about "this FFmpeg build" always says which build it means. That line was true and pointed the wrong way, which is the whole cost of this issue.

    Namespacing, declined, and the reasoning is worth having on the record

    It needs a post-build symbol rewrite across every slice plus rewritten headers, and it breaks every consumer that uses the FFmpeg headers directly, which is a real group. The cause is also not really the shared symbol names: it is that link order is the host's to set and nothing inside a library can reach it. So the gap was a witness, not a rename.

    The libVLC half is documented rather than solved

    That part is the more useful finding of the two, because it is not a mistake anyone made. libVLC beside AetherEngine is the ordinary shape for the ladder this API invites, CocoaPods sorts a pod ahead of a vendored framework by default, and removing a force-loaded static copy therefore does not finish the job. docs/api.md carries it as a host contract now, with the nm -m output in both of its forms, and the README says it next to the note about the frameworks staying dynamically embedded. Being dynamically embedded is not the same as being reached, which was not written down anywhere before.

    Closing as invalid, as suggested. Thanks for chasing this all the way into your own link and then writing it up properly instead of stopping at "fixed on our side"; the five fixtures across three codecs and two containers are what made the host-side conclusion airtight, and this release exists because of the write-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions