aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2023-04-18 22:31:44 +0200
committerdec05eba <dec05eba@protonmail.com>2023-04-18 22:31:44 +0200
commit690065da0fa9344c41782aba0a29e38b79c94d84 (patch)
treec8dd6968436c5c2014e3ffad35786c9e16c3147c /src/main.cpp
parent3bb22d0b3e4119d32cd1555cc33f5b66e5ed04eb (diff)
Only capture frame if num frames to capture > 0
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 05db5b0..45bc77e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1933,35 +1933,37 @@ int main(int argc, char **argv) {
if (frame_time_overflow >= 0.0) {
frame_time_overflow = std::min(frame_time_overflow, target_fps);
frame_timer_start = time_now - frame_time_overflow;
- gsr_capture_capture(capture, frame);
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 int num_frames = framerate_mode == FramerateMode::CONSTANT ? std::max(0L, expected_frames - video_pts_counter) : 1;
- // 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) {
- if(framerate_mode == FramerateMode::CONSTANT) {
- frame->pts = video_pts_counter + i;
- } else {
- frame->pts = (this_video_frame_time - record_start_time) * (double)AV_TIME_BASE;
- const bool same_pts = frame->pts == video_prev_pts;
- video_prev_pts = frame->pts;
- if(same_pts)
- continue;
- }
+ 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
+ for(int i = 0; i < num_frames; ++i) {
+ if(framerate_mode == FramerateMode::CONSTANT) {
+ frame->pts = video_pts_counter + i;
+ } else {
+ frame->pts = (this_video_frame_time - record_start_time) * (double)AV_TIME_BASE;
+ const bool same_pts = frame->pts == video_prev_pts;
+ video_prev_pts = frame->pts;
+ if(same_pts)
+ continue;
+ }
- int ret = avcodec_send_frame(video_codec_context, frame);
- if(ret == 0) {
- // TODO: Move to separate thread because this could write to network (for example when livestreaming)
- receive_frames(video_codec_context, VIDEO_STREAM_INDEX, video_stream, frame->pts, av_format_context,
- record_start_time, frame_data_queue, replay_buffer_size_secs, frames_erased, write_output_mutex);
- } else {
- fprintf(stderr, "Error: avcodec_send_frame failed, error: %s\n", av_error_to_string(ret));
+ int ret = avcodec_send_frame(video_codec_context, frame);
+ if(ret == 0) {
+ // TODO: Move to separate thread because this could write to network (for example when livestreaming)
+ receive_frames(video_codec_context, VIDEO_STREAM_INDEX, video_stream, frame->pts, av_format_context,
+ record_start_time, frame_data_queue, replay_buffer_size_secs, frames_erased, write_output_mutex);
+ } else {
+ fprintf(stderr, "Error: avcodec_send_frame failed, error: %s\n", av_error_to_string(ret));
+ }
}
+ 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) {