On Thu, Apr 2, 2015 at 3:10 PM, James Zern <[email protected]> wrote:
> On Thu, Apr 2, 2015 at 12:19 PM, Debargha Mukherjee <[email protected]>
> wrote:
> > [...]
> >
> > Updated patch to handle the checks better.
> >
>
> > +#if CONFIG_LIBVPX_VP9_ENCODER
> > +static int set_pix_fmt(AVCodecContext *avctx, vpx_codec_caps_t
> codec_caps,
> > + 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:
> >
>
> Indent is inconsistent with the other switch in this file: align 'case'
> with
> 'switch'.
>
done
>
> > +#ifdef VPX_IMG_FMT_HIGHBITDEPTH
> > + enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
> > +#endif
> > + enccfg->g_profile = 0;
> > + *img_fmt = VPX_IMG_FMT_I420;
> > + return 0;
> > + case AV_PIX_FMT_YUV422P:
> > +#ifdef VPX_IMG_FMT_HIGHBITDEPTH
> > + enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
> > +#endif
> > + enccfg->g_profile = 1;
> > + *img_fmt = VPX_IMG_FMT_I422;
> > + return 0;
> > + case AV_PIX_FMT_YUV444P:
> > +#ifdef VPX_IMG_FMT_HIGHBITDEPTH
> > + enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
> > +#endif
> > + enccfg->g_profile = 1;
> > + *img_fmt = VPX_IMG_FMT_I444;
> > + return 0;
> >
>
> You can probably merge profile 1 like 2/3 to cut down on the duplication.
> You
> might want to set bitdepth to 8 by default reducing the ifdefs here too.
>
done.
>
> > +#if CONFIG_LIBVPX_VP9_ENCODER
> > + if (avctx->codec_id == AV_CODEC_ID_VP9) {
> > + if (set_pix_fmt(avctx, codec_caps, &enccfg, &flags, &img_fmt))
> > + return AVERROR(EINVAL);
> > + av_log(avctx, AV_LOG_INFO, "Bit-depth: %d\n",
> enccfg.g_bit_depth);
> >
>
> Won't build with a non-high-bitdepth build.
>
done.
>
> > - .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
>
done using ff_vp9_init_static().
>
> Now a non-high-bitdepth build will fail the encode if given a high-bitdepth
> file. Previously this would silently downsample.
> _______________________________________________
> ffmpeg-devel mailing list
> [email protected]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
--
Debargha Mukherjee, Ph.D.
Staff Software Engineer,
Google, Inc.
Email: [email protected]
Phone: 408-234-5956 (cell)
From 9f2d6c0303dba76cb9e744eb49b25f9e9e002899 Mon Sep 17 00:00:00 2001
From: Deb Mukherjee <[email protected]>
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/libvpx.c | 37 ++++++++++++++++++++-
libavcodec/libvpxenc.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 123 insertions(+), 3 deletions(-)
diff --git a/libavcodec/libvpx.c b/libavcodec/libvpx.c
index 5d29893..5111eed 100644
--- a/libavcodec/libvpx.c
+++ b/libavcodec/libvpx.c
@@ -19,12 +19,47 @@
*/
#include <vpx/vpx_codec.h>
-
+#include <vpx/vpx_encoder.h>
+#include <vpx/vp8cx.h>
#include "libvpx.h"
+static const enum AVPixelFormat vp9_pix_fmts_def[] = {
+ AV_PIX_FMT_YUV420P,
+ AV_PIX_FMT_NONE
+};
+
+static const enum AVPixelFormat vp9_pix_fmts_highcol[] = {
+ AV_PIX_FMT_YUV420P,
+ AV_PIX_FMT_YUV422P,
+ AV_PIX_FMT_YUV444P,
+ AV_PIX_FMT_NONE
+};
+
+static const enum AVPixelFormat vp9_pix_fmts_highbd[] = {
+ AV_PIX_FMT_YUV420P,
+ AV_PIX_FMT_YUV422P,
+ AV_PIX_FMT_YUV444P,
+ AV_PIX_FMT_YUV420P10LE,
+ AV_PIX_FMT_YUV422P10LE,
+ AV_PIX_FMT_YUV444P10LE,
+ AV_PIX_FMT_YUV420P12LE,
+ AV_PIX_FMT_YUV422P12LE,
+ AV_PIX_FMT_YUV444P12LE,
+ AV_PIX_FMT_NONE
+};
+
av_cold void ff_vp9_init_static(AVCodec *codec)
{
if ( vpx_codec_version_major() < 1
|| (vpx_codec_version_major() == 1 && vpx_codec_version_minor() < 3))
codec->capabilities |= CODEC_CAP_EXPERIMENTAL;
+ if ( vpx_codec_version_major() == 1 && vpx_codec_version_minor() >= 3) {
+ vpx_codec_caps_t codec_caps = vpx_codec_get_caps(vpx_codec_vp9_cx());
+ if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH)
+ codec->pix_fmts = vp9_pix_fmts_highbd;
+ else
+ codec->pix_fmts = vp9_pix_fmts_highcol;
+ } else {
+ codec->pix_fmts = vp9_pix_fmts_def;
+ }
}
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 176c6b6..14ac6e9 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,69 @@ static av_cold int vp8_free(AVCodecContext *avctx)
return 0;
}
+#if CONFIG_LIBVPX_VP9_ENCODER
+static int set_pix_fmt(AVCodecContext *avctx, vpx_codec_caps_t codec_caps,
+ struct vpx_codec_enc_cfg *enccfg, vpx_codec_flags_t *flags,
+ vpx_img_fmt_t *img_fmt) {
+#ifdef VPX_IMG_FMT_HIGHBITDEPTH
+ enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
+#endif
+ switch (avctx->pix_fmt) {
+ case AV_PIX_FMT_YUV420P:
+ enccfg->g_profile = 0;
+ *img_fmt = VPX_IMG_FMT_I420;
+ return 0;
+ case AV_PIX_FMT_YUV422P:
+ case AV_PIX_FMT_YUV444P:
+ enccfg->g_profile = 1;
+ *img_fmt = avctx->pix_fmt == AV_PIX_FMT_YUV422P ? VPX_IMG_FMT_I422 : VPX_IMG_FMT_I444;
+ return 0;
+#ifdef VPX_IMG_FMT_HIGHBITDEPTH
+ case AV_PIX_FMT_YUV420P10LE:
+ case AV_PIX_FMT_YUV420P12LE:
+ if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
+ 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;
+ } else {
+ break;
+ }
+ case AV_PIX_FMT_YUV422P10LE:
+ case AV_PIX_FMT_YUV422P12LE:
+ if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
+ 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;
+ } else {
+ break;
+ }
+ case AV_PIX_FMT_YUV444P10LE:
+ case AV_PIX_FMT_YUV444P12LE:
+ if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
+ 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;
+ } else {
+ break;
+ }
+#endif
+ default:
+ break;
+ }
+ 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 +337,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 +352,16 @@ static av_cold int vpx_init(AVCodecContext *avctx,
return AVERROR(EINVAL);
}
+#if CONFIG_LIBVPX_VP9_ENCODER
+ if (avctx->codec_id == AV_CODEC_ID_VP9) {
+ if (set_pix_fmt(avctx, codec_caps, &enccfg, &flags, &img_fmt))
+ return AVERROR(EINVAL);
+#ifdef VPX_IMG_FMT_HIGHBITDEPTH
+ av_log(avctx, AV_LOG_INFO, "Bit-depth: %d\n", enccfg.g_bit_depth);
+#endif
+ }
+#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 +565,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 +1001,6 @@ 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 },
.priv_class = &class_vp9,
.defaults = defaults,
.init_static_data = ff_vp9_init_static,
--
2.2.0.rc0.207.ga3a616c
_______________________________________________
ffmpeg-devel mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel