From 76aaf74d30039df10e114c4e771bc9e3ddc779d5 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 21 Feb 2020 11:57:21 +0100 Subject: ytdl_hook: use tbr for all tracks if vbr/abr not available vbr and abr are the video and audio bitrates. Sometimes there is a weird mix of any of them available, but in these cases, it's not good to fall back to tbr if a specific track has no vbr/abr. For example, the alphabetic site provides tbr only for the muxed fallback stream, but using tbr would make the primitive mpv hls_bitrate selection pick the compatibility stream for audio, because it appears to have a higher bitrate than the other audio-only streams (because the bitrate includes video). So we must not use tbr in this case. On the other hand, formats coming from youtube-dl HLS master playlist use will only have tbr set. So as a heuristic, use the tbr only if it's the only bitrate available in any track entry. --- player/lua/ytdl_hook.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua index 7269f3f4b7..67eac3f4ae 100644 --- a/player/lua/ytdl_hook.lua +++ b/player/lua/ytdl_hook.lua @@ -344,6 +344,12 @@ local function formats_to_edl(json, formats, use_all_formats) local single_url = nil local streams = {} + local tbr_only = true + for index, track in ipairs(formats) do + tbr_only = tbr_only and track["tbr"] and + (not track["abr"]) and (not track["vbr"]) + end + for index, track in ipairs(formats) do local edl_track = nil edl_track = edl_track_joined(track.fragments, @@ -392,6 +398,9 @@ local function formats_to_edl(json, formats, use_all_formats) if #tracks > 1 then rates = {({video = "vbr", audio = "abr"})[sub.media_type]} end + if tbr_only then + rates = {"tbr"} + end for _, f in ipairs(rates) do local br = as_integer(track[f]) if br > 0 then -- cgit v1.2.3