0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 20:03:10 +02:00

ytdl_hook: reenable support for length-less segments in EDL

They're unsupported only in MP4 DASH mode.
This commit is contained in:
Ricardo Constantino 2017-02-06 16:08:18 +00:00
parent 46a556bd4b
commit 5fbad204a6
No known key found for this signature in database
GPG Key ID: EFD16019AE4FF531

View File

@ -88,18 +88,36 @@ local function extract_chapters(data, video_length)
return ret return ret
end end
local function edl_track_joined(fragments) local function edl_track_joined(fragments, protocol)
if not (type(fragments) == "table") or not fragments[1] then
msg.debug("No fragments to join into EDL")
return nil
end
local edl = "edl://" local edl = "edl://"
local offset = 1 local offset = 1
if fragments[1] and not fragments[1].duration then
-- if no duration, probably initialization segment if (protocol == "http_dash_segments") and
not fragments[1].duration then
-- assume MP4 DASH initialization segment
edl = edl .. "!mp4_dash,init=" .. edl_escape(fragments[1].url) .. ";" edl = edl .. "!mp4_dash,init=" .. edl_escape(fragments[1].url) .. ";"
offset = 2 offset = 2
-- Check remaining fragments for duration;
-- if not available in all, give up.
for i = offset, #fragments do
if not fragments[i].duration then
msg.error("EDL doesn't support fragments" ..
"without duration with MP4 DASH")
return nil
end
end
end end
for i = offset, #fragments do for i = offset, #fragments do
local fragment = fragments[i] local fragment = fragments[i]
edl = edl .. edl_escape(fragment.url)
if fragment.duration then if fragment.duration then
edl = edl .. edl_escape(fragment.url)
edl = edl..",length="..fragment.duration edl = edl..",length="..fragment.duration
end end
edl = edl .. ";" edl = edl .. ";"
@ -285,25 +303,23 @@ mp.add_hook("on_load", 10, function ()
if not (json["requested_formats"] == nil) then if not (json["requested_formats"] == nil) then
for _, track in pairs(json.requested_formats) do for _, track in pairs(json.requested_formats) do
local edl_track = nil local edl_track = nil
if (track.protocol == "http_dash_segments") and edl_track = edl_track_joined(track.fragments,track.protocol)
(track.fragments ~= nil) then
edl_track = edl_track_joined(track.fragments)
end
if track.acodec and track.acodec ~= "none" then if track.acodec and track.acodec ~= "none" then
-- audio track
mp.commandv("audio-add", mp.commandv("audio-add",
edl_track or track.url, "auto", edl_track or track.url, "auto",
track.format_note or "") track.format_note or "")
elseif track.vcodec and track.vcodec ~= "none" then elseif track.vcodec and track.vcodec ~= "none" then
-- video track
streamurl = edl_track or track.url streamurl = edl_track or track.url
end end
end end
elseif not (json.url == nil) then elseif not (json.url == nil) then
local edl_track = nil local edl_track = nil
if json.protocol == "http_dash_segments" then edl_track = edl_track_joined(json.fragments, json.protocol)
edl_track = edl_track_joined(json.fragments)
end -- normal video or single track
-- normal video
streamurl = edl_track or json.url streamurl = edl_track or json.url
set_http_headers(json.http_headers) set_http_headers(json.http_headers)
else else