Skip to content

Unknown-length HTTP MP4 enters streaming mode and returns ready with zero packets; the same URL plays in VLC #126

Closed

Description

@YangHanqing

What happened?

When playing an Emby static/direct MP4 with AetherEngine 5.0.3, no first frame is presented.

AetherEngine cannot resolve a positive file size and falls back to streaming mode:

[AVIOReader] Persistent conn start gen=1 offset=0
[AVIOReader] Persistent conn gen=1 ended with error: <error text omitted from the debug report>
[AVIOReader] File size: -1 bytes (HEAD fallback) streaming mode
[AVIOReader] Streaming started: stream.mp4
[AVIOReader] Streaming ended

FFmpeg discovers the video, audio, and duration, but then reports a partial-file error:

[mov,mp4,m4a,3gp,3g2,mj2] stream 0, offset 0x2c: partial file
[Demuxer] Opened: 2 streams, duration=635088980 us
[Demuxer] stream[0] type=video codec=hevc 3840x2160
[Demuxer] stream[1] type=audio codec=aac

The native loopback-HLS path still creates a segment plan, but the first packet read fails immediately:

[HLSVideoEngine] cue prewarm: seek to 317.5s took 0.0ms
[HLSVideoEngine] segment plan: keyframe-aligned, 164 IRAPs → 151 segments
[HLSSegmentProducer] demuxer.readPacket threw: readFailed(code: -1)
[HLSSegmentProducer] pump finished: reason=readError(-1)
    packetsRead=0 packetsWritten=0 cacheCount=0

The local HLS asset is reported as playable and its duration is loaded, but it has no tracks or playable segments:

[NativeAVPlayerHost] asset.load(isPlayable) value=true
[NativeAVPlayerHost] asset.load(tracks) count=0
[NativeAVPlayerHost] timeControlStatus=waitingToPlay

engine.load() has already returned and the host marks the engine as ready, but playback never advances. It times out after 25 seconds without presenting a first frame.

Expected behavior:

  • Either produce playable loopback-HLS segments; or
  • fail before returning ready.

An unknown-length, forward-only MP4 should not enter a seek-dependent native HLS path and then silently produce zero packets.

Control test

The exact same Emby item, MediaSourceId, and static MP4 URL play normally in VLC without transcoding:

first source bytes: 1.64s
playback phase playing: 2.17s
video: HEVC 3840x2160, VideoToolbox
duration: 635.089s

This indicates that the media URL itself is playable. The issue may be related to AVIOReader's handling of this HTTP response's length/Range behavior and the subsequent native HLS segmentation path.

Steps to reproduce

  1. Use an Emby static/direct HTTP MP4.

  2. Force Aether direct playback with server transcoding disabled.

  3. Call engine.load(...) from position 0.

  4. Confirm the log contains:

    [AVIOReader] File size: -1 bytes (HEAD fallback) streaming mode
    
  5. Observe that FFmpeg discovers the streams and duration, then reports partial file.

  6. Observe that HLSSegmentProducer exits with readFailed(code: -1) and packetsRead=0.

  7. The local AVPlayer remains in waitingToPlay until the first-frame timeout.

  8. Play the same URL with VLC as a control; VLC starts normally.

AetherEngine version or commit SHA

5.0.3

Host app

Custom / my own integration

Platform

tvOS

OS version

tvOS 26.5

Device / chip

Apple TV 4K (3rd gen, 2022)

Playback path

Native AVPlayer

Source media (for playback bugs)

  • HTTP progressive MP4
  • HEVC, 3840×2160, 25 fps, SDR
  • AAC
  • Duration: 635.089 seconds
  • No subtitles
  • Emby static/direct stream, no server transcoding

Error codes / log lines

[AVIOReader] File size: -1 bytes (HEAD fallback) streaming mode
[mov,mp4,m4a,3gp,3g2,mj2] stream 0, offset 0x2c: partial file
[HLSSegmentProducer] demuxer.readPacket threw: readFailed(code: -1)
[HLSSegmentProducer] pump finished: reason=readError(-1)
    packetsRead=0 packetsWritten=0
