diff options
Diffstat (limited to 'graphics/ffmpeg/patches/patch-libavcodec_libaomenc_c')
| -rw-r--r-- | graphics/ffmpeg/patches/patch-libavcodec_libaomenc_c | 218 |
1 files changed, 0 insertions, 218 deletions
diff --git a/graphics/ffmpeg/patches/patch-libavcodec_libaomenc_c b/graphics/ffmpeg/patches/patch-libavcodec_libaomenc_c deleted file mode 100644 index 254b5ee..0000000 --- a/graphics/ffmpeg/patches/patch-libavcodec_libaomenc_c +++ /dev/null | |||
| @@ -1,218 +0,0 @@ | |||
| 1 | - lavc/aomenc: Force default qmax of 0 if crf was set to 0 | ||
| 2 | - avcodec/libaomenc: Avoid copying data, allow user-supplied buffers | ||
| 3 | - lavc/libaomenc: Show encoder config as a warning in case of failed initialization | ||
| 4 | - avcodec/libaomenc: use ctx->usage to get default cfg | ||
| 5 | - avcodec/libaomenc: remove the redundant initialization | ||
| 6 | - avcodec/libaomenc: Add unmet target level warning | ||
| 7 | - avcodec/libaomenc: Expose the allintra usage mode | ||
| 8 | - avcodec/libaomenc: Get number of operating points | ||
| 9 | |||
| 10 | Index: libavcodec/libaomenc.c | ||
| 11 | --- libavcodec/libaomenc.c.orig | ||
| 12 | +++ libavcodec/libaomenc.c | ||
| 13 | @@ -36,6 +36,7 @@ | ||
| 14 | |||
| 15 | #include "av1.h" | ||
| 16 | #include "avcodec.h" | ||
| 17 | +#include "encode.h" | ||
| 18 | #include "internal.h" | ||
| 19 | #include "packet_internal.h" | ||
| 20 | #include "profiles.h" | ||
| 21 | @@ -194,6 +195,15 @@ static const char *const ctlidstr[] = { | ||
| 22 | [AV1E_SET_ENABLE_SMOOTH_INTERINTRA] = "AV1E_SET_ENABLE_SMOOTH_INTERINTRA", | ||
| 23 | [AV1E_SET_ENABLE_REF_FRAME_MVS] = "AV1E_SET_ENABLE_REF_FRAME_MVS", | ||
| 24 | #endif | ||
| 25 | +#ifdef AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS | ||
| 26 | + [AV1E_GET_NUM_OPERATING_POINTS] = "AV1E_GET_NUM_OPERATING_POINTS", | ||
| 27 | +#endif | ||
| 28 | +#ifdef AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX | ||
| 29 | + [AV1E_GET_SEQ_LEVEL_IDX] = "AV1E_GET_SEQ_LEVEL_IDX", | ||
| 30 | +#endif | ||
| 31 | +#ifdef AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX | ||
| 32 | + [AV1E_GET_TARGET_SEQ_LEVEL_IDX] = "AV1E_GET_TARGET_SEQ_LEVEL_IDX", | ||
| 33 | +#endif | ||
| 34 | }; | ||
| 35 | |||
| 36 | static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc) | ||
| 37 | @@ -208,10 +218,10 @@ static av_cold void log_encoder_error(AVCodecContext * | ||
| 38 | } | ||
| 39 | |||
| 40 | static av_cold void dump_enc_cfg(AVCodecContext *avctx, | ||
| 41 | - const struct aom_codec_enc_cfg *cfg) | ||
| 42 | + const struct aom_codec_enc_cfg *cfg, | ||
| 43 | + int level) | ||
| 44 | { | ||
| 45 | int width = -30; | ||
| 46 | - int level = AV_LOG_DEBUG; | ||
| 47 | |||
| 48 | av_log(avctx, level, "aom_codec_enc_cfg\n"); | ||
| 49 | av_log(avctx, level, "generic settings\n" | ||
| 50 | @@ -319,10 +329,73 @@ static av_cold int codecctl_int(AVCodecContext *avctx, | ||
| 51 | return 0; | ||
| 52 | } | ||
| 53 | |||
| 54 | +#if defined(AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS) && \ | ||
| 55 | + defined(AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX) && \ | ||
| 56 | + defined(AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX) | ||
| 57 | +static av_cold int codecctl_intp(AVCodecContext *avctx, | ||
| 58 | +#ifdef UENUM1BYTE | ||
| 59 | + aome_enc_control_id id, | ||
| 60 | +#else | ||
| 61 | + enum aome_enc_control_id id, | ||
| 62 | +#endif | ||
| 63 | + int* ptr) | ||
| 64 | +{ | ||
| 65 | + AOMContext *ctx = avctx->priv_data; | ||
| 66 | + char buf[80]; | ||
| 67 | + int width = -30; | ||
| 68 | + int res; | ||
| 69 | + | ||
| 70 | + snprintf(buf, sizeof(buf), "%s:", ctlidstr[id]); | ||
| 71 | + av_log(avctx, AV_LOG_DEBUG, " %*s%d\n", width, buf, *ptr); | ||
| 72 | + | ||
| 73 | + res = aom_codec_control(&ctx->encoder, id, ptr); | ||
| 74 | + if (res != AOM_CODEC_OK) { | ||
| 75 | + snprintf(buf, sizeof(buf), "Failed to set %s codec control", | ||
| 76 | + ctlidstr[id]); | ||
| 77 | + log_encoder_error(avctx, buf); | ||
| 78 | + return AVERROR(EINVAL); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + return 0; | ||
| 82 | +} | ||
| 83 | +#endif | ||
| 84 | + | ||
| 85 | static av_cold int aom_free(AVCodecContext *avctx) | ||
| 86 | { | ||
| 87 | AOMContext *ctx = avctx->priv_data; | ||
| 88 | |||
| 89 | +#if defined(AOM_CTRL_AV1E_GET_NUM_OPERATING_POINTS) && \ | ||
| 90 | + defined(AOM_CTRL_AV1E_GET_SEQ_LEVEL_IDX) && \ | ||
| 91 | + defined(AOM_CTRL_AV1E_GET_TARGET_SEQ_LEVEL_IDX) | ||
| 92 | + if (!(avctx->flags & AV_CODEC_FLAG_PASS1)) { | ||
| 93 | + int num_operating_points; | ||
| 94 | + int levels[32]; | ||
| 95 | + int target_levels[32]; | ||
| 96 | + | ||
| 97 | + if (!codecctl_intp(avctx, AV1E_GET_NUM_OPERATING_POINTS, | ||
| 98 | + &num_operating_points) && | ||
| 99 | + !codecctl_intp(avctx, AV1E_GET_SEQ_LEVEL_IDX, levels) && | ||
| 100 | + !codecctl_intp(avctx, AV1E_GET_TARGET_SEQ_LEVEL_IDX, | ||
| 101 | + target_levels)) { | ||
| 102 | + for (int i = 0; i < num_operating_points; i++) { | ||
| 103 | + if (levels[i] > target_levels[i]) { | ||
| 104 | + // Warn when the target level was not met | ||
| 105 | + av_log(avctx, AV_LOG_WARNING, | ||
| 106 | + "Could not encode to target level %d.%d for " | ||
| 107 | + "operating point %d. The output level is %d.%d.\n", | ||
| 108 | + 2 + (target_levels[i] >> 2), target_levels[i] & 3, | ||
| 109 | + i, 2 + (levels[i] >> 2), levels[i] & 3); | ||
| 110 | + } else if (target_levels[i] < 31) { | ||
| 111 | + // Log the encoded level if a target level was given | ||
| 112 | + av_log(avctx, AV_LOG_INFO, | ||
| 113 | + "Output level for operating point %d is %d.%d.\n", | ||
| 114 | + i, 2 + (levels[i] >> 2), levels[i] & 3); | ||
| 115 | + } | ||
| 116 | + } | ||
| 117 | + } | ||
| 118 | + } | ||
| 119 | +#endif | ||
| 120 | + | ||
| 121 | aom_codec_destroy(&ctx->encoder); | ||
| 122 | av_freep(&ctx->twopass_stats.buf); | ||
| 123 | av_freep(&avctx->stats_out); | ||
| 124 | @@ -596,7 +669,7 @@ static av_cold int aom_init(AVCodecContext *avctx, | ||
| 125 | av_log(avctx, AV_LOG_INFO, "%s\n", aom_codec_version_str()); | ||
| 126 | av_log(avctx, AV_LOG_VERBOSE, "%s\n", aom_codec_build_config()); | ||
| 127 | |||
| 128 | - if ((res = aom_codec_enc_config_default(iface, &enccfg, 0)) != AOM_CODEC_OK) { | ||
| 129 | + if ((res = aom_codec_enc_config_default(iface, &enccfg, ctx->usage)) != AOM_CODEC_OK) { | ||
| 130 | av_log(avctx, AV_LOG_ERROR, "Failed to get config: %s\n", | ||
| 131 | aom_codec_err_to_string(res)); | ||
| 132 | return AVERROR(EINVAL); | ||
| 133 | @@ -611,7 +684,7 @@ static av_cold int aom_init(AVCodecContext *avctx, | ||
| 134 | return AVERROR(EINVAL); | ||
| 135 | } | ||
| 136 | |||
| 137 | - dump_enc_cfg(avctx, &enccfg); | ||
| 138 | + dump_enc_cfg(avctx, &enccfg, AV_LOG_DEBUG); | ||
| 139 | |||
| 140 | enccfg.g_w = avctx->width; | ||
| 141 | enccfg.g_h = avctx->height; | ||
| 142 | @@ -620,8 +693,6 @@ static av_cold int aom_init(AVCodecContext *avctx, | ||
| 143 | enccfg.g_threads = | ||
| 144 | FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 64); | ||
| 145 | |||
| 146 | - enccfg.g_usage = ctx->usage; | ||
| 147 | - | ||
| 148 | if (ctx->lag_in_frames >= 0) | ||
| 149 | enccfg.g_lag_in_frames = ctx->lag_in_frames; | ||
| 150 | |||
| 151 | @@ -654,8 +725,11 @@ static av_cold int aom_init(AVCodecContext *avctx, | ||
| 152 | |||
| 153 | if (avctx->qmin >= 0) | ||
| 154 | enccfg.rc_min_quantizer = avctx->qmin; | ||
| 155 | - if (avctx->qmax >= 0) | ||
| 156 | + if (avctx->qmax >= 0) { | ||
| 157 | enccfg.rc_max_quantizer = avctx->qmax; | ||
| 158 | + } else if (!ctx->crf) { | ||
| 159 | + enccfg.rc_max_quantizer = 0; | ||
| 160 | + } | ||
| 161 | |||
| 162 | if (enccfg.rc_end_usage == AOM_CQ || enccfg.rc_end_usage == AOM_Q) { | ||
| 163 | if (ctx->crf < enccfg.rc_min_quantizer || ctx->crf > enccfg.rc_max_quantizer) { | ||
| 164 | @@ -742,13 +816,14 @@ static av_cold int aom_init(AVCodecContext *avctx, | ||
| 165 | if (res < 0) | ||
| 166 | return res; | ||
| 167 | |||
| 168 | - dump_enc_cfg(avctx, &enccfg); | ||
| 169 | /* Construct Encoder Context */ | ||
| 170 | res = aom_codec_enc_init(&ctx->encoder, iface, &enccfg, flags); | ||
| 171 | if (res != AOM_CODEC_OK) { | ||
| 172 | + dump_enc_cfg(avctx, &enccfg, AV_LOG_WARNING); | ||
| 173 | log_encoder_error(avctx, "Failed to initialize encoder"); | ||
| 174 | return AVERROR(EINVAL); | ||
| 175 | } | ||
| 176 | + dump_enc_cfg(avctx, &enccfg, AV_LOG_DEBUG); | ||
| 177 | |||
| 178 | // codec control failures are currently treated only as warnings | ||
| 179 | av_log(avctx, AV_LOG_DEBUG, "aom_codec_control\n"); | ||
| 180 | @@ -943,7 +1018,6 @@ static inline void cx_pktcpy(AOMContext *ctx, | ||
| 181 | dst->sz = src->data.frame.sz; | ||
| 182 | dst->buf = src->data.frame.buf; | ||
| 183 | #ifdef AOM_FRAME_IS_INTRAONLY | ||
| 184 | - dst->have_sse = 0; | ||
| 185 | dst->frame_number = ++ctx->frame_number; | ||
| 186 | dst->have_sse = ctx->have_sse; | ||
| 187 | if (ctx->have_sse) { | ||
| 188 | @@ -967,7 +1041,7 @@ static int storeframe(AVCodecContext *avctx, struct Fr | ||
| 189 | { | ||
| 190 | AOMContext *ctx = avctx->priv_data; | ||
| 191 | int av_unused pict_type; | ||
| 192 | - int ret = ff_alloc_packet2(avctx, pkt, cx_frame->sz, 0); | ||
| 193 | + int ret = ff_get_encode_buffer(avctx, pkt, cx_frame->sz, 0); | ||
| 194 | if (ret < 0) { | ||
| 195 | av_log(avctx, AV_LOG_ERROR, | ||
| 196 | "Error getting output packet of size %"SIZE_SPECIFIER".\n", cx_frame->sz); | ||
| 197 | @@ -1282,6 +1356,7 @@ static const AVOption options[] = { | ||
| 198 | { "usage", "Quality and compression efficiency vs speed trade-off", OFFSET(usage), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, "usage"}, | ||
| 199 | { "good", "Good quality", 0, AV_OPT_TYPE_CONST, {.i64 = 0 /* AOM_USAGE_GOOD_QUALITY */}, 0, 0, VE, "usage"}, | ||
| 200 | { "realtime", "Realtime encoding", 0, AV_OPT_TYPE_CONST, {.i64 = 1 /* AOM_USAGE_REALTIME */}, 0, 0, VE, "usage"}, | ||
| 201 | + { "allintra", "All Intra encoding", 0, AV_OPT_TYPE_CONST, {.i64 = 2 /* AOM_USAGE_ALL_INTRA */}, 0, 0, VE, "usage"}, | ||
| 202 | { "tune", "The metric that the encoder tunes for. Automatically chosen by the encoder by default", OFFSET(tune), AV_OPT_TYPE_INT, {.i64 = -1}, -1, AOM_TUNE_SSIM, VE, "tune"}, | ||
| 203 | { "psnr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AOM_TUNE_PSNR}, 0, 0, VE, "tune"}, | ||
| 204 | { "ssim", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AOM_TUNE_SSIM}, 0, 0, VE, "tune"}, | ||
| 205 | @@ -1341,11 +1416,12 @@ AVCodec ff_libaom_av1_encoder = { | ||
| 206 | .long_name = NULL_IF_CONFIG_SMALL("libaom AV1"), | ||
| 207 | .type = AVMEDIA_TYPE_VIDEO, | ||
| 208 | .id = AV_CODEC_ID_AV1, | ||
| 209 | + .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | | ||
| 210 | + AV_CODEC_CAP_OTHER_THREADS, | ||
| 211 | .priv_data_size = sizeof(AOMContext), | ||
| 212 | .init = av1_init, | ||
| 213 | .encode2 = aom_encode, | ||
| 214 | .close = aom_free, | ||
| 215 | - .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_OTHER_THREADS, | ||
| 216 | .caps_internal = FF_CODEC_CAP_AUTO_THREADS, | ||
| 217 | .profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles), | ||
| 218 | .priv_class = &class_aom, | ||
