From 332f916bf3326ec09af3261c8b368ee4b73e383d Mon Sep 17 00:00:00 2001 From: David Rosca Date: Wed, 9 Aug 2023 11:35:09 +0200 Subject: [PATCH 1/2] Revert "Only flush when video codec has delay (#209)" This reverts commit ffcb6f94f941fd820885d98c295ed303b83b0eb1. --- src/frame-writer.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/frame-writer.cpp b/src/frame-writer.cpp index 0c0b0e6..b13e4e3 100644 --- a/src/frame-writer.cpp +++ b/src/frame-writer.cpp @@ -920,16 +920,13 @@ FrameWriter::~FrameWriter() // Writing the delayed frames: AVPacket *pkt = av_packet_alloc(); - if (videoCodecCtx->delay) - { - encode(videoCodecCtx, NULL, pkt); + encode(videoCodecCtx, NULL, pkt); #ifdef HAVE_PULSE - if (params.enable_audio) - { - encode(audioCodecCtx, NULL, pkt); - } -#endif + if (params.enable_audio) + { + encode(audioCodecCtx, NULL, pkt); } +#endif // Writing the end of the file. av_write_trailer(fmtCtx); From c73585569a99f8e63aeb9d56938c02b1d1a8f22f Mon Sep 17 00:00:00 2001 From: David Rosca Date: Wed, 9 Aug 2023 11:35:27 +0200 Subject: [PATCH 2/2] Break early when exit_main_loop is set in encoder thread Prevent sending old buffer to encoder. This is actually the correct fix for the issue described in previous (reverted) commit. --- src/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index c8abf81..546fae6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -496,6 +496,10 @@ static void write_loop(FrameWriterParams params) while(buffers.encode().ready_encode() != true && !exit_main_loop) { std::this_thread::sleep_for(std::chrono::microseconds(1000)); } + if (exit_main_loop) { + break; + } + auto& buffer = buffers.encode(); frame_writer_pending_mutex.lock();