From cb0dcfa84f9529ee371ff41ee6813c9bea71766a Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 30 Dec 2018 12:20:59 +0100 Subject: [PATCH] Do a small hack in Futatabi to make sure that Nageru gets the subtitles in time. --- futatabi/video_stream.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/futatabi/video_stream.cpp b/futatabi/video_stream.cpp index 745da27..59ab8bf 100644 --- a/futatabi/video_stream.cpp +++ b/futatabi/video_stream.cpp @@ -615,6 +615,20 @@ void VideoStream::encode_thread_func() frame_queue.pop_front(); } + // Hack: We mux the subtitle packet one time unit before the actual frame, + // so that Nageru is sure to get it first. + if (!qf.subtitle.empty()) { + AVPacket pkt; + av_init_packet(&pkt); + pkt.stream_index = mux->get_subtitle_stream_idx(); + assert(pkt.stream_index != -1); + pkt.data = (uint8_t *)qf.subtitle.data(); + pkt.size = qf.subtitle.size(); + pkt.flags = 0; + pkt.duration = lrint(TIMEBASE / global_flags.output_framerate); // Doesn't really matter for Nageru. + mux->add_packet(pkt, qf.output_pts - 1, qf.output_pts - 1); + } + if (qf.type == QueuedFrame::ORIGINAL) { // Send the JPEG frame on, unchanged. string jpeg = frame_reader.read_frame(qf.frame1); @@ -681,19 +695,6 @@ void VideoStream::encode_thread_func() } else { assert(false); } - - if (!qf.subtitle.empty()) { - AVPacket pkt; - av_init_packet(&pkt); - pkt.stream_index = mux->get_subtitle_stream_idx(); - assert(pkt.stream_index != -1); - pkt.data = (uint8_t *)qf.subtitle.data(); - pkt.size = qf.subtitle.size(); - pkt.flags = 0; - pkt.duration = lrint(TIMEBASE / global_flags.output_framerate); // Doesn't really matter for Nageru. - mux->add_packet(pkt, qf.output_pts, qf.output_pts); - } - if (qf.display_func != nullptr) { qf.display_func(); } -- 2.39.2