diff mbox series

[FFmpeg-devel] lavc/vaapi_encode: fix segfault

Message ID 20230130052321.27566-1-haihao.xiang@intel.com
State New
Headers show
Series [FFmpeg-devel] lavc/vaapi_encode: fix segfault | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Xiang, Haihao Jan. 30, 2023, 5:23 a.m. UTC
From: Haihao Xiang <haihao.xiang@intel.com>

This is a regression since commit fbdba9a1a69fe4df413d9e9df1b11db522946e75

input_image is freed in vaapi_encode_wait() however it is still used in
commit fbdba9a1a69fe4df413d9e9df1b11db522946e75

$ ffmpeg -vaapi_device /dev/dri/renderD128 -f lavfi -i testsrc -vf
"format=nv12,hwupload" -c:v h264_vaapi -f null -

Note input_image will be freed in vaapi_encode_free() now.

Cc: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
 libavcodec/vaapi_encode.c | 3 ---
 1 file changed, 3 deletions(-)

Comments

Anton Khirnov Jan. 30, 2023, 7:55 a.m. UTC | #1
Quoting Xiang, Haihao (2023-01-30 06:23:21)
> From: Haihao Xiang <haihao.xiang@intel.com>
> 
> This is a regression since commit fbdba9a1a69fe4df413d9e9df1b11db522946e75
> 
> input_image is freed in vaapi_encode_wait() however it is still used in
> commit fbdba9a1a69fe4df413d9e9df1b11db522946e75
> 
> $ ffmpeg -vaapi_device /dev/dri/renderD128 -f lavfi -i testsrc -vf
> "format=nv12,hwupload" -c:v h264_vaapi -f null -
> 
> Note input_image will be freed in vaapi_encode_free() now.
> 
> Cc: Anton Khirnov <anton@khirnov.net>
> Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
> ---
>  libavcodec/vaapi_encode.c | 3 ---
>  1 file changed, 3 deletions(-)

Thank you, looks good.

Could swear I tested this, but apparently not :/
Xiang, Haihao Jan. 30, 2023, 3:15 p.m. UTC | #2
On Ma, 2023-01-30 at 08:55 +0100, Anton Khirnov wrote:
> Quoting Xiang, Haihao (2023-01-30 06:23:21)
> > From: Haihao Xiang <haihao.xiang@intel.com>
> > 
> > This is a regression since commit fbdba9a1a69fe4df413d9e9df1b11db522946e75
> > 
> > input_image is freed in vaapi_encode_wait() however it is still used in
> > commit fbdba9a1a69fe4df413d9e9df1b11db522946e75
> > 
> > $ ffmpeg -vaapi_device /dev/dri/renderD128 -f lavfi -i testsrc -vf
> > "format=nv12,hwupload" -c:v h264_vaapi -f null -
> > 
> > Note input_image will be freed in vaapi_encode_free() now.
> > 
> > Cc: Anton Khirnov <anton@khirnov.net>
> > Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
> > ---
> >  libavcodec/vaapi_encode.c | 3 ---
> >  1 file changed, 3 deletions(-)
> 
> Thank you, looks good.
> 
> Could swear I tested this, but apparently not :/

There is another issue caused by commit fbdba91, some commands for transcode
doesn't work now.

E.g.

$ ffmpeg -y -init_hw_device vaapi=hw:/dev/dri/renderD128 -hwaccel_output_format
vaapi -hwaccel vaapi -i input.mpg -c:v h264_vaapi out.h264

...
[mpeg2video @ 0x55991e9c5540] get_buffer() failed
[mpeg2video @ 0x55991e9c5540] get_buffer() failed (-12 (nil))
Error while decoding stream #0:0: Operation not permitted
...

User will has to use -extra_hw_frames option to require more hardware frames.

E.g.

$ ffmpeg -y -init_hw_device vaapi=hw:/dev/dri/renderD128 -hwaccel_output_format
vaapi -hwaccel vaapi -extra_hw_frames 8 -i input.mpg -c:v h264_vaapi out.h264

Is this also taken as an regression ? 

Thanks
Haihao
diff mbox series

Patch

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 6787b90e8d..b644814b6c 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -173,9 +173,6 @@  static int vaapi_encode_wait(AVCodecContext *avctx,
         }
     }
 
-    // Input is definitely finished with now.
-    av_frame_free(&pic->input_image);
-
     pic->encode_complete = 1;
     return 0;
 }