diff options
author | wm4 <wm4@nowhere> | 2020-02-21 14:29:55 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-02-21 14:29:55 +0100 |
commit | 6337c1cc1423e3a7c8e82bb39b04055ee102663c (patch) | |
tree | 90d612f82d008382c383f73e92e6171f6e9d3c38 | |
parent | 04118eefb8a19e7bb1de56257a9b1ddc5dc6ebb7 (diff) | |
download | mpv-6337c1cc1423e3a7c8e82bb39b04055ee102663c.tar.bz2 mpv-6337c1cc1423e3a7c8e82bb39b04055ee102663c.tar.xz |
ytdl_hook: make codec mapping more declarative
-rw-r--r-- | player/lua/ytdl_hook.lua | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua index 28600530da..05e7624221 100644 --- a/player/lua/ytdl_hook.lua +++ b/player/lua/ytdl_hook.lua @@ -40,9 +40,13 @@ local safe_protos = Set { } local codec_map = { + -- src pattern = mpv codec ["vtt"] = "webvtt", ["opus"] = "opus", ["vp9"] = "vp9", + ["avc1\..*"] = "h264", + ["av01\..*"] = "av1", + ["mp4a\..*"] = "aac", } -- Codec name as reported by youtube-dl mapped to mpv internal codec names. @@ -54,18 +58,11 @@ local function map_codec_to_mpv(codec) if codec == nil then return nil end - local mc = codec_map[codec] - if mc then - return mc - end - if codec:sub(1, 5) == "avc1." then - return "h264" - end - if codec:sub(1, 5) == "av01." then - return "av1" - end - if codec:sub(1, 5) == "mp4a." then - return "aac" + for k, v in pairs(codec_map) do + local s, e = codec:find(k) + if s == 1 and e == #codec then + return v + end end return nil end |