* [FFmpeg-devel] [PATCH] lavc/vaapi_encode: fix segfault @ 2023-01-30 5:23 Xiang, Haihao 2023-01-30 7:55 ` Anton Khirnov 0 siblings, 1 reply; 6+ messages in thread From: Xiang, Haihao @ 2023-01-30 5:23 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Haihao Xiang, Anton Khirnov 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(-) 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; } -- 2.17.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH] lavc/vaapi_encode: fix segfault 2023-01-30 5:23 [FFmpeg-devel] [PATCH] lavc/vaapi_encode: fix segfault Xiang, Haihao @ 2023-01-30 7:55 ` Anton Khirnov 2023-01-30 15:15 ` Xiang, Haihao 0 siblings, 1 reply; 6+ messages in thread From: Anton Khirnov @ 2023-01-30 7:55 UTC (permalink / raw) To: ffmpeg-devel, Xiang, Haihao 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 :/ -- Anton Khirnov _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH] lavc/vaapi_encode: fix segfault 2023-01-30 7:55 ` Anton Khirnov @ 2023-01-30 15:15 ` Xiang, Haihao 2023-01-31 13:14 ` [FFmpeg-devel] [PATCH] lavc/vaapi_encode: fix propagating durations and opaques Anton Khirnov 0 siblings, 1 reply; 6+ messages in thread From: Xiang, Haihao @ 2023-01-30 15:15 UTC (permalink / raw) To: ffmpeg-devel 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 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 6+ messages in thread
* [FFmpeg-devel] [PATCH] lavc/vaapi_encode: fix propagating durations and opaques 2023-01-30 15:15 ` Xiang, Haihao @ 2023-01-31 13:14 ` Anton Khirnov 2023-02-01 2:59 ` Xiang, Haihao 0 siblings, 1 reply; 6+ messages in thread From: Anton Khirnov @ 2023-01-31 13:14 UTC (permalink / raw) To: ffmpeg-devel input_image is freed by the time the output packet is constructed, so we need to store copies in VAAPIEncodePicture. --- Is this better? --- libavcodec/vaapi_encode.c | 22 +++++++++++++++++----- libavcodec/vaapi_encode.h | 4 ++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index 6787b90e8d6..bfca315a7ad 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -695,7 +695,7 @@ static int vaapi_encode_output(AVCodecContext *avctx, pkt->flags |= AV_PKT_FLAG_KEY; pkt->pts = pic->pts; - pkt->duration = pic->input_image->duration; + pkt->duration = pic->duration; vas = vaUnmapBuffer(ctx->hwctx->display, pic->output_buffer); if (vas != VA_STATUS_SUCCESS) { @@ -706,10 +706,11 @@ static int vaapi_encode_output(AVCodecContext *avctx, } // for no-delay encoders this is handled in generic codec - if (avctx->codec->capabilities & AV_CODEC_CAP_DELAY) { - err = ff_encode_reordered_opaque(avctx, pkt, pic->input_image); - if (err < 0) - goto fail; + if (avctx->codec->capabilities & AV_CODEC_CAP_DELAY && + avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) { + pkt->opaque = pic->opaque; + pkt->opaque_ref = pic->opaque_ref; + pic->opaque_ref = NULL; } av_buffer_unref(&pic->output_buffer_ref); @@ -785,6 +786,8 @@ static int vaapi_encode_free(AVCodecContext *avctx, av_frame_free(&pic->input_image); av_frame_free(&pic->recon_image); + av_buffer_unref(&pic->opaque_ref); + av_freep(&pic->param_buffers); av_freep(&pic->slices); // Output buffer should already be destroyed. @@ -1152,6 +1155,15 @@ static int vaapi_encode_send_frame(AVCodecContext *avctx, AVFrame *frame) pic->input_surface = (VASurfaceID)(uintptr_t)frame->data[3]; pic->pts = frame->pts; + pic->duration = frame->duration; + + if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) { + err = av_buffer_replace(&pic->opaque_ref, frame->opaque_ref); + if (err < 0) + goto fail; + + pic->opaque = frame->opaque; + } av_frame_move_ref(pic->input_image, frame); diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h index 359f954ffff..a1e639f56b0 100644 --- a/libavcodec/vaapi_encode.h +++ b/libavcodec/vaapi_encode.h @@ -75,8 +75,12 @@ typedef struct VAAPIEncodePicture { int64_t display_order; int64_t encode_order; int64_t pts; + int64_t duration; int force_idr; + void *opaque; + AVBufferRef *opaque_ref; + #if VA_CHECK_VERSION(1, 0, 0) // ROI regions. VAEncROI *roi; -- 2.35.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH] lavc/vaapi_encode: fix propagating durations and opaques 2023-01-31 13:14 ` [FFmpeg-devel] [PATCH] lavc/vaapi_encode: fix propagating durations and opaques Anton Khirnov @ 2023-02-01 2:59 ` Xiang, Haihao 2023-02-02 2:47 ` Xiang, Haihao 0 siblings, 1 reply; 6+ messages in thread From: Xiang, Haihao @ 2023-02-01 2:59 UTC (permalink / raw) To: ffmpeg-devel On Di, 2023-01-31 at 14:14 +0100, Anton Khirnov wrote: > input_image is freed by the time the output packet is constructed, so we > need to store copies in VAAPIEncodePicture. > --- > Is this better? > --- > libavcodec/vaapi_encode.c | 22 +++++++++++++++++----- > libavcodec/vaapi_encode.h | 4 ++++ > 2 files changed, 21 insertions(+), 5 deletions(-) > > diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c > index 6787b90e8d6..bfca315a7ad 100644 > --- a/libavcodec/vaapi_encode.c > +++ b/libavcodec/vaapi_encode.c > @@ -695,7 +695,7 @@ static int vaapi_encode_output(AVCodecContext *avctx, > pkt->flags |= AV_PKT_FLAG_KEY; > > pkt->pts = pic->pts; > - pkt->duration = pic->input_image->duration; > + pkt->duration = pic->duration; > > vas = vaUnmapBuffer(ctx->hwctx->display, pic->output_buffer); > if (vas != VA_STATUS_SUCCESS) { > @@ -706,10 +706,11 @@ static int vaapi_encode_output(AVCodecContext *avctx, > } > > // for no-delay encoders this is handled in generic codec > - if (avctx->codec->capabilities & AV_CODEC_CAP_DELAY) { > - err = ff_encode_reordered_opaque(avctx, pkt, pic->input_image); > - if (err < 0) > - goto fail; > + if (avctx->codec->capabilities & AV_CODEC_CAP_DELAY && > + avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) { > + pkt->opaque = pic->opaque; > + pkt->opaque_ref = pic->opaque_ref; > + pic->opaque_ref = NULL; > } > > av_buffer_unref(&pic->output_buffer_ref); > @@ -785,6 +786,8 @@ static int vaapi_encode_free(AVCodecContext *avctx, > av_frame_free(&pic->input_image); > av_frame_free(&pic->recon_image); > > + av_buffer_unref(&pic->opaque_ref); > + > av_freep(&pic->param_buffers); > av_freep(&pic->slices); > // Output buffer should already be destroyed. > @@ -1152,6 +1155,15 @@ static int vaapi_encode_send_frame(AVCodecContext > *avctx, AVFrame *frame) > > pic->input_surface = (VASurfaceID)(uintptr_t)frame->data[3]; > pic->pts = frame->pts; > + pic->duration = frame->duration; > + > + if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) { > + err = av_buffer_replace(&pic->opaque_ref, frame->opaque_ref); > + if (err < 0) > + goto fail; > + > + pic->opaque = frame->opaque; > + } > > av_frame_move_ref(pic->input_image, frame); > > diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h > index 359f954ffff..a1e639f56b0 100644 > --- a/libavcodec/vaapi_encode.h > +++ b/libavcodec/vaapi_encode.h > @@ -75,8 +75,12 @@ typedef struct VAAPIEncodePicture { > int64_t display_order; > int64_t encode_order; > int64_t pts; > + int64_t duration; > int force_idr; > > + void *opaque; > + AVBufferRef *opaque_ref; > + > #if VA_CHECK_VERSION(1, 0, 0) > // ROI regions. > VAEncROI *roi; LGTM and the command for transcoding with vaapi works well now. BRs Haihao _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH] lavc/vaapi_encode: fix propagating durations and opaques 2023-02-01 2:59 ` Xiang, Haihao @ 2023-02-02 2:47 ` Xiang, Haihao 0 siblings, 0 replies; 6+ messages in thread From: Xiang, Haihao @ 2023-02-02 2:47 UTC (permalink / raw) To: ffmpeg-devel On Wo, 2023-02-01 at 02:59 +0000, Xiang, Haihao wrote: > On Di, 2023-01-31 at 14:14 +0100, Anton Khirnov wrote: > > input_image is freed by the time the output packet is constructed, so we > > need to store copies in VAAPIEncodePicture. > > --- > > Is this better? > > --- > > libavcodec/vaapi_encode.c | 22 +++++++++++++++++----- > > libavcodec/vaapi_encode.h | 4 ++++ > > 2 files changed, 21 insertions(+), 5 deletions(-) > > > > diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c > > index 6787b90e8d6..bfca315a7ad 100644 > > --- a/libavcodec/vaapi_encode.c > > +++ b/libavcodec/vaapi_encode.c > > @@ -695,7 +695,7 @@ static int vaapi_encode_output(AVCodecContext *avctx, > > pkt->flags |= AV_PKT_FLAG_KEY; > > > > pkt->pts = pic->pts; > > - pkt->duration = pic->input_image->duration; > > + pkt->duration = pic->duration; > > > > vas = vaUnmapBuffer(ctx->hwctx->display, pic->output_buffer); > > if (vas != VA_STATUS_SUCCESS) { > > @@ -706,10 +706,11 @@ static int vaapi_encode_output(AVCodecContext *avctx, > > } > > > > // for no-delay encoders this is handled in generic codec > > - if (avctx->codec->capabilities & AV_CODEC_CAP_DELAY) { > > - err = ff_encode_reordered_opaque(avctx, pkt, pic->input_image); > > - if (err < 0) > > - goto fail; > > + if (avctx->codec->capabilities & AV_CODEC_CAP_DELAY && > > + avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) { > > + pkt->opaque = pic->opaque; > > + pkt->opaque_ref = pic->opaque_ref; > > + pic->opaque_ref = NULL; > > } > > > > av_buffer_unref(&pic->output_buffer_ref); > > @@ -785,6 +786,8 @@ static int vaapi_encode_free(AVCodecContext *avctx, > > av_frame_free(&pic->input_image); > > av_frame_free(&pic->recon_image); > > > > + av_buffer_unref(&pic->opaque_ref); > > + > > av_freep(&pic->param_buffers); > > av_freep(&pic->slices); > > // Output buffer should already be destroyed. > > @@ -1152,6 +1155,15 @@ static int vaapi_encode_send_frame(AVCodecContext > > *avctx, AVFrame *frame) > > > > pic->input_surface = (VASurfaceID)(uintptr_t)frame->data[3]; > > pic->pts = frame->pts; > > + pic->duration = frame->duration; > > + > > + if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) { > > + err = av_buffer_replace(&pic->opaque_ref, frame->opaque_ref); > > + if (err < 0) > > + goto fail; > > + > > + pic->opaque = frame->opaque; > > + } > > > > av_frame_move_ref(pic->input_image, frame); > > > > diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h > > index 359f954ffff..a1e639f56b0 100644 > > --- a/libavcodec/vaapi_encode.h > > +++ b/libavcodec/vaapi_encode.h > > @@ -75,8 +75,12 @@ typedef struct VAAPIEncodePicture { > > int64_t display_order; > > int64_t encode_order; > > int64_t pts; > > + int64_t duration; > > int force_idr; > > > > + void *opaque; > > + AVBufferRef *opaque_ref; > > + > > #if VA_CHECK_VERSION(1, 0, 0) > > // ROI regions. > > VAEncROI *roi; > > LGTM and the command for transcoding with vaapi works well now. > Pushed because this patch fixed critical regression in vaapi path. Thanks Haihao _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-02-02 2:47 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-01-30 5:23 [FFmpeg-devel] [PATCH] lavc/vaapi_encode: fix segfault Xiang, Haihao 2023-01-30 7:55 ` Anton Khirnov 2023-01-30 15:15 ` Xiang, Haihao 2023-01-31 13:14 ` [FFmpeg-devel] [PATCH] lavc/vaapi_encode: fix propagating durations and opaques Anton Khirnov 2023-02-01 2:59 ` Xiang, Haihao 2023-02-02 2:47 ` Xiang, Haihao
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git