From 5519d146ac8cf93af372fcdbf80b74fdf9bfee7e Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 26 Mar 2025 13:10:17 -0400 Subject: [PATCH] Fix out_frame encoding --- src/zm_videostore.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/zm_videostore.cpp b/src/zm_videostore.cpp index 45e89f525..f3f23e35d 100644 --- a/src/zm_videostore.cpp +++ b/src/zm_videostore.cpp @@ -1100,6 +1100,8 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr zm_packet) if (monitor->GetOptVideoWriter() == Monitor::ENCODE) { Debug(3, "Have encoding video frame count (%d)", frame_count); + AVFrame *frame = nullptr; + if (!zm_packet->out_frame) { Debug(3, "Have no out frame. codec is %s sw_pf %d %s hw_pf %d %s %dx%d", chosen_codec_data->codec_name, @@ -1107,11 +1109,6 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr zm_packet) chosen_codec_data->hw_pix_fmt, av_get_pix_fmt_name(chosen_codec_data->hw_pix_fmt), video_out_ctx->width, video_out_ctx->height ); - AVFrame *out_frame = zm_packet->get_out_frame(video_out_ctx->width, video_out_ctx->height, chosen_codec_data->sw_pix_fmt); - if (!out_frame) { - Error("Unable to allocate a frame"); - return 0; - } if (zm_packet->image) { Debug(2, "Have an image, convert it"); @@ -1146,17 +1143,19 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr zm_packet) and static_cast(zm_packet->in_frame->format) == chosen_codec_data->sw_pix_fmt ) { - zm_packet->out_frame = std::move(zm_packet->in_frame); - zm_packet->in_frame = nullptr; + frame = zm_packet->in_frame.get(); } else { + frame = zm_packet->get_out_frame(video_out_ctx->width, video_out_ctx->height, chosen_codec_data->sw_pix_fmt); + if (!out_frame) { + Error("Unable to allocate a frame"); + return 0; + } // Have in_frame.... may need to convert it to out_frame swscale.Convert(zm_packet->in_frame.get(), zm_packet->out_frame.get()); } } // end if no in_frame } // end if no out_frame - AVFrame *frame = zm_packet->out_frame.get(); - #if HAVE_LIBAVUTIL_HWCONTEXT_H if (video_out_ctx->hw_frames_ctx) { int ret;