[FFmpeg-devel] [PATCH 3/4] avcodec/nvenc: Handle non-square pixel aspect ratios

Nicolas George george at nsup.org
Thu Dec 25 15:17:42 CET 2014


Le quintidi 5 nivôse, an CCXXIII, timo at rothenpieler.org a écrit :
> From: Timo Rothenpieler <timo at rothenpieler.org>
> 
> ---
>  libavcodec/nvenc.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
> index 6a37ea6..ebc3249 100644
> --- a/libavcodec/nvenc.c
> +++ b/libavcodec/nvenc.c
> @@ -471,6 +471,7 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
>      int i, num_mbs;
>      int isLL = 0;
>      int res = 0;
> +    int dw, dh;
>  
>      NvencContext *ctx = avctx->priv_data;
>      NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs;
> @@ -564,8 +565,16 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
>      ctx->init_encode_params.encodeGUID = NV_ENC_CODEC_H264_GUID;
>      ctx->init_encode_params.encodeHeight = avctx->height;
>      ctx->init_encode_params.encodeWidth = avctx->width;
> -    ctx->init_encode_params.darHeight = avctx->height;
> -    ctx->init_encode_params.darWidth = avctx->width;
> +

> +    if (avctx->sample_aspect_ratio.num && avctx->sample_aspect_ratio.den) {
> +        av_reduce(&dw, &dh, avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den, 4096);
> +        ctx->init_encode_params.darHeight = dw;
> +        ctx->init_encode_params.darWidth = dh;
> +    } else {
> +        ctx->init_encode_params.darHeight = avctx->height;
> +        ctx->init_encode_params.darWidth = avctx->width;

This looks very strange. Was this tested? In the first case, you set
darWidth and darHeight to FFmpeg's SAMPLE aspect ratio, and in the second
case, you set it to the image aspect ratio.

Based on the name of the fields, I would guess the second is correct but the
first is wrong.

> +    }
> +
>      ctx->init_encode_params.frameRateNum = avctx->time_base.den;
>      ctx->init_encode_params.frameRateDen = avctx->time_base.num * avctx->ticks_per_frame;

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20141225/540c6981/attachment.asc>


More information about the ffmpeg-devel mailing list