[PR #15699] Fix: Add FFmpeg reconnect flags for HTTP VOD streams to improve stability #14215

Open
opened 2025-12-22 10:23:04 +01:00 by backuprepo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/jellyfin/jellyfin/pull/15699
Author: @martenumberto
Created: 12/2/2025
Status: 🔄 Open

Base: release-10.11.zHead: fix-ffmpeg-http-reconnect


📝 Commits (3)

  • 71b170f Fix: Add FFmpeg reconnect flags for HTTP streams
  • 54325f3 Fix: Add FFmpeg reconnect flags for HTTP streams (Static Streams)
  • 499ea99 Contributors.md

📊 Changes

2 files changed (+6 additions, -0 deletions)

View changed files

📝 CONTRIBUTORS.md (+1 -0)
📝 MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs (+5 -0)

📄 Description

Describe the bug

Currently, Jellyfin playback stops immediately if an HTTP stream connection drops, times out, or is closed by the server/proxy prematurely (TCP FIN/RST).

This behavior is particularly problematic for:

  1. Proxies & Gateways: Some IPTV/M3U proxies explicitly close client connections to trigger failovers or refresh tokens.
  2. CDNs: Connections may be dropped due to load balancing or timeouts, which ffmpeg interprets as a valid EOF (End of File), causing the movie to stop halfway.
  3. Unstable Networks: Temporary packet loss causes the transcoder/remuxer to exit instead of retrying.

Logs typically show Stream ends prematurely followed by a clean exit of ffmpeg, leaving the user with a stopped video.

The Solution

This PR adds standard ffmpeg reconnect flags to the input arguments in EncodingHelper.cs.

Logic Changes:

  • Applies flags ONLY if the input protocol is Http (which in Jellyfin handles both http:// and https://).
  • Applies flags ONLY if IsInfiniteStream is false. This ensures that Live TV logic (Tuners/M3U Live) remains untouched to prevent interference with existing live buffer mechanisms.

Added Flags:

  • -reconnect 1: Retry connection on failure.
  • -reconnect_at_eof 1: Critical fix: Retry if the stream ends before the expected duration/header length (fixes "premature EOF" issues).
  • -reconnect_streamed 1: Allow reconnection for streamed data.
  • -reconnect_delay_max 30: Sets a generous max delay (30s) to allow upstream proxies or gateways enough time to recover or switch routes.

Testing Done

  • Environment: Jellyfin connecting to a custom upstream HTTP proxy for VOD content (.mkv via .strm).
  • Scenario: The proxy was forced to close the connection mid-stream (simulating a timeout or failover).
  • Before: Jellyfin playback stopped immediately. FFmpeg log showed Stream ends prematurely.
  • After: FFmpeg logged Will reconnect at ..., successfully re-established the connection, and playback continued to the end of the file without user intervention.

Checklist

  • I have read the contributing guidelines.
  • I have verified that my change is targeting the correct branch.
  • I have verified that my changes do not break existing functionality (Live TV is excluded).

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/jellyfin/jellyfin/pull/15699 **Author:** [@martenumberto](https://github.com/martenumberto) **Created:** 12/2/2025 **Status:** 🔄 Open **Base:** `release-10.11.z` ← **Head:** `fix-ffmpeg-http-reconnect` --- ### 📝 Commits (3) - [`71b170f`](https://github.com/jellyfin/jellyfin/commit/71b170faf2a8687d9f71ee040272b11cc1120b43) Fix: Add FFmpeg reconnect flags for HTTP streams - [`54325f3`](https://github.com/jellyfin/jellyfin/commit/54325f353bcffcf090f641f4848f948733f1e4b2) Fix: Add FFmpeg reconnect flags for HTTP streams (Static Streams) - [`499ea99`](https://github.com/jellyfin/jellyfin/commit/499ea9919646bd53f0214e4dadf78ba83c58a8c5) Contributors.md ### 📊 Changes **2 files changed** (+6 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `CONTRIBUTORS.md` (+1 -0) 📝 `MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs` (+5 -0) </details> ### 📄 Description ### Describe the bug Currently, Jellyfin playback stops immediately if an HTTP stream connection drops, times out, or is closed by the server/proxy prematurely (TCP FIN/RST). This behavior is particularly problematic for: 1. **Proxies & Gateways:** Some IPTV/M3U proxies explicitly close client connections to trigger failovers or refresh tokens. 2. **CDNs:** Connections may be dropped due to load balancing or timeouts, which `ffmpeg` interprets as a valid `EOF` (End of File), causing the movie to stop halfway. 3. **Unstable Networks:** Temporary packet loss causes the transcoder/remuxer to exit instead of retrying. Logs typically show `Stream ends prematurely` followed by a clean exit of ffmpeg, leaving the user with a stopped video. ### The Solution This PR adds standard `ffmpeg` reconnect flags to the input arguments in `EncodingHelper.cs`. **Logic Changes:** * Applies flags **ONLY** if the input protocol is `Http` (which in Jellyfin handles both `http://` and `https://`). * Applies flags **ONLY** if `IsInfiniteStream` is `false`. This ensures that **Live TV** logic (Tuners/M3U Live) remains untouched to prevent interference with existing live buffer mechanisms. **Added Flags:** * `-reconnect 1`: Retry connection on failure. * `-reconnect_at_eof 1`: **Critical fix:** Retry if the stream ends before the expected duration/header length (fixes "premature EOF" issues). * `-reconnect_streamed 1`: Allow reconnection for streamed data. * `-reconnect_delay_max 30`: Sets a generous max delay (30s) to allow upstream proxies or gateways enough time to recover or switch routes. ### Testing Done * **Environment:** Jellyfin connecting to a custom upstream HTTP proxy for VOD content (.mkv via .strm). * **Scenario:** The proxy was forced to close the connection mid-stream (simulating a timeout or failover). * **Before:** Jellyfin playback stopped immediately. FFmpeg log showed `Stream ends prematurely`. * **After:** FFmpeg logged `Will reconnect at ...`, successfully re-established the connection, and playback continued to the end of the file without user intervention. ### Checklist - [x] I have read the contributing guidelines. - [x] I have verified that my change is targeting the correct branch. - [x] I have verified that my changes do not break existing functionality (Live TV is excluded). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
backuprepo added the
pull-request
label 2025-12-22 10:23:04 +01:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: starred/jellyfin#14215
No description provided.