From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 06/11] avcodec/libaomenc: add support for encoder reconfiguration Date: Tue, 18 Feb 2025 10:08:08 -0300 Message-ID: <20250218130813.74-6-jamrial@gmail.com> (raw) In-Reply-To: <20250218130813.74-1-jamrial@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com> --- libavcodec/libaomenc.c | 47 +++++++++++++++++++++++++++++++++++++----- libavcodec/libx264.c | 27 ++++++++---------------- 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c index 38bdff6a38..d040898b0e 100644 --- a/libavcodec/libaomenc.c +++ b/libavcodec/libaomenc.c @@ -1488,10 +1488,41 @@ static av_cold int av1_init(AVCodecContext *avctx) return aom_init(avctx, aom_codec_av1_cx()); } +static av_cold int av1_reconf(AVCodecContext *avctx, AVDictionary **dict) +{ + AOMContext *ctx = avctx->priv_data; + int loglevel; + int res; + + res = ff_encode_reconf_parse_dict(avctx, dict); + if (res < 0) + return res; + + res = aom_config(avctx, ctx->encoder.iface); + if (res < 0) + return res; + + res = aom_codec_enc_config_set(&ctx->encoder, &ctx->enccfg); + loglevel = res != AOM_CODEC_OK ? AV_LOG_WARNING : AV_LOG_DEBUG; + av_log(avctx, loglevel, "Reconfigure options:\n"); + dump_enc_cfg(avctx, &ctx->enccfg, loglevel); + if (res != AOM_CODEC_OK) { + log_encoder_error(avctx, "Failed to reconfigure encoder"); + return AVERROR(EINVAL); + } + + res = aom_codecctl(avctx); + if (res < 0) + return res; + + return 0; +} + #define OFFSET(x) offsetof(AOMContext, x) #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM +#define VER VE | AV_OPT_FLAG_RUNTIME_PARAM static const AVOption options[] = { - { "cpu-used", "Quality/Speed ratio modifier", OFFSET(cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 8, VE}, + { "cpu-used", "Quality/Speed ratio modifier", OFFSET(cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 8, VER}, { "auto-alt-ref", "Enable use of alternate reference " "frames (2-pass only)", OFFSET(auto_alt_ref), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2, VE}, { "lag-in-frames", "Number of frames to look ahead at for " @@ -1505,7 +1536,7 @@ static const AVOption options[] = { { "cyclic", "Cyclic Refresh Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE, .unit = "aq_mode"}, { "error-resilience", "Error resilience configuration", OFFSET(error_resilient), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, VE, .unit = "er"}, { "default", "Improve resiliency against losses of whole frames", 0, AV_OPT_TYPE_CONST, {.i64 = AOM_ERROR_RESILIENT_DEFAULT}, 0, 0, VE, .unit = "er"}, - { "crf", "Select the quality for constant quality mode", offsetof(AOMContext, crf), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, VE }, + { "crf", "Select the quality for constant quality mode", offsetof(AOMContext, crf), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, VER }, { "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 }, { "drop-threshold", "Frame drop threshold", offsetof(AOMContext, drop_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, VE }, { "denoise-noise-level", "Amount of noise to be removed", OFFSET(denoise_noise_level), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, @@ -1569,9 +1600,13 @@ static const AVOption options[] = { }; static const FFCodecDefault defaults[] = { - { "b", "0" }, - { "qmin", "-1" }, - { "qmax", "-1" }, + { "b", "0", AV_OPT_FLAG_RUNTIME_PARAM }, + { "bufsize", "0", AV_OPT_FLAG_RUNTIME_PARAM }, + { "maxrate", "0", AV_OPT_FLAG_RUNTIME_PARAM }, + { "minrate", "0", AV_OPT_FLAG_RUNTIME_PARAM }, + { "qmin", "-1", AV_OPT_FLAG_RUNTIME_PARAM }, + { "qmax", "-1", AV_OPT_FLAG_RUNTIME_PARAM }, + { "sar", "0", AV_OPT_FLAG_RUNTIME_PARAM }, { "g", "-1" }, { "keyint_min", "-1" }, { NULL }, @@ -1591,6 +1626,7 @@ FFCodec ff_libaom_av1_encoder = { .p.id = AV_CODEC_ID_AV1, .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_ENCODER_RECON_FRAME | + AV_CODEC_CAP_RECONF | AV_CODEC_CAP_OTHER_THREADS, .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG, .p.profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles), @@ -1598,6 +1634,7 @@ FFCodec ff_libaom_av1_encoder = { .p.wrapper_name = "libaom", .priv_data_size = sizeof(AOMContext), .init = av1_init, + .reconf = av1_reconf, FF_CODEC_ENCODE_CB(aom_encode), .close = aom_free, .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE | diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index d2adfa7bc5..d9cf7f5428 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -771,22 +771,9 @@ static void X264_flush(AVCodecContext *avctx) static av_cold int X264_reconf(AVCodecContext *avctx, AVDictionary **dict) { - static const AVOption global_opts[] = { - { "aspect", "sample aspect ratio", offsetof(AVCodecContext, sample_aspect_ratio), AV_OPT_TYPE_RATIONAL, {.dbl = 0}, 0, 10, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM}, - { "sar", "sample aspect ratio", offsetof(AVCodecContext, sample_aspect_ratio), AV_OPT_TYPE_RATIONAL, {.dbl = 0}, 0, 10, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM}, - { "bufsize", "set ratecontrol buffer size (in bits)", offsetof(AVCodecContext, rc_buffer_size), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM}, - { "b", "set bitrate (in bits/s)", offsetof(AVCodecContext, bit_rate), AV_OPT_TYPE_INT64, {.i64 = 0 }, 0, INT64_MAX, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM}, - { NULL }, - }; - static const AVOption private_opts[] = { - { "crf", "Select the quality for constant quality mode", offsetof(X264Context, crf), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM }, - { "crf_max", "In CRF mode, prevents VBV from lowering quality beyond this point.", offsetof(X264Context, crf_max), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM }, - { "qp", "Constant quantization parameter rate control method", offsetof(X264Context, cqp), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM }, - { NULL }, - }; int ret; - ret = ff_encode_reconf_parse_dict(avctx, global_opts, private_opts, dict); + ret = ff_encode_reconf_parse_dict(avctx, dict); if (ret < 0) return ret; @@ -1536,6 +1523,7 @@ static const enum AVPixelFormat pix_fmts_8bit_rgb[] = { #define OFFSET(x) offsetof(X264Context, x) #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM +#define VER VE | AV_OPT_FLAG_RUNTIME_PARAM static const AVOption options[] = { { "preset", "Set the encoding preset (cf. x264 --fullhelp)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "medium" }, 0, 0, VE}, { "tune", "Tune the encoding params (cf. x264 --fullhelp)", OFFSET(tune), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE}, @@ -1546,9 +1534,9 @@ static const AVOption options[] = { {"wpredp", "Weighted prediction for P-frames", OFFSET(wpredp), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE}, {"a53cc", "Use A53 Closed Captions (if available)", OFFSET(a53_cc), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, VE}, {"x264opts", "x264 options", OFFSET(x264opts), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE}, - { "crf", "Select the quality for constant quality mode", OFFSET(crf), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, VE }, - { "crf_max", "In CRF mode, prevents VBV from lowering quality beyond this point.",OFFSET(crf_max), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, VE }, - { "qp", "Constant quantization parameter rate control method",OFFSET(cqp), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE }, + { "crf", "Select the quality for constant quality mode", OFFSET(crf), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, VER }, + { "crf_max", "In CRF mode, prevents VBV from lowering quality beyond this point.",OFFSET(crf_max), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, VER }, + { "qp", "Constant quantization parameter rate control method",OFFSET(cqp), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VER }, { "aq-mode", "AQ method", OFFSET(aq_mode), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, .unit = "aq_mode"}, { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_AQ_NONE}, INT_MIN, INT_MAX, VE, .unit = "aq_mode" }, { "variance", "Variance AQ (complexity mask)", 0, AV_OPT_TYPE_CONST, {.i64 = X264_AQ_VARIANCE}, INT_MIN, INT_MAX, VE, .unit = "aq_mode" }, @@ -1618,7 +1606,10 @@ static const AVOption options[] = { }; static const FFCodecDefault x264_defaults[] = { - { "b", "0" }, + { "sar", "0", AV_OPT_FLAG_RUNTIME_PARAM }, + { "b", "0", AV_OPT_FLAG_RUNTIME_PARAM }, + { "bufsize", "0", AV_OPT_FLAG_RUNTIME_PARAM }, + { "maxrate", "0", AV_OPT_FLAG_RUNTIME_PARAM }, { "bf", "-1" }, { "flags2", "0" }, { "g", "-1" }, -- 2.48.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".
next prev parent reply other threads:[~2025-02-18 13:10 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-02-18 13:08 [FFmpeg-devel] [PATCH 01/11] avutil/opt: allow passing a fake object to av_opt_set() James Almer 2025-02-18 13:08 ` [FFmpeg-devel] [PATCH 02/11] avcodec/encode: add a function to gracefully reconfigure an encoder James Almer 2025-02-18 13:08 ` [FFmpeg-devel] [PATCH 03/11] avcodec/libx264: refactor encoder configuration functions James Almer 2025-02-18 13:08 ` [FFmpeg-devel] [PATCH 04/11] avcodec/libx264: add support for encoder reconfiguration James Almer 2025-02-18 13:08 ` [FFmpeg-devel] [PATCH 05/11] avcodec/libaomenc: refactor encoder configuration functions James Almer 2025-02-18 13:08 ` James Almer [this message] 2025-02-18 13:08 ` [FFmpeg-devel] [PATCH 07/11] fftools/ffmpeg_filter: add AVOptions to OutputFilter James Almer 2025-02-18 13:08 ` [FFmpeg-devel] [PATCH 08/11] fftools/ffmpeg_enc: split off parts of enc_open() into a separate function James Almer 2025-02-18 13:08 ` [FFmpeg-devel] [PATCH 09/11] fftools/ffmpeg_enc: split off encoder flushing in encoder_thread() " James Almer 2025-02-18 13:08 ` [FFmpeg-devel] [PATCH 10/11] fftools/ffmpeg_enc: store a few more AVCodecContext fields in Encoder James Almer 2025-02-18 13:08 ` [FFmpeg-devel] [PATCH 11/11] fftools/ffmpeg: support reinitializing the encoder James Almer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20250218130813.74-6-jamrial@gmail.com \ --to=jamrial@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git