@@ -500,7 +500,7 @@ int hw_device_setup_for_encode(OutputStream *ost)
static int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input)
{
InputStream *ist = avctx->opaque;
- AVFrame *output = NULL;
+ AVFrame *output = ist->filter_frame;
enum AVPixelFormat output_format = ist->hwaccel_output_format;
int err;
@@ -509,10 +509,6 @@ static int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input)
return 0;
}
- output = av_frame_alloc();
- if (!output)
- return AVERROR(ENOMEM);
-
output->format = output_format;
err = av_hwframe_transfer_data(output, input, 0);
@@ -524,18 +520,16 @@ static int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input)
err = av_frame_copy_props(output, input);
if (err < 0) {
- av_frame_unref(output);
goto fail;
}
av_frame_unref(input);
av_frame_move_ref(input, output);
- av_frame_free(&output);
return 0;
fail:
- av_frame_free(&output);
+ av_frame_unref(output);
return err;
}
This avoids an AVFrame allocation per decoded frame. Signed-off-by: James Almer <jamrial@gmail.com> --- ist->filter_frame is safe to use here since send_frame_to_filters() also unrefs it immediately after using it. But if this is deemed ugly/evil, I'll just add a new AVFrame to InputStream. fftools/ffmpeg_hw.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)