From 7885bec3b304f79b1933156b624a293df64f7aa3 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 19 Feb 2022 00:28:50 +0100 Subject: Attempt to fix video/audio desync on youtube (load audio at same time as video) --- video_player/src/main.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'video_player') diff --git a/video_player/src/main.cpp b/video_player/src/main.cpp index 7489873..03acd93 100644 --- a/video_player/src/main.cpp +++ b/video_player/src/main.cpp @@ -255,12 +255,21 @@ static void mpv_set_before_init_options(mpv_handle *mpv_ctx, const Args &args) { else check_error(mpv_set_option_string(mpv_ctx, property.key.c_str(), property.value.c_str()), property.key.c_str()); } -} -static void mpv_set_after_load_options(mpv_handle *mpv_ctx, const Args &args) { if(args.audio_file) { - const char* cmd_args[] = { "audio-add", args.audio_file, "select", "Default track", nullptr }; - check_error(mpv_command_async(mpv_ctx, 0, cmd_args), "audio-add"); + mpv_node first_element; + first_element.format = MPV_FORMAT_STRING; + first_element.u.string = (char*)args.audio_file; + + mpv_node_list list; + list.num = 1; + list.keys = NULL; + list.values = &first_element; + + mpv_node node; + node.format = MPV_FORMAT_NODE_ARRAY; + node.u.list = &list; + check_error(mpv_set_option(mpv_ctx, "audio-files", MPV_FORMAT_NODE, &node), "audio-files"); } } @@ -313,7 +322,6 @@ int main(int argc, char **argv) { if(event->event_id == MPV_EVENT_START_FILE && !file_started) { file_started = true; - mpv_set_after_load_options(mpv_ctx, args); } else if(event->event_id == MPV_EVENT_SHUTDOWN) { running = false; break; -- cgit v1.2.3