From bef2ea5b9ea6207f5f360c884fc28fae2e95f151 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 22 Jan 2026 20:54:00 -0500 Subject: [PATCH] Allocate the temp frame inside Assign, instead of keeping it around. --- src/zm_image.cpp | 16 ++++++++-------- src/zm_image.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/zm_image.cpp b/src/zm_image.cpp index c57037662..0e882e23e 100644 --- a/src/zm_image.cpp +++ b/src/zm_image.cpp @@ -348,11 +348,6 @@ bool Image::Assign(const AVFrame *frame) { // Desired format AVPixelFormat format = (AVPixelFormat)AVPixFormat(); - av_frame_ptr dest_frame{av_frame_alloc()}; - if (!dest_frame) { - Error("Unable to allocate destination frame"); - return false; - } sws_convert_context = sws_getCachedContext( sws_convert_context, frame->width, frame->height, (AVPixelFormat)frame->format, @@ -364,13 +359,18 @@ bool Image::Assign(const AVFrame *frame) { Error("Unable to create conversion context"); return false; } - bool result = Assign(frame, sws_convert_context, dest_frame.get()); + bool result = Assign(frame, sws_convert_context); update_function_pointers(); return result; } // end Image::Assign(const AVFrame *frame) -bool Image::Assign(const AVFrame *frame, SwsContext *convert_context, AVFrame *temp_frame) { - PopulateFrame(temp_frame); +bool Image::Assign(const AVFrame *frame, SwsContext *convert_context) { + av_frame_ptr temp_frame{av_frame_alloc()}; + if (!temp_frame) { + Error("Unable to allocate destination frame"); + return false; + } + PopulateFrame(temp_frame.get()); zm_dump_video_frame(frame, "source frame before convert"); temp_frame->pts = frame->pts; diff --git a/src/zm_image.h b/src/zm_image.h index 5019e5d87..547019bdb 100644 --- a/src/zm_image.h +++ b/src/zm_image.h @@ -206,7 +206,7 @@ class Image { const size_t buffer_size); void Assign(const Image &image); bool Assign(const AVFrame *frame); - bool Assign(const AVFrame *frame, SwsContext *convert_context, AVFrame *temp_frame); + bool Assign(const AVFrame *frame, SwsContext *convert_context); void AssignDirect( const unsigned int p_width, const unsigned int p_height,