Updated patch.

On Wed, Apr 1, 2015 at 3:10 PM, Debargha Mukherjee <debar...@google.com>
wrote:

>
>
> On Tue, Mar 31, 2015 at 4:16 PM, James Zern <jz...@google.com> wrote:
>
>> On Mon, Mar 30, 2015 at 10:26 AM, Debargha Mukherjee
>> <debar...@google.com> wrote:
>> > On Fri, Mar 27, 2015 at 8:07 PM, James Zern <jz...@google.com> wrote:
>> >
>> >> On Fri, Mar 27, 2015 at 6:58 PM, Debargha Mukherjee <
>> debar...@google.com>
>> >> wrote:
>> >> > [...]
>> >>
>> >> > +#if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_IMG_FMT_HIGHBITDEPTH)
>> >> > +static int set_pix_fmt(AVCodecContext *avctx, struct
>> vpx_codec_enc_cfg
>> >> *enccfg,
>> >> > +                       vpx_codec_flags_t *flags, vpx_img_fmt_t
>> >> *img_fmt) {
>> >> > +    if (avctx->codec_id == AV_CODEC_ID_VP8 && avctx->pix_fmt !=
>> >> AV_PIX_FMT_YUV420P) {
>> >> >
>> >>
>> >> couldn't you just check a codec capability? what happens when vp9 is
>> >> configured
>> >> with high bitdepth encoding disabled?
>> >>
>> >
>> > I wanted to insulate against compiling with an older version of libvpx
>> that
>> > did not have the highbitdepth flags defined. This is how we did the
>> > libvpxdec.
>> > I have added a codec caps check also to the code.
>> >
>>
>> OK, but if you're checking for VPX_IMG_FMT_HIGHBITDEPTH then couldn't
>> you just rely on the presence of the codec capability? If the mapping
>> is for vp9 only then cap+vp9 check is all right, you can drop the vp8
>> check as that code can't be reached (maybe add an av_assert).
>>
>
> Removed the vp8 check.
>
>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>
>
>
> --
> Debargha Mukherjee, Ph.D.
> Staff Software Engineer,
> Google, Inc.
> Email: debar...@google.com
> Phone: 408-234-5956 (cell)
>



-- 
Debargha Mukherjee, Ph.D.
Staff Software Engineer,
Google, Inc.
Email: debar...@google.com
Phone: 408-234-5956 (cell)
From fd34da12162a8c0a5e2053bcb50d676cb9e03405 Mon Sep 17 00:00:00 2001
From: Deb Mukherjee <debar...@google.com>
Date: Wed, 25 Mar 2015 17:10:16 -0700
Subject: [PATCH] Support for VP9 high-color/high-bit-depth encoding

Patch to support VP9 encoding with new profiles 1-3.
Profile 1 (8-bit 422/444) should work with default libvpx
configuration.
However you will need to configure libvpx with
--enable-vp9-highbitdepth before building and linking
with ffmpeg for profile 2 (10-/12-bit 420) and profile 3
(10-/12-bit 422/444) encoding.

You may use the appropriate profile option on the
command line:
-profile:v 1 for 422/444 8-bit encoding
-profile:v 2 for 420 10-/12- bit encoding
-profile:v 3 for 422/444 10-/12-bit encoding
If you do not use the -profile:v option, it will be deduced
from the source format.
---
 libavcodec/libvpxenc.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 84 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 176c6b6..5cd098a 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -149,12 +149,19 @@ static av_cold void dump_enc_cfg(AVCodecContext *avctx,
     av_log(avctx, level, "vpx_codec_enc_cfg\n");
     av_log(avctx, level, "generic settings\n"
            "  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n  %*s%u\n"
+#if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_IMG_FMT_HIGHBITDEPTH)
+           "  %*s%u\n  %*s%u\n"
+#endif
            "  %*s{%u/%u}\n  %*s%u\n  %*s%d\n  %*s%u\n",
            width, "g_usage:",           cfg->g_usage,
            width, "g_threads:",         cfg->g_threads,
            width, "g_profile:",         cfg->g_profile,
            width, "g_w:",               cfg->g_w,
            width, "g_h:",               cfg->g_h,
+#if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_IMG_FMT_HIGHBITDEPTH)
+           width, "g_bit_depth:",       cfg->g_bit_depth,
+           width, "g_input_bit_depth:", cfg->g_input_bit_depth,
+#endif
            width, "g_timebase:",        cfg->g_timebase.num, cfg->g_timebase.den,
            width, "g_error_resilient:", cfg->g_error_resilient,
            width, "g_pass:",            cfg->g_pass,
@@ -259,6 +266,56 @@ static av_cold int vp8_free(AVCodecContext *avctx)
     return 0;
 }
 
+#if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_IMG_FMT_HIGHBITDEPTH)
+static int set_pix_fmt(AVCodecContext *avctx, struct vpx_codec_enc_cfg *enccfg,
+                       vpx_codec_flags_t *flags, vpx_img_fmt_t *img_fmt) {
+    switch (avctx->pix_fmt) {
+        case AV_PIX_FMT_YUV420P:
+            enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
+            enccfg->g_profile = 0;
+            *img_fmt = VPX_IMG_FMT_I420;
+            return 0;
+        case AV_PIX_FMT_YUV422P:
+            enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
+            enccfg->g_profile = 1;
+            *img_fmt = VPX_IMG_FMT_I422;
+            return 0;
+        case AV_PIX_FMT_YUV444P:
+            enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
+            enccfg->g_profile = 1;
+            *img_fmt = VPX_IMG_FMT_I444;
+            return 0;
+        case AV_PIX_FMT_YUV420P10LE:
+        case AV_PIX_FMT_YUV420P12LE:
+            enccfg->g_bit_depth = enccfg->g_input_bit_depth =
+                avctx->pix_fmt == AV_PIX_FMT_YUV420P10LE ? 10 : 12;
+            enccfg->g_profile = 2;
+            *img_fmt = VPX_IMG_FMT_I42016;
+            *flags |= VPX_CODEC_USE_HIGHBITDEPTH;
+            return 0;
+        case AV_PIX_FMT_YUV422P10LE:
+        case AV_PIX_FMT_YUV422P12LE:
+            enccfg->g_bit_depth = enccfg->g_input_bit_depth =
+                avctx->pix_fmt == AV_PIX_FMT_YUV422P10LE ? 10 : 12;
+            enccfg->g_profile = 3;
+            *img_fmt = VPX_IMG_FMT_I42216;
+            *flags |= VPX_CODEC_USE_HIGHBITDEPTH;
+            return 0;
+        case AV_PIX_FMT_YUV444P10LE:
+        case AV_PIX_FMT_YUV444P12LE:
+            enccfg->g_bit_depth = enccfg->g_input_bit_depth =
+                avctx->pix_fmt == AV_PIX_FMT_YUV444P10LE ? 10 : 12;
+            enccfg->g_profile = 3;
+            *img_fmt = VPX_IMG_FMT_I44416;
+            *flags |= VPX_CODEC_USE_HIGHBITDEPTH;
+            return 0;
+        default:
+            av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format.\n");
+            return AVERROR_INVALIDDATA;
+  }
+}
+#endif
+
 static av_cold int vpx_init(AVCodecContext *avctx,
                             const struct vpx_codec_iface *iface)
 {
@@ -267,6 +324,8 @@ static av_cold int vpx_init(AVCodecContext *avctx,
     struct vpx_codec_enc_cfg enccfg_alpha;
     vpx_codec_flags_t flags = (avctx->flags & CODEC_FLAG_PSNR) ? VPX_CODEC_USE_PSNR : 0;
     int res;
+    vpx_img_fmt_t img_fmt = VPX_IMG_FMT_I420;
+    vpx_codec_caps_t codec_caps = vpx_codec_get_caps(iface);
 
     av_log(avctx, AV_LOG_INFO, "%s\n", vpx_codec_version_str());
     av_log(avctx, AV_LOG_VERBOSE, "%s\n", vpx_codec_build_config());
@@ -280,6 +339,14 @@ static av_cold int vpx_init(AVCodecContext *avctx,
         return AVERROR(EINVAL);
     }
 
+#if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_IMG_FMT_HIGHBITDEPTH)
+    if (avctx->codec_id == AV_CODEC_ID_VP9 && (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH)) {
+        if (set_pix_fmt(avctx, &enccfg, &flags, &img_fmt))
+            return AVERROR(EINVAL);
+        av_log(avctx, AV_LOG_INFO, "Bit-depth: %d\n", enccfg.g_bit_depth);
+    }
+#endif
+
     if(!avctx->bit_rate)
         if(avctx->rc_max_rate || avctx->rc_buffer_size || avctx->rc_initial_buffer_occupancy) {
             av_log( avctx, AV_LOG_ERROR, "Rate control parameters set without a bitrate\n");
@@ -483,8 +550,12 @@ static av_cold int vpx_init(AVCodecContext *avctx,
     av_log(avctx, AV_LOG_DEBUG, "Using deadline: %d\n", ctx->deadline);
 
     //provide dummy value to initialize wrapper, values will be updated each _encode()
-    vpx_img_wrap(&ctx->rawimg, VPX_IMG_FMT_I420, avctx->width, avctx->height, 1,
+    vpx_img_wrap(&ctx->rawimg, img_fmt, avctx->width, avctx->height, 1,
                  (unsigned char*)1);
+#if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_IMG_FMT_HIGHBITDEPTH)
+    if (avctx->codec_id == AV_CODEC_ID_VP9 && (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH))
+        ctx->rawimg.bit_depth = enccfg.g_bit_depth;
+#endif
 
     if (ctx->is_alpha)
         vpx_img_wrap(&ctx->rawimg_alpha, VPX_IMG_FMT_I420, avctx->width, avctx->height, 1,
@@ -915,7 +986,18 @@ AVCodec ff_libvpx_vp9_encoder = {
     .encode2        = vp8_encode,
     .close          = vp8_free,
     .capabilities   = CODEC_CAP_DELAY | CODEC_CAP_AUTO_THREADS,
-    .pix_fmts       = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
+    .pix_fmts       = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P,
+                                                    AV_PIX_FMT_YUV422P,
+                                                    AV_PIX_FMT_YUV444P,
+#ifdef VPX_IMG_FMT_HIGHBITDEPTH
+                                                    AV_PIX_FMT_YUV420P10LE,
+                                                    AV_PIX_FMT_YUV422P10LE,
+                                                    AV_PIX_FMT_YUV444P10LE,
+                                                    AV_PIX_FMT_YUV420P12LE,
+                                                    AV_PIX_FMT_YUV422P12LE,
+                                                    AV_PIX_FMT_YUV444P12LE,
+#endif
+                                                    AV_PIX_FMT_NONE },
     .priv_class     = &class_vp9,
     .defaults       = defaults,
     .init_static_data = ff_vp9_init_static,
-- 
2.2.0.rc0.207.ga3a616c

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to