From 7726240ab07ad9b96666d785190d936563809c11 Mon Sep 17 00:00:00 2001 From: progandy Date: Sat, 9 May 2020 11:09:49 +0200 Subject: [PATCH] Quit wf-recorder when the recording target fails This can happen when the sdl muxer is used and the window is closed or when the target file reaches the filesystem limits. ./wf-recorder -c rawvideo -m sdl -f pipe:mirror --- src/frame-writer.cpp | 4 +++- src/frame-writer.hpp | 4 ++++ src/main.cpp | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/frame-writer.cpp b/src/frame-writer.cpp index 26f12cb..01f825e 100644 --- a/src/frame-writer.cpp +++ b/src/frame-writer.cpp @@ -601,7 +601,9 @@ void FrameWriter::finish_frame(AVCodecContext *enc_ctx, AVPacket& pkt) pending_mutex.unlock(); } - av_interleaved_write_frame(fmtCtx, &pkt); + if (av_interleaved_write_frame(fmtCtx, &pkt) != 0) { + params.write_aborted_flag = true; + } av_packet_unref(&pkt); if (params.enable_audio) diff --git a/src/frame-writer.hpp b/src/frame-writer.hpp index 4b74594..d2430ce 100644 --- a/src/frame-writer.hpp +++ b/src/frame-writer.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "config.h" #define AUDIO_RATE 44100 @@ -64,6 +65,9 @@ struct FrameWriterParams bool force_yuv; int opencl_device; int bframes; + + std::atomic& write_aborted_flag; + FrameWriterParams(std::atomic& flag): write_aborted_flag(flag) {} }; class FrameWriter diff --git a/src/main.cpp b/src/main.cpp index 47af572..277679e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -584,7 +584,7 @@ With no FILE, start recording the current screen. int main(int argc, char *argv[]) { - FrameWriterParams params; + FrameWriterParams params = FrameWriterParams(exit_main_loop); params.file = "recording.mp4"; params.codec = DEFAULT_CODEC; params.enable_ffmpeg_debug_output = false;