Only capture frame if num frames to capture > 0

This commit is contained in:
dec05eba 2023-04-18 22:31:44 +02:00
parent 3bb22d0b3e
commit 690065da0f

View File

@ -1933,13 +1933,14 @@ int main(int argc, char **argv) {
if (frame_time_overflow >= 0.0) { if (frame_time_overflow >= 0.0) {
frame_time_overflow = std::min(frame_time_overflow, target_fps); frame_time_overflow = std::min(frame_time_overflow, target_fps);
frame_timer_start = time_now - frame_time_overflow; frame_timer_start = time_now - frame_time_overflow;
gsr_capture_capture(capture, frame);
const double this_video_frame_time = clock_get_monotonic_seconds(); const double this_video_frame_time = clock_get_monotonic_seconds();
const int64_t expected_frames = std::round((this_video_frame_time - start_time_pts) / target_fps); const int64_t expected_frames = std::round((this_video_frame_time - start_time_pts) / target_fps);
const int num_frames = framerate_mode == FramerateMode::CONSTANT ? std::max(0L, expected_frames - video_pts_counter) : 1; const int num_frames = framerate_mode == FramerateMode::CONSTANT ? std::max(0L, expected_frames - video_pts_counter) : 1;
if(num_frames > 0) {
gsr_capture_capture(capture, frame);
// TODO: Check if duplicate frame can be saved just by writing it with a different pts instead of sending it again // 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) { for(int i = 0; i < num_frames; ++i) {
if(framerate_mode == FramerateMode::CONSTANT) { if(framerate_mode == FramerateMode::CONSTANT) {
@ -1963,6 +1964,7 @@ int main(int argc, char **argv) {
} }
video_pts_counter += num_frames; video_pts_counter += num_frames;
} }
}
if(save_replay_thread.valid() && save_replay_thread.wait_for(std::chrono::seconds(0)) == std::future_status::ready) { if(save_replay_thread.valid() && save_replay_thread.wait_for(std::chrono::seconds(0)) == std::future_status::ready) {
save_replay_thread.get(); save_replay_thread.get();