iptvnator icon indicating copy to clipboard operation
iptvnator copied to clipboard

Embedded MPV: Streams stop after 15–20 seconds in v0.24.0

Open xg1ll opened this issue 2 months ago • 2 comments

Describe the bug

In IPTVnator 0.24.0, live streams played using the embedded MPV player stop working after approximately 15–20 seconds when using an Xtream Codes login.

The same Xtream Codes account and live streams work perfectly in IPTVnator 0.23.

With IPTVnator 0.24.0, the stream initially starts playing normally, but after approximately 15–20 seconds it stops. IPTVnator then attempts to reconnect to the stream. The reconnect succeeds temporarily, but the stream stops again after a few seconds. This continues until all 6 automatic reconnect attempts have been exhausted, after which IPTVnator displays "the live stream ended".

The same streams also work correctly when using VLC or MPV as external players.

To Reproduce

Steps to reproduce the behavior:

  1. Install IPTVnator 0.24.0 from iptvnator-0.24.0-linux-amd64.deb.
  2. Add an IPTV provider using an Xtream Codes login.
  3. Open the Live TV section.
  4. Select any live stream.
  5. Play the stream using the embedded MPV player.
  6. After approximately 15–20 seconds, the stream stops.
  7. IPTVnator automatically attempts to reconnect.
  8. The stream resumes briefly, then stops again.
  9. This repeats until all 6 reconnect attempts have been exhausted.
  10. IPTVnator then displays "the live stream ended".

The reconnect timing appears to be consistent. The first reconnect occurs after approximately 15–20 seconds, then the next reconnect occurs approximately 5 seconds later. This pattern continues until all 6 reconnect attempts have been exhausted.

If "Reconnect dropped streams automatically" is disabled, the stream simply stops after approximately 15–20 seconds and displays "the live stream ended".

Expected behavior

The live stream should continue playing normally without stopping or repeatedly reconnecting.

The same Xtream Codes account and streams work correctly in IPTVnator 0.23.

Screenshots

Not applicable. Logs can be provided if required.

Desktop

  • Application: Electron/Tauri application
  • OS: Ubuntu 26.04.1
  • Version: 0.24.0
  • Feature: Xtream Codes
  • Package: iptvnator-0.24.0-linux-amd64.deb

Additional context

  • IPTVnator 0.23 works perfectly with the same Xtream Codes account and streams.
  • Re-downloading and reinstalling IPTVnator 0.23 confirms that the streams continue to work correctly.
  • The issue occurs specifically with the embedded MPV player in IPTVnator 0.24.0.
  • VLC as an external player works correctly with the same streams.
  • MPV as an external player also works correctly with the same streams.
  • The issue appears to be specific to the embedded MPV implementation or a change introduced in IPTVnator 0.24.0.
  • The problem occurs with multiple live streams tested through the same Xtream Codes account.

xg1ll avatar Sep 24 '26 14:09 xg1ll

Update: workaround / root cause isolated

I have now isolated the issue to the FFmpeg reconnect_streamed option introduced in v0.24.

With the default v0.24 configuration, the stream consistently stops after approximately 15–20 seconds.

The following tests did not resolve the problem:

  • hwdec=no
  • network-timeout=60
  • network-timeout=300

However, setting:

demuxer-lavf-o=reconnect_streamed=0

allows the stream to play normally and continuously.

demuxer-lavf-o=reconnect=0

also works.

Therefore, the issue appears to be specifically related to the default:

reconnect_streamed=1

introduced with the embedded MPV reconnect changes in v0.24.

Current workaround

demuxer-lavf-o=reconnect_streamed=0

With IPTVNATOR_TRACE_PLAYER=1, the failing configuration produces:

loading -> playing -> ended

after approximately 15–20 seconds.

The same streams play continuously in:

  • IPTVnator v0.23
  • External MPV
  • VLC

xg1ll avatar Sep 24 '26 20:09 xg1ll

I think I found the root cause of this, and why reconnect_streamed=0 fixes it.

Cause

FFmpeg records an HTTP response that has no Content-Length as unknown-size (filesize = UINT64_MAX). In http_read_stream() the "premature end" check is

bool is_premature = s->filesize > 0 && s->off < s->filesize;   // FFmpeg 8.0, libavformat/http.c

which is therefore always true for such a response. IPTV CDNs usually don't send Accept-Ranges, so the response is also is_streamed, and the only thing that normally stops FFmpeg from reconnecting is if (h->is_streamed && !s->reconnect_streamed) break;.

With the v0.24 default demuxer-lavf-o=reconnect=1,reconnect_streamed=1,reconnect_delay_max=5, every normal end of an HLS playlist or segment served without a length (Connection: close, or chunked) is treated as a dropped connection: FFmpeg requests the same playlist/segment again with 0 s → 1 s → 3 s backoff before giving up. Live HLS falls behind the live edge and stalls once the initial buffer is used up, which is the ~15–20 s in this report. If the playlist itself has no length, playback never starts.

The same check is in FFmpeg 6.1, 7.1, 8.0 and current master (where it reads requested_end(s), still UINT64_MAX when unknown).

