aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-09-17 16:10:51 +0200
committerdec05eba <dec05eba@protonmail.com>2022-09-17 16:10:51 +0200
commit9f2f4240bafbc5a44afa2e0faf31d7901da0aaea (patch)
tree5a276c2982ba0ea1125d9299a38b617b8f226017 /src
parent49c876ca0037f72165d97e60640af788847101bc (diff)
Attempt to fix video/audio desync when video pts gets desynced with clock
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 5f59bea..fb466c2 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1582,9 +1582,11 @@ int main(int argc, char **argv) {
// res = cuCtxPopCurrent(&old_ctx);
}
- // TODO: Check if duplicate frame can be saved just by writing it with a different pts instead of sending it again
const double this_video_frame_time = clock_get_monotonic_seconds();
- const int num_frames = std::max(1.0, std::round((this_video_frame_time - prev_video_frame_time) / target_fps));
+ const int64_t expected_frames = (this_video_frame_time - start_time_pts) / target_fps;
+
+ const int num_frames = std::max(0L, expected_frames - video_pts_counter);
+ // TODO: Check if duplicate frame can be saved just by writing it with a different pts instead of sending it again
for(int i = 0; i < num_frames; ++i) {
frame->pts = video_pts_counter + i;
if (avcodec_send_frame(video_codec_context, frame) >= 0) {