[NativeAVPlayerHost] asset.load(tracks) count=0
[NativeAVPlayerHost] timeControlStatus=waitingToPlay

Anything else

This may be related to #8 and #70, but it reproduces on 5.0.3:

Current hypothesis:

  • When fileSize <= 0, AVIOReader enters forward-only streaming mode.
  • However, the reader still reports itself as seekable to the upper layers.
  • The native HLS path then performs index-related seeks.
  • The first packet read fails, and no HLS segments are produced.

This is only a hypothesis; please confirm the actual failure path.

Activity

  1. added
    bug
    on Jul 15, 2026
  2. superuser404notfound commented on Jul 15, 2026

    @superuser404notfound
    Owner

    Thanks for the exceptionally precise report. The log excerpts plus the VLC control test made this quick to pin down. Your hypothesis is confirmed, with one refinement on where exactly it breaks.

    Actual failure path

    1. The open-time data connection (Range: bytes=0-) resolved no usable length: the response carried neither a Content-Length nor a Content-Range total (the "ended with error" line is most likely the engine abandoning that connection for exactly that reason; if it was a genuine transport error the conclusion is the same). The dedicated range probe and the HEAD fallback also failed, so the reader degraded to forward-only streaming mode (File size: -1).
    2. The streaming reader still advertised itself as seekable, both to FFmpeg (AVIOContext.seekable) and to the engine's routing layer, violating its own provider contract. Your file has the moov at the tail (a first sample offset of 0x2c means ftyp + mdat come first), so the mov demuxer "seeked" forward to the moov, which the streaming reader served by downloading and discarding the mdat, parsed the full sample table (that is where the 164 IRAPs and the duration came from), and then seeked back to sample 0 at 0x2c. The streaming reader retains only a 1 MB back-window, so that seek returns -1, which mov reports as stream 0, offset 0x2c: partial file. Every subsequent readPacket dies the same way: readFailed(code: -1), packetsRead=0.
    3. The VOD pump's readError exit had no recovery or surfacing arm (only live sessions react to it), so the session died silently: playlist present, isPlayable=true, zero segments, waitingToPlay forever. That is the "returns ready with zero packets" half.

    The cue prewarm "took 0.0ms" is consistent with this: for mp4 that seek only repositions the in-memory sample cursor, no I/O.

    Fix

    Three layers, on fix/126-unknown-length-streaming-mode (cf388de):

    1. Last-resort bounded range probe. After bytes=0- and HEAD both fail, the reader now probes bytes=0-1. Origins that answer open-ended range requests with 200/chunked but honor real ranges (typical for Emby behind a buffering reverse proxy) answer 206 with the total in Content-Range, and the reader stays on the normal fully seekable path. Given that VLC can start and seek this source, I expect this layer alone to restore direct playback for your item.
    2. Honest seekability. If no probe resolves a size, the reader now reports itself non-seekable to FFmpeg and to routing. A moov-at-end file then fails cleanly at engine.load() instead of parsing an index it can never rewind to, and faststart files route to the sequential software path. This also removes a nasty side effect of the old behavior: the forward "seek" through the mdat buffered the entire skipped span in RAM.
    3. No silent zero-progress death. A VOD producer that exits on a read error having produced nothing (zero packets written, empty segment cache) now surfaces a fatal error to the host instead of leaving AVPlayer in waitingToPlay until a host-side timeout.

    One request

    To confirm which layer applies to your setup, could you capture the response headers for the bounded range against the same static URL?

    curl -s -o /dev/null -D - -H "Range: bytes=0-1" "<your stream.mp4 url>"
    

    A 206 with Content-Range: bytes 0-1/<total> means layer 1 restores full direct playback. A 200 without a length means the origin is genuinely length-less for this route and you should expect the clean load failure from layer 2 instead (plus whatever fallback your host does), in which case the interesting question becomes why this origin behaves differently from what VLC negotiates.

    The fix ships with the next release; I will ping here once it is tagged.

  3. superuser404notfound commented on Jul 15, 2026

    @superuser404notfound
    Owner

    The fix is released in 5.0.7. Please retest against your Emby item when you get a chance. With the bounded-range probe you should land on the normal seekable path (look for File size: ... bytes (bounded-range fallback) in the log); if the origin really exposes no length on any probe, you should now see a clean load failure instead of the silent 25s wait. The header capture from my previous comment is still useful to confirm which of the two you are getting.

  4. YangHanqing commented on Jul 16, 2026

    @YangHanqing
    Author

    I retested with AetherEngine 5.2.1. The original source reported in #126 now plays correctly.


    This is a different source that initially showed a similar symptom: unresolved size, forward-only streaming, software-path failure, and fallback. I traced this one to cross-origin redirect handling.

    The media-server URL redirects (307) to a cross-origin presigned object-storage URL. The presigned target is byte-seekable and returns 206 with Content-Range when requested normally.

    However, redirectPreservingHeaders currently reapplies extraHeaders on the cross-origin redirect. In this case, that includes the media-server Authorization header. The presigned target rejects the redirected request with HTTP 400 only when that header is replayed: the URL already uses query-string authentication, so the two authentication mechanisms conflict.

    As a result, the persistent reader and size probes cannot see the valid Content-Range, resolve fileSize as -1, and fall into forward-only streaming mode. This MP4 has its moov atom near the end, so the subsequent backward seek cannot work in that mode.

    A/B result, with the same engine build, file, and server:

    Authorization replayed cross-origin Authorization omitted
    size resolution unresolved / forward-only 310715302 bytes from Content-Range
    startup 17.1 s, then playback error 3.2 s, playing
    decode path forced software path native VideoToolbox H.264
    first frame not presented presented
    outcome fallback player Aether direct play

    With Authorization omitted, the persistent connection resolves the size directly from its initial Range: bytes=0- response, and the demuxer can seek to the tail moov atom normally.

    Could cross-origin redirect handling preserve Range but avoid replaying sensitive credentials such as Authorization to a different origin? The current unconditional replay may have been intended for proxy compatibility, so a per-header redirect policy may be safer than dropping every extra header cross-origin.

    This also avoids disclosing a media-server token to a redirect target.

  5. superuser404notfound commented on Jul 16, 2026

    @superuser404notfound
    Owner

    Thanks for confirming the original source, and for another exemplary diagnosis. Your read of the second failure is exactly right: redirectPreservingHeaders reapplied every extra header, including Authorization, on cross-origin redirects, the presigned target rejected the conflicting authentication with 400, and with the persistent connection and both probes blind the reader degraded to forward-only mode, which a tail-moov MP4 cannot survive. The unconditional replay dated back to a proxy-compatibility fix (#8) whose actual cross-origin requirement was only the Range header, so there was no reason for credentials to ride along.

    Fixed in 5.3.1 with the per-header policy you suggested:

    • Range and non-credential extra headers still survive cross-host redirects (the AVIOReader falls back to streaming mode when the origin rejects HEAD, breaking seekable playback #8 proxy behavior is unchanged).
    • Credential headers (Authorization, Proxy-Authorization, Cookie, X-Emby-Token, X-Emby-Authorization, X-MediaBrowser-Token) are replayed only to a same-host target with no TLS downgrade. A same-host http to https upgrade keeps credentials even across a port change (the typical media-server TLS redirect); anything else, including your media-server to object-storage hop, gets the credentials withheld and additionally scrubbed if the URL loading system carried them over itself.

    Your security point was a real motivator here: beyond the 400, the old behavior disclosed the server token to whatever host the redirect named. That is gone.

    With 5.3.1 your redirecting source should resolve 310715302 from the initial Range: bytes=0- response on the presigned target and stay on the native seekable path. A quick retest on that item would be appreciated.

  6. superuser404notfound commented on Jul 31, 2026

    @superuser404notfound
    Owner

    Checking back on this one. The per-header redirect policy shipped in 5.3.1 and the current release is 6.3.0, so a retest against the redirecting source is a short one: the presigned target should resolve the content length off the initial Range: bytes=0- response and stay on the native seekable path, with no 400 and no forward-only degradation.

    If it plays, this can be closed. If it still stalls, the request/response pair for the first two opens against the object-storage host would be the artifact to attach, since the remaining candidates are all on the response side rather than the header replay this fixed.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions