mpv2oboeru

mpv helpers to create flashcards from movies and TV shows
git clone anongit@rnpnr.xyz:mpv2oboeru.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 69806b75275ab6dbeb9d280b676f719a1846fc71
Parent: 568a1bd654eceac57de291da85dee98765e0830e
Author: Ren Tatsumoto
Date:   Tue,  4 Aug 2020 21:49:18 +0300

select the right audio track if there's more than one of them

Diffstat:
Msubs2srs.lua | 20+++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/subs2srs.lua b/subs2srs.lua @@ -171,6 +171,23 @@ function add_extension(filename, extension) return filename .. extension end +function get_audio_track_number() + local audio_track_number = 0 + local tracks_count = mp.get_property_number("track-list/count") + + for i = 1, tracks_count do + local track_type = mp.get_property(string.format("track-list/%d/type", i)) + local track_index = mp.get_property_number(string.format("track-list/%d/ff-index", i)) + local track_selected = mp.get_property(string.format("track-list/%d/selected", i)) + + if track_type == "audio" and track_selected == "yes" then + audio_track_number = track_index - 1 + break + end + end + return audio_track_number +end + ffmpeg.execute = function(args) if next(args) ~= nil then for i, value in ipairs(ffmpeg.prefix) do @@ -202,13 +219,14 @@ end ffmpeg.create_audio = function(sub, audio_filename) local video_path = mp.get_property("path") local fragment_path = config.collection_path .. audio_filename + local track_number = get_audio_track_number() ffmpeg.execute{'-vn', '-ss', tostring(sub['start']), '-to', tostring(sub['end']), '-i', video_path, '-map_metadata', '-1', - '-map', 'a', + '-map', string.format("0:a:%d", track_number), '-ac', 1, '-codec:a', 'libopus', '-vbr', 'on',