libx265: Support tiny video sizes

Message ID 20180316153425.21353-1-vittorio.giovara@gmail.com
State Committed
Commit cc06f7bd10c236539b4f6f87b795c459dd873770
Headers show
Series
  • libx265: Support tiny video sizes
Related show

Commit Message

Vittorio Giovara March 16, 2018, 3:34 p.m.
Where tiny is less than the default CTU size.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
---
 libavcodec/libx265.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Luca Barbato March 16, 2018, 3:46 p.m. | #1
On 16/03/2018 16:34, Vittorio Giovara wrote:
> Where tiny is less than the default CTU size.
> 
> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
> ---
>   libavcodec/libx265.c | 11 +++++++++++
>   1 file changed, 11 insertions(+)
> 
> diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
> index fd5452193b..8f1d60b4e5 100644
> --- a/libavcodec/libx265.c
> +++ b/libavcodec/libx265.c
> @@ -122,6 +122,17 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx)
>       ctx->params->sourceHeight    = avctx->height;
>       ctx->params->bEnablePsnr     = !!(avctx->flags & AV_CODEC_FLAG_PSNR);
>   
> +    /* Tune the CTU size based on input resolution. */
> +    if (ctx->params->sourceWidth < 64 || ctx->params->sourceHeight < 64)
> +        ctx->params->maxCUSize = 32;
> +    if (ctx->params->sourceWidth < 32 || ctx->params->sourceHeight < 32)
> +        ctx->params->maxCUSize = 16;
> +    if (ctx->params->sourceWidth < 16 || ctx->params->sourceHeight < 16) {
> +        av_log(avctx, AV_LOG_ERROR, "Image size is too small (%dx%d).\n",
> +               ctx->params->sourceWidth, ctx->params->sourceHeight);
> +        return AVERROR(EINVAL);
> +    }
> +
>       if ((avctx->color_primaries <= AVCOL_PRI_BT2020 &&
>            avctx->color_primaries != AVCOL_PRI_UNSPECIFIED) ||
>           (avctx->color_trc <= AVCOL_TRC_BT2020_12 &&
> 

Ok.

Patch

diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index fd5452193b..8f1d60b4e5 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -122,6 +122,17 @@  static av_cold int libx265_encode_init(AVCodecContext *avctx)
     ctx->params->sourceHeight    = avctx->height;
     ctx->params->bEnablePsnr     = !!(avctx->flags & AV_CODEC_FLAG_PSNR);
 
+    /* Tune the CTU size based on input resolution. */
+    if (ctx->params->sourceWidth < 64 || ctx->params->sourceHeight < 64)
+        ctx->params->maxCUSize = 32;
+    if (ctx->params->sourceWidth < 32 || ctx->params->sourceHeight < 32)
+        ctx->params->maxCUSize = 16;
+    if (ctx->params->sourceWidth < 16 || ctx->params->sourceHeight < 16) {
+        av_log(avctx, AV_LOG_ERROR, "Image size is too small (%dx%d).\n",
+               ctx->params->sourceWidth, ctx->params->sourceHeight);
+        return AVERROR(EINVAL);
+    }
+
     if ((avctx->color_primaries <= AVCOL_PRI_BT2020 &&
          avctx->color_primaries != AVCOL_PRI_UNSPECIFIED) ||
         (avctx->color_trc <= AVCOL_TRC_BT2020_12 &&