[FFmpeg-devel] [PATCH v0 10/14] avcodec: add function for setting avctx side data
Jan Ekström
jeebjp at gmail.com
Tue Mar 21 01:34:04 EET 2023
---
libavcodec/avcodec.c | 30 ++++++++++++++++++++++++++++++
libavcodec/avcodec.h | 12 ++++++++++++
2 files changed, 42 insertions(+)
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 3faabe77d1..9ffff28d70 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -29,6 +29,7 @@
#include "libavutil/bprint.h"
#include "libavutil/channel_layout.h"
#include "libavutil/fifo.h"
+#include "libavutil/frame.h"
#include "libavutil/imgutils.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
@@ -719,3 +720,32 @@ int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr
return ff_decode_receive_frame(avctx, frame);
return ff_encode_receive_frame(avctx, frame);
}
+
+int avcodec_configure_side_data(AVCodecContext *avctx,
+ const AVFrameSideDataSet set)
+{
+ if (!avctx || !avctx->internal || !av_codec_is_encoder(avctx->codec))
+ return AVERROR(EINVAL);
+
+ {
+ AVCodecInternal *avci = avctx->internal;
+ AVFrameSideDataSet *dst = &avci->side_data_set;
+
+ for (int i = 0; i < set.nb_side_data; i++) {
+ const AVFrameSideData *sd_src = set.side_data[i];
+ AVFrameSideData *sd_dst =
+ av_new_side_data_to_set(dst, sd_src->type,
+ sd_src->size);
+ if (!sd_dst) {
+ av_side_data_set_wipe(dst);
+ return AVERROR(ENOMEM);
+ }
+
+ memcpy(sd_dst->data, sd_src->data, sd_src->size);
+
+ av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
+ }
+
+ return 0;
+ }
+}
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 30f1d312f4..8f535a0cc8 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3223,6 +3223,18 @@ void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size);
*/
int avcodec_is_open(AVCodecContext *s);
+/**
+ * Configure a side data set to an encoder AVCodecContext. With multiple
+ * calls new side data gets added in addition to the existing set of side data.
+ *
+ * @param avctx codec context to which to add side data
+ * @param set set of side data to add
+ *
+* @return negative error code on failure, >=0 on success.
+ */
+int avcodec_configure_side_data(AVCodecContext *avctx,
+ const AVFrameSideDataSet set);
+
/**
* @}
*/
--
2.39.2
More information about the ffmpeg-devel
mailing list