Repository navigation
Description
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
-
Use an Emby static/direct HTTP MP4.
-
Force Aether direct playback with server transcoding disabled.
-
Call
engine.load(...)from position 0. -
Confirm the log contains:
[AVIOReader] File size: -1 bytes (HEAD fallback) streaming mode -
Observe that FFmpeg discovers the streams and duration, then reports
partial file. -
Observe that
HLSSegmentProducerexits withreadFailed(code: -1)andpacketsRead=0. -
The local AVPlayer remains in
waitingToPlayuntil the first-frame timeout. -
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:
- AVIOReader falls back to streaming mode when the origin rejects HEAD, breaking seekable playback #8: falling back to streaming mode when the source length cannot be resolved breaks seekable playback.
- AVIOReader issues a redundant size probe (Range bytes=0-0 → HEAD) that the first data connection already answers #70: file-size probing and HEAD fallback can downgrade a source to streaming mode.
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
superuser404notfound commentedon Jul 15, 2026
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
Range: bytes=0-) resolved no usable length: the response carried neither aContent-Lengthnor aContent-Rangetotal (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).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 asstream 0, offset 0x2c: partial file. Every subsequentreadPacketdies the same way:readFailed(code: -1),packetsRead=0.readErrorexit had no recovery or surfacing arm (only live sessions react to it), so the session died silently: playlist present,isPlayable=true, zero segments,waitingToPlayforever. 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):bytes=0-and HEAD both fail, the reader now probesbytes=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 inContent-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.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.waitingToPlayuntil 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?
A
206withContent-Range: bytes 0-1/<total>means layer 1 restores full direct playback. A200without 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.
superuser404notfound commentedon Jul 15, 2026
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.YangHanqing commentedon Jul 16, 2026
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
206withContent-Rangewhen requested normally.However,
redirectPreservingHeaderscurrently reappliesextraHeaderson the cross-origin redirect. In this case, that includes the media-serverAuthorizationheader. 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, resolvefileSizeas-1, and fall into forward-only streaming mode. This MP4 has itsmoovatom near the end, so the subsequent backward seek cannot work in that mode.A/B result, with the same engine build, file, and server:
Authorizationreplayed cross-originAuthorizationomitted310715302bytes fromContent-RangeWith
Authorizationomitted, the persistent connection resolves the size directly from its initialRange: bytes=0-response, and the demuxer can seek to the tailmoovatom normally.Could cross-origin redirect handling preserve
Rangebut avoid replaying sensitive credentials such asAuthorizationto 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.
Merge fix/126-cross-origin-credential-redirect: per-header redirect p…
superuser404notfound commentedon Jul 16, 2026
Thanks for confirming the original source, and for another exemplary diagnosis. Your read of the second failure is exactly right:
redirectPreservingHeadersreapplied every extra header, includingAuthorization, 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 theRangeheader, so there was no reason for credentials to ride along.Fixed in 5.3.1 with the per-header policy you suggested:
Rangeand 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).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
310715302from the initialRange: bytes=0-response on the presigned target and stay on the native seekable path. A quick retest on that item would be appreciated.fix(io): unknown-length HTTP MP4 must not enter seek-dependent paths (s…
fix(avio): stop replaying credential headers on cross-origin redirects (
fix(video): recover from a VOD producer that dies mid-session at the …
superuser404notfound commentedon Jul 31, 2026
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.
fix(routing): a sequential origin keeps the native path
fix(video): a VOD pump that produced nothing says so, whatever killed it
fix(hls): the cue prewarm may not run where a seek is a linear read (s…
fix(prewarm): a warm hands over its resolved target, its Matroska tai…
fix(hls): keep credential headers on the host's origin when a playlis…
fix(demuxer): the held connection applies the redirect header policy …
feat(hls): persistent HTTP/1.1 transport for the HLS VOD ingest under…