X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Flibvpxenc.c;h=b2deb5d93bdc32f68abc2e3e27fd49cc4435f5c3;hb=4299f085f45cdd8fcb3ecf681d9fef0c4b3fe207;hp=adf4b2e2f6d35472c69ac23f33a798611024843c;hpb=abee1972ef8a88fde0bff5f40f4767cb3150d26e;p=ffmpeg diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index adf4b2e2f6d..b2deb5d93bd 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -91,6 +91,8 @@ typedef struct VP8EncoderContext { int crf; int static_thresh; int max_intra_rate; + int rc_undershoot_pct; + int rc_overshoot_pct; // VP9-only int lossless; @@ -126,6 +128,9 @@ static const char *const ctlidstr[] = { [VP9E_SET_TILE_ROWS] = "VP9E_SET_TILE_ROWS", [VP9E_SET_FRAME_PARALLEL_DECODING] = "VP9E_SET_FRAME_PARALLEL_DECODING", [VP9E_SET_AQ_MODE] = "VP9E_SET_AQ_MODE", +#if VPX_ENCODER_ABI_VERSION > 8 + [VP9E_SET_COLOR_SPACE] = "VP9E_SET_COLOR_SPACE", +#endif #endif }; @@ -347,6 +352,29 @@ static int set_pix_fmt(AVCodecContext *avctx, vpx_codec_caps_t codec_caps, av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format.\n"); return AVERROR_INVALIDDATA; } + +#if VPX_ENCODER_ABI_VERSION > 8 +static void set_colorspace(AVCodecContext *avctx) +{ + enum vpx_color_space vpx_cs; + + switch (avctx->colorspace) { + case AVCOL_SPC_RGB: vpx_cs = VPX_CS_SRGB; break; + case AVCOL_SPC_BT709: vpx_cs = VPX_CS_BT_709; break; + case AVCOL_SPC_UNSPECIFIED: vpx_cs = VPX_CS_UNKNOWN; break; + case AVCOL_SPC_RESERVED: vpx_cs = VPX_CS_RESERVED; break; + case AVCOL_SPC_BT470BG: vpx_cs = VPX_CS_BT_601; break; + case AVCOL_SPC_SMPTE170M: vpx_cs = VPX_CS_SMPTE_170; break; + case AVCOL_SPC_SMPTE240M: vpx_cs = VPX_CS_SMPTE_240; break; + case AVCOL_SPC_BT2020_NCL: vpx_cs = VPX_CS_BT_2020; break; + default: + av_log(avctx, AV_LOG_WARNING, "Unsupported colorspace (%d)\n", + avctx->colorspace); + return; + } + codecctl_int(avctx, VP9E_SET_COLOR_SPACE, vpx_cs); +} +#endif #endif static av_cold int vpx_init(AVCodecContext *avctx, @@ -472,7 +500,19 @@ static av_cold int vpx_init(AVCodecContext *avctx, enccfg.rc_buf_initial_sz = avctx->rc_initial_buffer_occupancy * 1000LL / avctx->bit_rate; enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6; - enccfg.rc_undershoot_pct = round(avctx->rc_buffer_aggressivity * 100); +#if FF_API_MPV_OPT + FF_DISABLE_DEPRECATION_WARNINGS + if (avctx->rc_buffer_aggressivity != 1.0) { + av_log(avctx, AV_LOG_WARNING, "The rc_buffer_aggressivity option is " + "deprecated, use the undershoot-pct private option instead.\n"); + enccfg.rc_undershoot_pct = round(avctx->rc_buffer_aggressivity * 100); + } + FF_ENABLE_DEPRECATION_WARNINGS +#endif + if (ctx->rc_undershoot_pct >= 0) + enccfg.rc_undershoot_pct = ctx->rc_undershoot_pct; + if (ctx->rc_overshoot_pct >= 0) + enccfg.rc_overshoot_pct = ctx->rc_overshoot_pct; //_enc_init() will balk if kf_min_dist differs from max w/VPX_KF_AUTO if (avctx->keyint_min >= 0 && avctx->keyint_min == avctx->gop_size) @@ -579,6 +619,9 @@ static av_cold int vpx_init(AVCodecContext *avctx, codecctl_int(avctx, VP9E_SET_FRAME_PARALLEL_DECODING, ctx->frame_parallel); if (ctx->aq_mode >= 0) codecctl_int(avctx, VP9E_SET_AQ_MODE, ctx->aq_mode); +#if VPX_ENCODER_ABI_VERSION > 8 + set_colorspace(avctx); +#endif } #endif @@ -920,6 +963,8 @@ static int vp8_encode(AVCodecContext *avctx, AVPacket *pkt, " is still done over the partition boundary.", 0, AV_OPT_TYPE_CONST, {.i64 = VPX_ERROR_RESILIENT_PARTITIONS}, 0, 0, VE, "er"}, \ { "crf", "Select the quality for constant quality mode", offsetof(VP8Context, crf), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, VE }, \ { "static-thresh", "A change threshold on blocks below which they will be skipped by the encoder", OFFSET(static_thresh), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE }, \ + { "undershoot-pct", "Datarate undershoot (min) target (%)", OFFSET(rc_undershoot_pct), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 100, VE }, \ + { "overshoot-pct", "Datarate overshoot (max) target (%)", OFFSET(rc_overshoot_pct), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1000, VE }, \ #define LEGACY_OPTIONS \ {"speed", "", offsetof(VP8Context, cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, -16, 16, VE}, \ @@ -948,10 +993,10 @@ static const AVOption vp9_options[] = { { "tile-rows", "Number of tile rows to use, log2", OFFSET(tile_rows), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2, VE}, { "frame-parallel", "Enable frame parallel decodability features", OFFSET(frame_parallel), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, VE}, { "aq-mode", "adaptive quantization mode", OFFSET(aq_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 3, VE, "aq_mode"}, - { "none", "Aq not used", 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE, "aq_mode" }, \ - { "variance", "Variance based Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "aq_mode" }, \ - { "complexity", "Complexity based Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, "aq_mode" }, \ - { "cyclic", "Cyclic Refresh Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE, "aq_mode" }, \ + { "none", "Aq not used", 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE, "aq_mode" }, + { "variance", "Variance based Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "aq_mode" }, + { "complexity", "Complexity based Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, "aq_mode" }, + { "cyclic", "Cyclic Refresh Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE, "aq_mode" }, LEGACY_OPTIONS { NULL } };