[FFmpeg-devel] [PATCH] avcodec/nvdec: support resizing while decoding

Hendrik Leppkes h.leppkes at gmail.com
Fri Sep 20 08:18:28 EEST 2024


On Fri, Sep 20, 2024 at 1:24 AM Carlos Ruiz <carlos.r.domin at gmail.com> wrote:
>
> Hi!
>
> This is my first contribution to the project so please excuse any bad
> etiquette, I tried to read all the FAQs before posting. Would love to start
> by thanking everyone for such an amazing framework you've built!
>
> Anyway, here's my proposed patch to support video resizing when using NVDEC
> hwaccel to decode hevc video (I could look into a similar patch for h264,
> av1, etc if this looks useful). There's a bit more context/explanation in
> the commit description in the patch, but please let me know if the use case
> isn't clear.
>

We don't really leverage these extra functions of NVDEC because it
breaks many assumptions about hwaccels, which are meant to be exact
decoders.
If anything, just fudging the width/height is certainly an API
violation and will likely not be possible as it breaks many
assumptions in the code otherwise, see below.

> ---
>  libavcodec/hevc/hevcdec.c |  8 ++++++--
>  libavcodec/nvdec.c        | 21 +++++++++++++++++----
>  2 files changed, 23 insertions(+), 6 deletions(-)
>
> diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
> index d915d74d22..d63fc5875f 100644
> --- a/libavcodec/hevc/hevcdec.c
> +++ b/libavcodec/hevc/hevcdec.c
> @@ -351,8 +351,12 @@ static void export_stream_params(HEVCContext *s, const
> HEVCSPS *sps)
>      avctx->pix_fmt             = sps->pix_fmt;
>      avctx->coded_width         = sps->width;
>      avctx->coded_height        = sps->height;
> -    avctx->width               = sps->width  - ow->left_offset -
> ow->right_offset;
> -    avctx->height              = sps->height - ow->top_offset  -
> ow->bottom_offset;
> +    if (avctx->width <= 0 || avctx->height <= 0) {
> +        avctx->width           = sps->width;
> +        avctx->height          = sps->height;
> +    }
> +    avctx->width               = avctx->width - ow->left_offset - ow->right_offset;
> +    avctx->height              = avctx->height - ow->top_offset  - ow->bottom_offset;

You cannot do that here. The frame size can change mid-stream, and
this would suppress any such change.
Additionally, if this code runs more then once, then the offset is
applied repeatedly without actually resetting width/height.

- Hendrik


More information about the ffmpeg-devel mailing list