[FFmpeg-devel] [PATCH 5/7] avcodec/encode: add a new param change side data value that takes a dictionary
James Almer
jamrial at gmail.com
Wed Jan 22 04:54:01 EET 2025
Allow the caller to pass a dictionary with key/value pairs to set encoder
private options for reinitialization.
AVCodecContext global options are not affected. For that, specific
AVSideDataParamChangeFlags should be used, as is currently the case for
dimensions and sample rate.
Signed-off-by: James Almer <jamrial at gmail.com>
---
libavcodec/encode.c | 21 +++++++++++++++++++++
libavutil/defs.h | 1 +
2 files changed, 22 insertions(+)
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 187b4015f1..c14ab65509 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -20,12 +20,14 @@
#include "libavutil/attributes.h"
#include "libavutil/avassert.h"
+#include "libavutil/avstring.h"
#include "libavutil/channel_layout.h"
#include "libavutil/emms.h"
#include "libavutil/frame.h"
#include "libavutil/imgutils.h"
#include "libavutil/internal.h"
#include "libavutil/mem.h"
+#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/samplefmt.h"
@@ -101,6 +103,25 @@ static int apply_param_change(AVCodecContext *avctx, const AVFrame *frame)
avctx->width = frame->width;
avctx->height = frame->height;
}
+ if (flags & AV_SIDE_DATA_PARAM_CHANGE_DICT) {
+ AVDictionary *dict = NULL;
+ int left = av_strnlen(gbc.buffer, bytestream2_get_bytes_left(&gbc));
+ if (!left)
+ goto fail;
+ ret = av_dict_parse_string(&dict, gbc.buffer, "=", ":", 0);
+ if (ret < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid string");
+ goto fail2;
+ }
+ bytestream2_skip(&gbc, left + 1);
+
+ if (avctx->codec->priv_class) {
+ ret = av_opt_set_dict(avctx->priv_data, &dict);
+ if (ret < 0)
+ goto fail2;
+ }
+ av_dict_free(&dict);
+ }
if (flags) {
ret = 0;
diff --git a/libavutil/defs.h b/libavutil/defs.h
index f09fb5efd2..e1de680f2f 100644
--- a/libavutil/defs.h
+++ b/libavutil/defs.h
@@ -125,6 +125,7 @@ enum AVMediaType {
enum AVSideDataParamChangeFlags {
AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE = 0x0004,
AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS = 0x0008,
+ AV_SIDE_DATA_PARAM_CHANGE_DICT = 0x0016,
};
/**
--
2.48.1
More information about the ffmpeg-devel
mailing list