Reproduction

mpv 0.41.0 / FFmpeg 8.0.1 (Ubuntu 26.04 container), --no-config --vo=null --ao=null --network-timeout=10 plus the demuxer-lavf-o value below. The source is a local mock "panel" (302 to a mock CDN), and the CDN serves a sliding live window of 4 s segments. 50 s per run:

CDN response framing reconnect=1,reconnect_streamed=1,… (v0.24 default) reconnect=1,reconnect_streamed=0,… reconnect=1,reconnect_delay_max=5
Content-Length 15 segment requests / 15 unique ✅ 15 / 15 ✅ 15 / 15 ✅
no length, Connection: close 0 segments, 66,687 "Will reconnect" lines: never starts 15 / 15 ✅ 15 / 15 ✅
Transfer-Encoding: chunked 20 requests / 6 unique: each segment fetched 4× (t, t+1 s, t+4 s), segments skipped, stalls 15 / 15 ✅ 15 / 15 ✅

mpv logs Stream ends prematurely at N, should be 18446744073709551615 followed by Will reconnect at N in 0 second(s) at the end of every unframed response.

A side note for anyone changing this later: for a plain .ts live URL, mpv opens the HTTP stream itself, so demuxer-lavf-o never reaches FFmpeg's http protocol. With a mock CDN that drops the connection after 15 s, I saw zero FFmpeg reconnects with either value. In practice the option only affects HLS, where FFmpeg's demuxer opens the nested requests.

Mock server used (local only)
# python3 mock_hls.py SEGDIR PANEL_PORT CDN_PORT MODE   (MODE: cl | close | chunked)
# SEGDIR: ffmpeg -i any.ts -c copy -f hls -hls_time 4 -hls_list_size 0 -hls_segment_filename 'SEGDIR/s%03d.ts' SEGDIR/all.m3u8
import asyncio, re, sys, time
SEGDIR, PANEL, CDN, MODE = sys.argv[1], int(sys.argv[2]), int(sys.argv[3]), sys.argv[4]
segs = re.findall(r"#EXTINF:([\d.]+),\n(s\d+\.ts)", open(f"{SEGDIR}/all.m3u8").read())
T0 = time.monotonic()

async def send(w, ctype, body):
    h = f"HTTP/1.1 200 OK\r\nContent-Type: {ctype}\r\n"
    if MODE == "cl": w.write(f"{h}Content-Length: {len(body)}\r\nConnection: close\r\n\r\n".encode() + body)
    elif MODE == "close": w.write(f"{h}Connection: close\r\n\r\n".encode() + body)
    else:
        w.write(f"{h}Transfer-Encoding: chunked\r\nConnection: close\r\n\r\n".encode())
        for i in range(0, len(body), 65536):
            c = body[i:i + 65536]; w.write(f"{len(c):x}\r\n".encode() + c + b"\r\n")
        w.write(b"0\r\n\r\n")
    await w.drain(); w.close()

def playlist():  # sliding live window, 12 s available at start
    now, t, avail = time.monotonic() - T0 + 12, 0, []
    for i, (d, n) in enumerate(segs):
        t += float(d)
        if t > now: break
        avail.append((i, d, n))
    win = avail[-4:]
    return ("#EXTM3U\n#EXT-X-VERSION:3\n#EXT-X-TARGETDURATION:5\n"
            f"#EXT-X-MEDIA-SEQUENCE:{win[0][0]}\n" +
            "".join(f"#EXTINF:{d},\n/hls/tok/{n}\n" for _, d, n in win)).encode()

async def handle(r, w, panel):
    path = (await r.readuntil(b"\r\n\r\n")).split()[1].decode()
    if panel:
        w.write(f"HTTP/1.1 302 Found\r\nLocation: http://127.0.0.1:{CDN}/hls/tok/index.m3u8\r\nContent-Length: 0\r\nConnection: close\r\n\r\n".encode())
        await w.drain(); w.close(); return
    print(f"{time.monotonic() - T0:6.1f}s {path}", flush=True)
    if path.endswith(".m3u8"): await send(w, "application/vnd.apple.mpegurl", playlist())
    else: await send(w, "video/mp2t", open(f"{SEGDIR}/{path.rsplit('/', 1)[-1]}", "rb").read())

async def main():
    await asyncio.start_server(lambda r, w: handle(r, w, True), "127.0.0.1", PANEL)
    await asyncio.start_server(lambda r, w: handle(r, w, False), "127.0.0.1", CDN)
    await asyncio.Event().wait()
asyncio.run(main())
mpv --no-config --vo=null --ao=null --network-timeout=10 \
  --demuxer-lavf-o=reconnect=1,reconnect_streamed=1,reconnect_delay_max=5 \
  http://127.0.0.1:PANEL_PORT/live/user/pass/1.m3u8

I'll open a PR that drops reconnect_streamed=1 from EMBEDDED_MPV_NETWORK_DEFAULT_OPTIONS (keeping reconnect=1 for seekable responses), with a regression test and the docs update.

marinionroids avatar Nov 08 '26 15:11 marinionroids