From 86a253859e2eac62f41a2821804efa90ae8215c8 Mon Sep 17 00:00:00 2001 From: Kishi <41839133+Kishi85@users.noreply.github.com> Date: Sun, 28 Jun 2026 22:11:35 +0200 Subject: [PATCH] fix(video): avoid nullptr deref segfault on encode session teardown (#5257) --- src/video.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/video.cpp b/src/video.cpp index 08f9c99c8..5e100859e 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -418,8 +418,8 @@ namespace video { avcodec_encode_session_t(avcodec_encode_session_t &&other) noexcept = default; ~avcodec_encode_session_t() { - // Flush any remaining frames in the encoder - if (avcodec_send_frame(avcodec_ctx.get(), nullptr) == 0) { + // Flush any remaining frames in the encoder if the encoder started up (frame num > 0) + if (avcodec_ctx->frame_num > 0 && avcodec_send_frame(avcodec_ctx.get(), nullptr) == 0) { packet_raw_avcodec pkt; while (avcodec_receive_packet(avcodec_ctx.get(), pkt.av_packet) == 0); }