X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=ffmpeg_capture.cpp;h=e03382cec5418c8732bff8f0ecbc0d8346cb0544;hb=bf6f4393ef3282685392858aaef8151f63e8b3c2;hp=5474c52fd94f511491206e4f8a92b2545bc87475;hpb=f07adb19f0e2571bf4894ec57e6fcfe4a3e5fd95;p=nageru diff --git a/ffmpeg_capture.cpp b/ffmpeg_capture.cpp index 5474c52..e03382c 100644 --- a/ffmpeg_capture.cpp +++ b/ffmpeg_capture.cpp @@ -189,9 +189,7 @@ bool FFmpegCapture::play_video(const string &pathname) unique_ptr codec_ctx_cleanup( codec_ctx.get(), avcodec_close); - int64_t pts_origin = 0, last_pts = 0; - steady_clock::time_point start = steady_clock::now(); - steady_clock::time_point next_frame_start = start; + internal_rewind(); double rate = 1.0; unique_ptr sws_ctx(nullptr, sws_freeContext); @@ -211,8 +209,7 @@ bool FFmpegCapture::play_video(const string &pathname) if (av_seek_frame(format_ctx.get(), /*stream_index=*/-1, /*timestamp=*/0, /*flags=*/0) < 0) { fprintf(stderr, "%s: Rewind failed, stopping play.\n", pathname.c_str()); } - pts_origin = last_pts = 0; - start = next_frame_start = steady_clock::now(); + internal_rewind(); break; case QueuedCommand::CHANGE_RATE: @@ -263,8 +260,7 @@ bool FFmpegCapture::play_video(const string &pathname) fprintf(stderr, "%s: Rewind failed, not looping.\n", pathname.c_str()); return true; } - pts_origin = last_pts = 0; - start = steady_clock::now(); + internal_rewind(); continue; } @@ -314,3 +310,9 @@ bool FFmpegCapture::play_video(const string &pathname) } return true; } + +void FFmpegCapture::internal_rewind() +{ + pts_origin = last_pts = 0; + start = next_frame_start = steady_clock::now(); +}