diff mbox series

[FFmpeg-devel] avcodec/libvpxenc: Apply codec options to alpha codec context

Message ID 20210902100656.991238-1-chelminski.adam@gmail.com
State New
Headers show
Series [FFmpeg-devel] avcodec/libvpxenc: Apply codec options to alpha codec context | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Adam Chelminski Sept. 2, 2021, 10:06 a.m. UTC
When encoding yuva420 (alpha) frames, the vpx encoder uses a second
vpx_codec_ctx to encode the alpha stream. However, codec options were
only being applied to the primary encoder. This patch updates
codecctl_int and codecctl_intp to also apply codec options to the alpha
codec context when encoding frames with alpha.

This is necessary to take advantage of libvpx speed optimization options
such as 'row-mt', 'cpu-used', and 'deadline' when encoding videos with
alpha. Without this patch, the speed optimizations are only applied to
the primary stream encoding, and the overall encoding is just as slow as
it would be without the options specified.

Signed-off-by: Adam Chelminski <chelminski.adam@gmail.com>
---
 libavcodec/libvpxenc.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

Comments

James Zern Sept. 2, 2021, 5:12 p.m. UTC | #1
Hi,

On Thu, Sep 2, 2021 at 3:08 AM Adam Chelminski
<chelminski.adam@gmail.com> wrote:
>
> When encoding yuva420 (alpha) frames, the vpx encoder uses a second
> vpx_codec_ctx to encode the alpha stream. However, codec options were
> only being applied to the primary encoder. This patch updates
> codecctl_int and codecctl_intp to also apply codec options to the alpha
> codec context when encoding frames with alpha.
>
> This is necessary to take advantage of libvpx speed optimization options
> such as 'row-mt', 'cpu-used', and 'deadline' when encoding videos with

deadline is passed to the encode call in libvpx, but the others are correct.

> alpha. Without this patch, the speed optimizations are only applied to
> the primary stream encoding, and the overall encoding is just as slow as
> it would be without the options specified.
>
> Signed-off-by: Adam Chelminski <chelminski.adam@gmail.com>
> ---
>  libavcodec/libvpxenc.c | 26 ++++++++++++++++++++++++--
>  1 file changed, 24 insertions(+), 2 deletions(-)
>

Thanks for the patch. This should bump the micro version in
libavcodec/version.h for the behavior change.

> diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> index 0e50fbfd7c..1df0a8343c 100644
> --- a/libavcodec/libvpxenc.c
> +++ b/libavcodec/libvpxenc.c
> @@ -385,9 +385,20 @@ static av_cold int codecctl_int(AVCodecContext *avctx,
>          snprintf(buf, sizeof(buf), "Failed to set %s codec control",
>                   ctlidstr[id]);
>          log_encoder_error(avctx, buf);
> +        return AVERROR(EINVAL);
>      }
>
> -    return res == VPX_CODEC_OK ? 0 : AVERROR(EINVAL);
> +    if (ctx->is_alpha) {
> +        int res_alpha = vpx_codec_control(&ctx->encoder_alpha, id, val);
> +        if (res_alpha != VPX_CODEC_OK) {
> +            snprintf(buf, sizeof(buf), "Failed to set %s alpha codec control",
> +                    ctlidstr[id]);

indent is off.

> +            log_encoder_error(avctx, buf);
> +            return AVERROR(EINVAL);
> +        }
> +    }
> +
> +    return 0;
>  }
>
>  #if VPX_ENCODER_ABI_VERSION >= 12
> @@ -407,9 +418,20 @@ static av_cold int codecctl_intp(AVCodecContext *avctx,
>          snprintf(buf, sizeof(buf), "Failed to set %s codec control",
>                   ctlidstr[id]);
>          log_encoder_error(avctx, buf);
> +        return AVERROR(EINVAL);
>      }
>
> -    return res == VPX_CODEC_OK ? 0 : AVERROR(EINVAL);
> +    if (ctx->is_alpha) {
> +        int res_alpha = vpx_codec_control(&ctx->encoder_alpha, id, val);
> +        if (res_alpha != VPX_CODEC_OK) {
> +            snprintf(buf, sizeof(buf), "Failed to set %s alpha codec control",
> +                    ctlidstr[id]);

here too.

> +            log_encoder_error(avctx, buf);
> +            return AVERROR(EINVAL);
> +        }
> +    }
> +
> +    return 0;
>  }
>  #endif
>
> --
> 2.25.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".
diff mbox series

Patch

diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 0e50fbfd7c..1df0a8343c 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -385,9 +385,20 @@  static av_cold int codecctl_int(AVCodecContext *avctx,
         snprintf(buf, sizeof(buf), "Failed to set %s codec control",
                  ctlidstr[id]);
         log_encoder_error(avctx, buf);
+        return AVERROR(EINVAL);
     }
 
-    return res == VPX_CODEC_OK ? 0 : AVERROR(EINVAL);
+    if (ctx->is_alpha) {
+        int res_alpha = vpx_codec_control(&ctx->encoder_alpha, id, val);
+        if (res_alpha != VPX_CODEC_OK) {
+            snprintf(buf, sizeof(buf), "Failed to set %s alpha codec control",
+                    ctlidstr[id]);
+            log_encoder_error(avctx, buf);
+            return AVERROR(EINVAL);
+        }
+    }
+
+    return 0;
 }
 
 #if VPX_ENCODER_ABI_VERSION >= 12
@@ -407,9 +418,20 @@  static av_cold int codecctl_intp(AVCodecContext *avctx,
         snprintf(buf, sizeof(buf), "Failed to set %s codec control",
                  ctlidstr[id]);
         log_encoder_error(avctx, buf);
+        return AVERROR(EINVAL);
     }
 
-    return res == VPX_CODEC_OK ? 0 : AVERROR(EINVAL);
+    if (ctx->is_alpha) {
+        int res_alpha = vpx_codec_control(&ctx->encoder_alpha, id, val);
+        if (res_alpha != VPX_CODEC_OK) {
+            snprintf(buf, sizeof(buf), "Failed to set %s alpha codec control",
+                    ctlidstr[id]);
+            log_encoder_error(avctx, buf);
+            return AVERROR(EINVAL);
+        }
+    }
+
+    return 0;
 }
 #endif