* [FFmpeg-devel] [PATCH] Allow enabling SVC in libaomenc
@ 2024-06-24 18:50 Chun-Min Chang
2024-06-25 8:45 ` Anton Khirnov
0 siblings, 1 reply; 6+ messages in thread
From: Chun-Min Chang @ 2024-06-24 18:50 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Chun-Min Chang
This patch updates libaomenc.c to accept parameters for SVC (Scalable
Video Coding) settings via the FFmpeg API `av_opt_set`. The SVC
configuration is applied based on the provided parameters. As libaom's
SVC functionality only operates with constant bitrate encoding [1],
these parameters will only take effect when the bitrate is set to
constant.
[1] https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/encoder/svc_layercontext.h#115
---
libavcodec/libaomenc.c | 75 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index dec74ebecd..a8602a6b56 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -30,6 +30,7 @@
#include <aom/aomcx.h>
#include "libavutil/avassert.h"
+#include "libavutil/avstring.h"
#include "libavutil/base64.h"
#include "libavutil/common.h"
#include "libavutil/cpu.h"
@@ -137,6 +138,7 @@ typedef struct AOMEncoderContext {
int enable_diff_wtd_comp;
int enable_dist_wtd_comp;
int enable_dual_filter;
+ AVDictionary *svc_parameters;
AVDictionary *aom_params;
} AOMContext;
@@ -201,6 +203,7 @@ static const char *const ctlidstr[] = {
[AV1E_GET_TARGET_SEQ_LEVEL_IDX] = "AV1E_GET_TARGET_SEQ_LEVEL_IDX",
#endif
[AV1_GET_NEW_FRAME_IMAGE] = "AV1_GET_NEW_FRAME_IMAGE",
+ [AV1E_SET_SVC_PARAMS] = "AV1E_SET_SVC_PARAMS",
};
static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -382,6 +385,31 @@ static av_cold int codecctl_imgp(AVCodecContext *avctx,
return 0;
}
+static av_cold int codecctl_svcp(AVCodecContext *avctx,
+#ifdef UENUM1BYTE
+ aome_enc_control_id id,
+#else
+ enum aome_enc_control_id id,
+#endif
+ aom_svc_params_t *svc_params)
+{
+ AOMContext *ctx = avctx->priv_data;
+ char buf[80];
+ int res;
+
+ snprintf(buf, sizeof(buf), "%s:", ctlidstr[id]);
+
+ res = aom_codec_control(&ctx->encoder, id, svc_params);
+ if (res != AOM_CODEC_OK) {
+ snprintf(buf, sizeof(buf), "Failed to get %s codec control",
+ ctlidstr[id]);
+ log_encoder_error(avctx, buf);
+ return AVERROR(EINVAL);
+ }
+
+ return 0;
+}
+
static av_cold int aom_free(AVCodecContext *avctx)
{
AOMContext *ctx = avctx->priv_data;
@@ -673,6 +701,18 @@ static int choose_tiling(AVCodecContext *avctx,
return 0;
}
+static void aom_svc_parse_int_array(int *dest, char *value, int max_entries)
+{
+ int dest_idx = 0;
+ char *saveptr = NULL;
+ char *token = av_strtok(value, ",", &saveptr);
+
+ while (token && dest_idx < max_entries) {
+ dest[dest_idx++] = strtoul(token, NULL, 10);
+ token = av_strtok(NULL, ",", &saveptr);
+ }
+}
+
static av_cold int aom_init(AVCodecContext *avctx,
const struct aom_codec_iface *iface)
{
@@ -968,6 +1008,40 @@ static av_cold int aom_init(AVCodecContext *avctx,
if (ctx->enable_intrabc >= 0)
codecctl_int(avctx, AV1E_SET_ENABLE_INTRABC, ctx->enable_intrabc);
+ if (enccfg.rc_end_usage == AOM_CBR) {
+ aom_svc_params_t svc_params = {};
+ svc_params.framerate_factor[0] = 1;
+ svc_params.number_spatial_layers = 1;
+ svc_params.number_temporal_layers = 1;
+
+ const AVDictionaryEntry *en = NULL;
+ while ((en = av_dict_iterate(ctx->svc_parameters, en))) {
+ if (!strlen(en->value))
+ return AVERROR(EINVAL);
+
+ if (!strcmp(en->key, "number_spatial_layers"))
+ svc_params.number_spatial_layers = strtoul(en->value, NULL, 10);
+ else if (!strcmp(en->key, "number_temporal_layers"))
+ svc_params.number_temporal_layers = strtoul(en->value, NULL, 10);
+ else if (!strcmp(en->key, "max_quantizers"))
+ aom_svc_parse_int_array(svc_params.max_quantizers, en->value, AOM_MAX_LAYERS);
+ else if (!strcmp(en->key, "min_quantizers"))
+ aom_svc_parse_int_array(svc_params.min_quantizers, en->value, AOM_MAX_LAYERS);
+ else if (!strcmp(en->key, "scaling_factor_num"))
+ aom_svc_parse_int_array(svc_params.scaling_factor_num, en->value, AOM_MAX_SS_LAYERS);
+ else if (!strcmp(en->key, "scaling_factor_den"))
+ aom_svc_parse_int_array(svc_params.scaling_factor_den, en->value, AOM_MAX_SS_LAYERS);
+ else if (!strcmp(en->key, "layer_target_bitrate"))
+ aom_svc_parse_int_array(svc_params.layer_target_bitrate, en->value, AOM_MAX_LAYERS);
+ else if (!strcmp(en->key, "framerate_factor"))
+ aom_svc_parse_int_array(svc_params.framerate_factor, en->value, AOM_MAX_TS_LAYERS);
+ }
+
+ res = codecctl_svcp(avctx, AV1E_SET_SVC_PARAMS, &svc_params);
+ if (res < 0)
+ return res;
+ }
+
#if AOM_ENCODER_ABI_VERSION >= 23
{
const AVDictionaryEntry *en = NULL;
@@ -1517,6 +1591,7 @@ static const AVOption options[] = {
{ "enable-masked-comp", "Enable masked compound", OFFSET(enable_masked_comp), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
{ "enable-interintra-comp", "Enable interintra compound", OFFSET(enable_interintra_comp), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
{ "enable-smooth-interintra", "Enable smooth interintra mode", OFFSET(enable_smooth_interintra), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
+ { "svc-parameters", "SVC configuration using a :-separated list of key=value parameters (only applied in CBR mode)", OFFSET(svc_parameters), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE},
#if AOM_ENCODER_ABI_VERSION >= 23
{ "aom-params", "Set libaom options using a :-separated list of key=value pairs", OFFSET(aom_params), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE },
#endif
--
2.34.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".
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH] Allow enabling SVC in libaomenc
2024-06-24 18:50 [FFmpeg-devel] [PATCH] Allow enabling SVC in libaomenc Chun-Min Chang
@ 2024-06-25 8:45 ` Anton Khirnov
0 siblings, 0 replies; 6+ messages in thread
From: Anton Khirnov @ 2024-06-25 8:45 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Chun-Min Chang
Quoting Chun-Min Chang (2024-06-24 20:50:59)
> + const AVDictionaryEntry *en = NULL;
> + while ((en = av_dict_iterate(ctx->svc_parameters, en))) {
> + if (!strlen(en->value))
> + return AVERROR(EINVAL);
> +
> + if (!strcmp(en->key, "number_spatial_layers"))
> + svc_params.number_spatial_layers = strtoul(en->value, NULL, 10);
> + else if (!strcmp(en->key, "number_temporal_layers"))
> + svc_params.number_temporal_layers = strtoul(en->value, NULL, 10);
> + else if (!strcmp(en->key, "max_quantizers"))
> + aom_svc_parse_int_array(svc_params.max_quantizers, en->value, AOM_MAX_LAYERS);
> + else if (!strcmp(en->key, "min_quantizers"))
> + aom_svc_parse_int_array(svc_params.min_quantizers, en->value, AOM_MAX_LAYERS);
> + else if (!strcmp(en->key, "scaling_factor_num"))
> + aom_svc_parse_int_array(svc_params.scaling_factor_num, en->value, AOM_MAX_SS_LAYERS);
> + else if (!strcmp(en->key, "scaling_factor_den"))
> + aom_svc_parse_int_array(svc_params.scaling_factor_den, en->value, AOM_MAX_SS_LAYERS);
> + else if (!strcmp(en->key, "layer_target_bitrate"))
> + aom_svc_parse_int_array(svc_params.layer_target_bitrate, en->value, AOM_MAX_LAYERS);
> + else if (!strcmp(en->key, "framerate_factor"))
> + aom_svc_parse_int_array(svc_params.framerate_factor, en->value, AOM_MAX_TS_LAYERS);
So you declare a new dict-type option, then parse this dict manually
instead of AVOptions doing this work for you? Why?
--
Anton Khirnov
_______________________________________________
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".
^ permalink raw reply [flat|nested] 6+ messages in thread
* [FFmpeg-devel] [PATCH] Allow enabling SVC in libaomenc
@ 2024-06-11 20:22 Chun-Min Chang
2024-06-11 20:28 ` Chun-Min Chang
0 siblings, 1 reply; 6+ messages in thread
From: Chun-Min Chang @ 2024-06-11 20:22 UTC (permalink / raw)
To: ffmpeg-devel
This patch updates libaomenc.c to accept parameters for SVC (Scalable
Video Coding) settings via the FFmpeg API `av_opt_set`. The SVC
configuration is applied based on the provided parameters. As libaom's
SVC functionality only operates with constant bitrate encoding [1],
these parameters will only take effect when the bitrate is set to
constant.
[1]
https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/encoder/svc_layercontext.h#115
Signed-off-by: Chun-Min Chang <chun.m.chang@gmail.com>
---
libavcodec/libaomenc.c | 75 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index dec74ebecd..a8602a6b56 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -30,6 +30,7 @@
#include <aom/aomcx.h>
#include "libavutil/avassert.h"
+#include "libavutil/avstring.h"
#include "libavutil/base64.h"
#include "libavutil/common.h"
#include "libavutil/cpu.h"
@@ -137,6 +138,7 @@ typedef struct AOMEncoderContext {
int enable_diff_wtd_comp;
int enable_dist_wtd_comp;
int enable_dual_filter;
+ AVDictionary *svc_parameters;
AVDictionary *aom_params;
} AOMContext;
@@ -201,6 +203,7 @@ static const char *const ctlidstr[] = {
[AV1E_GET_TARGET_SEQ_LEVEL_IDX] = "AV1E_GET_TARGET_SEQ_LEVEL_IDX",
#endif
[AV1_GET_NEW_FRAME_IMAGE] = "AV1_GET_NEW_FRAME_IMAGE",
+ [AV1E_SET_SVC_PARAMS] = "AV1E_SET_SVC_PARAMS",
};
static av_cold void log_encoder_error(AVCodecContext *avctx, const
char *desc)
@@ -382,6 +385,31 @@ static av_cold int codecctl_imgp(AVCodecContext *avctx,
return 0;
}
+static av_cold int codecctl_svcp(AVCodecContext *avctx,
+#ifdef UENUM1BYTE
+ aome_enc_control_id id,
+#else
+ enum aome_enc_control_id id,
+#endif
+ aom_svc_params_t *svc_params)
+{
+ AOMContext *ctx = avctx->priv_data;
+ char buf[80];
+ int res;
+
+ snprintf(buf, sizeof(buf), "%s:", ctlidstr[id]);
+
+ res = aom_codec_control(&ctx->encoder, id, svc_params);
+ if (res != AOM_CODEC_OK) {
+ snprintf(buf, sizeof(buf), "Failed to get %s codec control",
+ ctlidstr[id]);
+ log_encoder_error(avctx, buf);
+ return AVERROR(EINVAL);
+ }
+
+ return 0;
+}
+
static av_cold int aom_free(AVCodecContext *avctx)
{
AOMContext *ctx = avctx->priv_data;
@@ -673,6 +701,18 @@ static int choose_tiling(AVCodecContext *avctx,
return 0;
}
+static void aom_svc_parse_int_array(int *dest, char *value, int
max_entries)
+{
+ int dest_idx = 0;
+ char *saveptr = NULL;
+ char *token = av_strtok(value, ",", &saveptr);
+
+ while (token && dest_idx < max_entries) {
+ dest[dest_idx++] = strtoul(token, NULL, 10);
+ token = av_strtok(NULL, ",", &saveptr);
+ }
+}
+
static av_cold int aom_init(AVCodecContext *avctx,
const struct aom_codec_iface *iface)
{
@@ -968,6 +1008,40 @@ static av_cold int aom_init(AVCodecContext *avctx,
if (ctx->enable_intrabc >= 0)
codecctl_int(avctx, AV1E_SET_ENABLE_INTRABC, ctx->enable_intrabc);
+ if (enccfg.rc_end_usage == AOM_CBR) {
+ aom_svc_params_t svc_params = {};
+ svc_params.framerate_factor[0] = 1;
+ svc_params.number_spatial_layers = 1;
+ svc_params.number_temporal_layers = 1;
+
+ const AVDictionaryEntry *en = NULL;
+ while ((en = av_dict_iterate(ctx->svc_parameters, en))) {
+ if (!strlen(en->value))
+ return AVERROR(EINVAL);
+
+ if (!strcmp(en->key, "number_spatial_layers"))
+ svc_params.number_spatial_layers = strtoul(en->value,
NULL, 10);
+ else if (!strcmp(en->key, "number_temporal_layers"))
+ svc_params.number_temporal_layers = strtoul(en->value,
NULL, 10);
+ else if (!strcmp(en->key, "max_quantizers"))
+ aom_svc_parse_int_array(svc_params.max_quantizers,
en->value, AOM_MAX_LAYERS);
+ else if (!strcmp(en->key, "min_quantizers"))
+ aom_svc_parse_int_array(svc_params.min_quantizers,
en->value, AOM_MAX_LAYERS);
+ else if (!strcmp(en->key, "scaling_factor_num"))
+ aom_svc_parse_int_array(svc_params.scaling_factor_num,
en->value, AOM_MAX_SS_LAYERS);
+ else if (!strcmp(en->key, "scaling_factor_den"))
+ aom_svc_parse_int_array(svc_params.scaling_factor_den,
en->value, AOM_MAX_SS_LAYERS);
+ else if (!strcmp(en->key, "layer_target_bitrate"))
+
aom_svc_parse_int_array(svc_params.layer_target_bitrate, en->value,
AOM_MAX_LAYERS);
+ else if (!strcmp(en->key, "framerate_factor"))
+ aom_svc_parse_int_array(svc_params.framerate_factor,
en->value, AOM_MAX_TS_LAYERS);
+ }
+
+ res = codecctl_svcp(avctx, AV1E_SET_SVC_PARAMS, &svc_params);
+ if (res < 0)
+ return res;
+ }
+
#if AOM_ENCODER_ABI_VERSION >= 23
{
const AVDictionaryEntry *en = NULL;
@@ -1517,6 +1591,7 @@ static const AVOption options[] = {
{ "enable-masked-comp", "Enable masked compound",
OFFSET(enable_masked_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
{ "enable-interintra-comp", "Enable interintra compound",
OFFSET(enable_interintra_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
{ "enable-smooth-interintra", "Enable smooth interintra mode",
OFFSET(enable_smooth_interintra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
+ { "svc-parameters", "SVC configuration using a :-separated list of
key=value parameters (only applied in CBR mode)",
OFFSET(svc_parameters), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE},
#if AOM_ENCODER_ABI_VERSION >= 23
{ "aom-params", "Set libaom options using a
:-separated list of key=value pairs", OFFSET(aom_params),
AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE },
#endif
--
2.34.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".
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH] Allow enabling SVC in libaomenc
2024-06-11 20:22 Chun-Min Chang
@ 2024-06-11 20:28 ` Chun-Min Chang
0 siblings, 0 replies; 6+ messages in thread
From: Chun-Min Chang @ 2024-06-11 20:28 UTC (permalink / raw)
To: ffmpeg-devel
It looks like the command
```
git format-patch -s -o "outputfolder" --add-header "X-Unsent: 1"
--suffix .eml --to ffmpeg-devel@ffmpeg.org -1 1a2b3c4d
```
doesn't work for me. I'll see if I can find another way to submit the patch.
On Tue, Jun 11, 2024 at 1:22 PM Chun-Min Chang <chun.m.chang@gmail.com>
wrote:
> This patch updates libaomenc.c to accept parameters for SVC (Scalable
> Video Coding) settings via the FFmpeg API `av_opt_set`. The SVC
> configuration is applied based on the provided parameters. As libaom's
> SVC functionality only operates with constant bitrate encoding [1],
> these parameters will only take effect when the bitrate is set to
> constant.
>
> [1]
>
> https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/encoder/svc_layercontext.h#115
>
> Signed-off-by: Chun-Min Chang <chun.m.chang@gmail.com>
> ---
> libavcodec/libaomenc.c | 75 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 75 insertions(+)
>
> diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
> index dec74ebecd..a8602a6b56 100644
> --- a/libavcodec/libaomenc.c
> +++ b/libavcodec/libaomenc.c
> @@ -30,6 +30,7 @@
> #include <aom/aomcx.h>
> #include "libavutil/avassert.h"
> +#include "libavutil/avstring.h"
> #include "libavutil/base64.h"
> #include "libavutil/common.h"
> #include "libavutil/cpu.h"
> @@ -137,6 +138,7 @@ typedef struct AOMEncoderContext {
> int enable_diff_wtd_comp;
> int enable_dist_wtd_comp;
> int enable_dual_filter;
> + AVDictionary *svc_parameters;
> AVDictionary *aom_params;
> } AOMContext;
> @@ -201,6 +203,7 @@ static const char *const ctlidstr[] = {
> [AV1E_GET_TARGET_SEQ_LEVEL_IDX] =
> "AV1E_GET_TARGET_SEQ_LEVEL_IDX",
> #endif
> [AV1_GET_NEW_FRAME_IMAGE] = "AV1_GET_NEW_FRAME_IMAGE",
> + [AV1E_SET_SVC_PARAMS] = "AV1E_SET_SVC_PARAMS",
> };
> static av_cold void log_encoder_error(AVCodecContext *avctx, const
> char *desc)
> @@ -382,6 +385,31 @@ static av_cold int codecctl_imgp(AVCodecContext
> *avctx,
> return 0;
> }
> +static av_cold int codecctl_svcp(AVCodecContext *avctx,
> +#ifdef UENUM1BYTE
> + aome_enc_control_id id,
> +#else
> + enum aome_enc_control_id id,
> +#endif
> + aom_svc_params_t *svc_params)
> +{
> + AOMContext *ctx = avctx->priv_data;
> + char buf[80];
> + int res;
> +
> + snprintf(buf, sizeof(buf), "%s:", ctlidstr[id]);
> +
> + res = aom_codec_control(&ctx->encoder, id, svc_params);
> + if (res != AOM_CODEC_OK) {
> + snprintf(buf, sizeof(buf), "Failed to get %s codec control",
> + ctlidstr[id]);
> + log_encoder_error(avctx, buf);
> + return AVERROR(EINVAL);
> + }
> +
> + return 0;
> +}
> +
> static av_cold int aom_free(AVCodecContext *avctx)
> {
> AOMContext *ctx = avctx->priv_data;
> @@ -673,6 +701,18 @@ static int choose_tiling(AVCodecContext *avctx,
> return 0;
> }
> +static void aom_svc_parse_int_array(int *dest, char *value, int
> max_entries)
> +{
> + int dest_idx = 0;
> + char *saveptr = NULL;
> + char *token = av_strtok(value, ",", &saveptr);
> +
> + while (token && dest_idx < max_entries) {
> + dest[dest_idx++] = strtoul(token, NULL, 10);
> + token = av_strtok(NULL, ",", &saveptr);
> + }
> +}
> +
> static av_cold int aom_init(AVCodecContext *avctx,
> const struct aom_codec_iface *iface)
> {
> @@ -968,6 +1008,40 @@ static av_cold int aom_init(AVCodecContext *avctx,
> if (ctx->enable_intrabc >= 0)
> codecctl_int(avctx, AV1E_SET_ENABLE_INTRABC,
> ctx->enable_intrabc);
> + if (enccfg.rc_end_usage == AOM_CBR) {
> + aom_svc_params_t svc_params = {};
> + svc_params.framerate_factor[0] = 1;
> + svc_params.number_spatial_layers = 1;
> + svc_params.number_temporal_layers = 1;
> +
> + const AVDictionaryEntry *en = NULL;
> + while ((en = av_dict_iterate(ctx->svc_parameters, en))) {
> + if (!strlen(en->value))
> + return AVERROR(EINVAL);
> +
> + if (!strcmp(en->key, "number_spatial_layers"))
> + svc_params.number_spatial_layers = strtoul(en->value,
> NULL, 10);
> + else if (!strcmp(en->key, "number_temporal_layers"))
> + svc_params.number_temporal_layers = strtoul(en->value,
> NULL, 10);
> + else if (!strcmp(en->key, "max_quantizers"))
> + aom_svc_parse_int_array(svc_params.max_quantizers,
> en->value, AOM_MAX_LAYERS);
> + else if (!strcmp(en->key, "min_quantizers"))
> + aom_svc_parse_int_array(svc_params.min_quantizers,
> en->value, AOM_MAX_LAYERS);
> + else if (!strcmp(en->key, "scaling_factor_num"))
> + aom_svc_parse_int_array(svc_params.scaling_factor_num,
> en->value, AOM_MAX_SS_LAYERS);
> + else if (!strcmp(en->key, "scaling_factor_den"))
> + aom_svc_parse_int_array(svc_params.scaling_factor_den,
> en->value, AOM_MAX_SS_LAYERS);
> + else if (!strcmp(en->key, "layer_target_bitrate"))
> +
> aom_svc_parse_int_array(svc_params.layer_target_bitrate, en->value,
> AOM_MAX_LAYERS);
> + else if (!strcmp(en->key, "framerate_factor"))
> + aom_svc_parse_int_array(svc_params.framerate_factor,
> en->value, AOM_MAX_TS_LAYERS);
> + }
> +
> + res = codecctl_svcp(avctx, AV1E_SET_SVC_PARAMS, &svc_params);
> + if (res < 0)
> + return res;
> + }
> +
> #if AOM_ENCODER_ABI_VERSION >= 23
> {
> const AVDictionaryEntry *en = NULL;
> @@ -1517,6 +1591,7 @@ static const AVOption options[] = {
> { "enable-masked-comp", "Enable masked compound",
> OFFSET(enable_masked_comp),
> AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
> { "enable-interintra-comp", "Enable interintra compound",
> OFFSET(enable_interintra_comp),
> AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
> { "enable-smooth-interintra", "Enable smooth interintra mode",
> OFFSET(enable_smooth_interintra),
> AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
> + { "svc-parameters", "SVC configuration using a :-separated list of
> key=value parameters (only applied in CBR mode)",
> OFFSET(svc_parameters), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE},
> #if AOM_ENCODER_ABI_VERSION >= 23
> { "aom-params", "Set libaom options using a
> :-separated list of key=value pairs", OFFSET(aom_params),
> AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE },
> #endif
> --
> 2.34.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".
^ permalink raw reply [flat|nested] 6+ messages in thread
* [FFmpeg-devel] [PATCH] Allow enabling SVC in libaomenc
@ 2024-06-05 21:34 Chun-Min Chang
2024-06-05 22:43 ` Michael Niedermayer
0 siblings, 1 reply; 6+ messages in thread
From: Chun-Min Chang @ 2024-06-05 21:34 UTC (permalink / raw)
To: ffmpeg-devel
This patch updates libaomenc.c to accept parameters for SVC (Scalable
Video Coding) settings via the FFmpeg API `av_opt_set`. The SVC
configuration is applied based on the provided parameters. As libaom's
SVC functionality only operates with constant bitrate encoding [1],
these parameters will only take effect when the bitrate is set to
constant.
[1]
https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/encoder/svc_layercontext.h#115
Signed-off-by: Chun-Min Chang <chun.m.chang@gmail.com>
---
libavcodec/libaomenc.c | 75 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index dec74ebecd..a8602a6b56 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -30,6 +30,7 @@
#include <aom/aomcx.h>
#include "libavutil/avassert.h"
+#include "libavutil/avstring.h"
#include "libavutil/base64.h"
#include "libavutil/common.h"
#include "libavutil/cpu.h"
@@ -137,6 +138,7 @@ typedef struct AOMEncoderContext {
int enable_diff_wtd_comp;
int enable_dist_wtd_comp;
int enable_dual_filter;
+ AVDictionary *svc_parameters;
AVDictionary *aom_params;
} AOMContext;
@@ -201,6 +203,7 @@ static const char *const ctlidstr[] = {
[AV1E_GET_TARGET_SEQ_LEVEL_IDX] = "AV1E_GET_TARGET_SEQ_LEVEL_IDX",
#endif
[AV1_GET_NEW_FRAME_IMAGE] = "AV1_GET_NEW_FRAME_IMAGE",
+ [AV1E_SET_SVC_PARAMS] = "AV1E_SET_SVC_PARAMS",
};
static av_cold void log_encoder_error(AVCodecContext *avctx, const
char *desc)
@@ -382,6 +385,31 @@ static av_cold int codecctl_imgp(AVCodecContext *avctx,
return 0;
}
+static av_cold int codecctl_svcp(AVCodecContext *avctx,
+#ifdef UENUM1BYTE
+ aome_enc_control_id id,
+#else
+ enum aome_enc_control_id id,
+#endif
+ aom_svc_params_t *svc_params)
+{
+ AOMContext *ctx = avctx->priv_data;
+ char buf[80];
+ int res;
+
+ snprintf(buf, sizeof(buf), "%s:", ctlidstr[id]);
+
+ res = aom_codec_control(&ctx->encoder, id, svc_params);
+ if (res != AOM_CODEC_OK) {
+ snprintf(buf, sizeof(buf), "Failed to get %s codec control",
+ ctlidstr[id]);
+ log_encoder_error(avctx, buf);
+ return AVERROR(EINVAL);
+ }
+
+ return 0;
+}
+
static av_cold int aom_free(AVCodecContext *avctx)
{
AOMContext *ctx = avctx->priv_data;
@@ -673,6 +701,18 @@ static int choose_tiling(AVCodecContext *avctx,
return 0;
}
+static void aom_svc_parse_int_array(int *dest, char *value, int
max_entries)
+{
+ int dest_idx = 0;
+ char *saveptr = NULL;
+ char *token = av_strtok(value, ",", &saveptr);
+
+ while (token && dest_idx < max_entries) {
+ dest[dest_idx++] = strtoul(token, NULL, 10);
+ token = av_strtok(NULL, ",", &saveptr);
+ }
+}
+
static av_cold int aom_init(AVCodecContext *avctx,
const struct aom_codec_iface *iface)
{
@@ -968,6 +1008,40 @@ static av_cold int aom_init(AVCodecContext *avctx,
if (ctx->enable_intrabc >= 0)
codecctl_int(avctx, AV1E_SET_ENABLE_INTRABC, ctx->enable_intrabc);
+ if (enccfg.rc_end_usage == AOM_CBR) {
+ aom_svc_params_t svc_params = {};
+ svc_params.framerate_factor[0] = 1;
+ svc_params.number_spatial_layers = 1;
+ svc_params.number_temporal_layers = 1;
+
+ const AVDictionaryEntry *en = NULL;
+ while ((en = av_dict_iterate(ctx->svc_parameters, en))) {
+ if (!strlen(en->value))
+ return AVERROR(EINVAL);
+
+ if (!strcmp(en->key, "number_spatial_layers"))
+ svc_params.number_spatial_layers = strtoul(en->value,
NULL, 10);
+ else if (!strcmp(en->key, "number_temporal_layers"))
+ svc_params.number_temporal_layers = strtoul(en->value,
NULL, 10);
+ else if (!strcmp(en->key, "max_quantizers"))
+ aom_svc_parse_int_array(svc_params.max_quantizers,
en->value, AOM_MAX_LAYERS);
+ else if (!strcmp(en->key, "min_quantizers"))
+ aom_svc_parse_int_array(svc_params.min_quantizers,
en->value, AOM_MAX_LAYERS);
+ else if (!strcmp(en->key, "scaling_factor_num"))
+ aom_svc_parse_int_array(svc_params.scaling_factor_num,
en->value, AOM_MAX_SS_LAYERS);
+ else if (!strcmp(en->key, "scaling_factor_den"))
+ aom_svc_parse_int_array(svc_params.scaling_factor_den,
en->value, AOM_MAX_SS_LAYERS);
+ else if (!strcmp(en->key, "layer_target_bitrate"))
+
aom_svc_parse_int_array(svc_params.layer_target_bitrate, en->value,
AOM_MAX_LAYERS);
+ else if (!strcmp(en->key, "framerate_factor"))
+ aom_svc_parse_int_array(svc_params.framerate_factor,
en->value, AOM_MAX_TS_LAYERS);
+ }
+
+ res = codecctl_svcp(avctx, AV1E_SET_SVC_PARAMS, &svc_params);
+ if (res < 0)
+ return res;
+ }
+
#if AOM_ENCODER_ABI_VERSION >= 23
{
const AVDictionaryEntry *en = NULL;
@@ -1517,6 +1591,7 @@ static const AVOption options[] = {
{ "enable-masked-comp", "Enable masked compound",
OFFSET(enable_masked_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
{ "enable-interintra-comp", "Enable interintra compound",
OFFSET(enable_interintra_comp),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
{ "enable-smooth-interintra", "Enable smooth interintra mode",
OFFSET(enable_smooth_interintra),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
+ { "svc-parameters", "SVC configuration using a :-separated list of
key=value parameters (only applied in CBR mode)",
OFFSET(svc_parameters), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE},
#if AOM_ENCODER_ABI_VERSION >= 23
{ "aom-params", "Set libaom options using a
:-separated list of key=value pairs", OFFSET(aom_params),
AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE },
#endif
--
2.34.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".
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH] Allow enabling SVC in libaomenc
2024-06-05 21:34 Chun-Min Chang
@ 2024-06-05 22:43 ` Michael Niedermayer
0 siblings, 0 replies; 6+ messages in thread
From: Michael Niedermayer @ 2024-06-05 22:43 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1148 bytes --]
On Wed, Jun 05, 2024 at 02:34:07PM -0700, Chun-Min Chang wrote:
> This patch updates libaomenc.c to accept parameters for SVC (Scalable
> Video Coding) settings via the FFmpeg API `av_opt_set`. The SVC
> configuration is applied based on the provided parameters. As libaom's
> SVC functionality only operates with constant bitrate encoding [1],
> these parameters will only take effect when the bitrate is set to
> constant.
>
> [1] https://aomedia.googlesource.com/aom/+/a7ef80c44bfb34b08254194b1ab72d4e93ff4b07/av1/encoder/svc_layercontext.h#115
>
> Signed-off-by: Chun-Min Chang <chun.m.chang@gmail.com>
> ---
> libavcodec/libaomenc.c | 75 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 75 insertions(+)
Applying: Allow enabling SVC in libaomenc
error: corrupt patch at line 16
error: could not build fake ancestor
Patch failed at 0001 Allow enabling SVC in libaomenc
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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".
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-06-25 8:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-24 18:50 [FFmpeg-devel] [PATCH] Allow enabling SVC in libaomenc Chun-Min Chang
2024-06-25 8:45 ` Anton Khirnov
-- strict thread matches above, loose matches on Subject: below --
2024-06-11 20:22 Chun-Min Chang
2024-06-11 20:28 ` Chun-Min Chang
2024-06-05 21:34 Chun-Min Chang
2024-06-05 22:43 ` Michael Niedermayer
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