]> git.sesse.net Git - nageru/commitdiff
Deliver more precise timestamps from FFmpegCapture.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 18 Apr 2018 22:43:54 +0000 (00:43 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 22 Apr 2018 13:17:32 +0000 (15:17 +0200)
ffmpeg_capture.cpp

index 9ae35042d1ce998701e34b9072ca26b2700d047f..c79ecf337fe8213efe16b26f3e3cd436c5c4dfe5 100644 (file)
@@ -484,7 +484,13 @@ bool FFmpegCapture::play_video(const string &pathname)
                                }
                        }
                        video_frame->received_timestamp = next_frame_start;
-                       audio_frame->received_timestamp = next_frame_start;
+
+                       // The easiest way to get all the rate conversions etc. right is to move the
+                       // audio PTS into the video PTS timebase and go from there. (We'll get some
+                       // rounding issues, but they should not be a big problem.)
+                       int64_t audio_pts_as_video_pts = av_rescale_q(audio_pts, audio_timebase, video_timebase);
+                       audio_frame->received_timestamp = compute_frame_start(audio_pts_as_video_pts, pts_origin, video_timebase, start, rate);
+
                        bool finished_wakeup = producer_thread_should_quit.sleep_until(next_frame_start);
                        if (finished_wakeup) {
                                if (audio_frame->len > 0) {