From 87e889d89166ad7566fe47aa9fcb63a6b5eb42f0 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sun, 17 May 2026 20:39:27 +0200 Subject: [PATCH] ytdl_hook.lua: get the duration of fragmented mp4 Changing all_formats' default to true broke reporting the duration of bilibili.tv videos because fragmented MP4 files have the duration in a segment index box and not in the container header. With all_formats=false the requested formats are opened immediately and libavformat uses HTTP range requests to probe the fragmented MP4 and reads the correct duration. With all_formats=true every format gets !delay_open and libavformat can't seek for the sidx in that sub-demuxer context. Fix this by not applying delay_open to the requested formats. Fixes https://github.com/mpv-player/mpv/pull/17762#issuecomment-4468518894. --- player/lua/ytdl_hook.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua index c8d3d71ab1d43..042f447d722d6 100644 --- a/player/lua/ytdl_hook.lua +++ b/player/lua/ytdl_hook.lua @@ -553,8 +553,11 @@ local function formats_to_edl(json, formats, use_all_formats) elseif sub.media_type == "audio" then props = props .. ",samplerate=" .. as_integer(track.asr) end - hdr[#hdr + 1] = "!delay_open,media_type=" .. sub.media_type .. - ",codec=" .. (sub.codec or "null") .. props + + if not is_default then + hdr[#hdr + 1] = "!delay_open,media_type=" .. sub.media_type .. + ",codec=" .. (sub.codec or "null") .. props + end -- Add bitrate information etc. for better user selection. local byterate = 0