* [FFmpeg-devel] [PATCH v1 00/12] encoder AVCodecContext configuration side data
@ 2023-03-31 16:21 Jan Ekström
2023-03-31 16:21 ` [FFmpeg-devel] [PATCH v1 01/12] avutil/frame: add AVFrameSideDataSet for passing sets of " Jan Ekström
` (11 more replies)
0 siblings, 12 replies; 13+ messages in thread
From: Jan Ekström @ 2023-03-31 16:21 UTC (permalink / raw)
To: ffmpeg-devel
Differences to v0:
1. side data set structure moved to public AVCodecContext itself
2. set extension helper renamed to av_extend_side_data_set
3. avutil/frame.c cleanup patch removed as it was applied to master
This patch set I've now been working for a while since I felt like it was weird
we couldn't pass through information such as static HDR metadata to encoders
from decoded input. This initial version adds the necessary framework, as well
as adds static HDR metadata support for libsvtav1, libx264 as well as libx265
wrappers.
An alternative to this would be to make encoders only properly initialize when
they receive the first AVFrame, but that seems to be a bigger, nastier change
than introducing an AVFrameSideDataSet in avctx as everything seems to
presume that extradata etc are available after opening the encoder.
Jan
Jan Ekström (12):
avutil/frame: add AVFrameSideDataSet for passing sets of side data
avutil/frame: split side data list wiping out to non-AVFrame function
avutil/frame: add helper for clearing out side data sets
avutil/frame: split side_data_from_buf to base and AVFrame func
avutil/frame: add helper for adding side data to set
avutil/frame: add helper for getting side data from set
avutil/frame: add helper for extending a set of side data
avcodec: add private side data set to AVCodecContext
ffmpeg: pass first video AVFrame's side data to encoder
avcodec/libsvtav1: add support for writing out CLL and MDCV
avcodec/libx264: add support for writing out CLL and MDCV
avcodec/libx265: add support for writing out CLL and MDCV
fftools/ffmpeg.c | 12 +++++
libavcodec/avcodec.h | 7 +++
libavcodec/libsvtav1.c | 70 ++++++++++++++++++++++++++
libavcodec/libx264.c | 79 +++++++++++++++++++++++++++++
libavcodec/libx265.c | 82 ++++++++++++++++++++++++++++++
libavcodec/options.c | 1 +
libavutil/frame.c | 112 +++++++++++++++++++++++++++++++++--------
libavutil/frame.h | 49 ++++++++++++++++++
8 files changed, 391 insertions(+), 21 deletions(-)
--
2.39.2
_______________________________________________
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] 13+ messages in thread
* [FFmpeg-devel] [PATCH v1 01/12] avutil/frame: add AVFrameSideDataSet for passing sets of side data
2023-03-31 16:21 [FFmpeg-devel] [PATCH v1 00/12] encoder AVCodecContext configuration side data Jan Ekström
@ 2023-03-31 16:21 ` Jan Ekström
2023-03-31 16:21 ` [FFmpeg-devel] [PATCH v1 02/12] avutil/frame: split side data list wiping out to non-AVFrame function Jan Ekström
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Jan Ekström @ 2023-03-31 16:21 UTC (permalink / raw)
To: ffmpeg-devel
---
libavutil/frame.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 5b58c14ac3..45024c2a03 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -241,6 +241,14 @@ typedef struct AVFrameSideData {
AVBufferRef *buf;
} AVFrameSideData;
+/**
+ * Structure to hold a set of AVFrameSideData
+ */
+typedef struct AVFrameSideDataSet {
+ AVFrameSideData **side_data;
+ int nb_side_data;
+} AVFrameSideDataSet;
+
/**
* Structure describing a single Region Of Interest.
*
--
2.39.2
_______________________________________________
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] 13+ messages in thread
* [FFmpeg-devel] [PATCH v1 02/12] avutil/frame: split side data list wiping out to non-AVFrame function
2023-03-31 16:21 [FFmpeg-devel] [PATCH v1 00/12] encoder AVCodecContext configuration side data Jan Ekström
2023-03-31 16:21 ` [FFmpeg-devel] [PATCH v1 01/12] avutil/frame: add AVFrameSideDataSet for passing sets of " Jan Ekström
@ 2023-03-31 16:21 ` Jan Ekström
2023-03-31 16:21 ` [FFmpeg-devel] [PATCH v1 03/12] avutil/frame: add helper for clearing out side data sets Jan Ekström
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Jan Ekström @ 2023-03-31 16:21 UTC (permalink / raw)
To: ffmpeg-devel
---
libavutil/frame.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/libavutil/frame.c b/libavutil/frame.c
index c905e8d611..019613e4d2 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -76,14 +76,18 @@ static void free_side_data(AVFrameSideData **ptr_sd)
av_freep(ptr_sd);
}
-static void wipe_side_data(AVFrame *frame)
+static void wipe_side_data(AVFrameSideData ***sd, int *nb_side_data)
{
- for (int i = 0; i < frame->nb_side_data; i++) {
- free_side_data(&frame->side_data[i]);
+ for (int i = 0; i < *nb_side_data; i++) {
+ free_side_data(&((*sd)[i]));
}
- frame->nb_side_data = 0;
+ *nb_side_data = 0;
+
+ av_freep(sd);
+}
- av_freep(&frame->side_data);
+static void wipe_side_data_from_frame(AVFrame *frame) {
+ wipe_side_data(&frame->side_data, &frame->nb_side_data);
}
AVFrame *av_frame_alloc(void)
@@ -326,7 +330,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
sd_dst = av_frame_new_side_data(dst, sd_src->type,
sd_src->size);
if (!sd_dst) {
- wipe_side_data(dst);
+ wipe_side_data_from_frame(dst);
return AVERROR(ENOMEM);
}
memcpy(sd_dst->data, sd_src->data, sd_src->size);
@@ -335,7 +339,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref);
if (!sd_dst) {
av_buffer_unref(&ref);
- wipe_side_data(dst);
+ wipe_side_data_from_frame(dst);
return AVERROR(ENOMEM);
}
}
@@ -486,7 +490,7 @@ void av_frame_unref(AVFrame *frame)
if (!frame)
return;
- wipe_side_data(frame);
+ wipe_side_data_from_frame(frame);
for (int i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
av_buffer_unref(&frame->buf[i]);
--
2.39.2
_______________________________________________
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] 13+ messages in thread
* [FFmpeg-devel] [PATCH v1 03/12] avutil/frame: add helper for clearing out side data sets
2023-03-31 16:21 [FFmpeg-devel] [PATCH v1 00/12] encoder AVCodecContext configuration side data Jan Ekström
2023-03-31 16:21 ` [FFmpeg-devel] [PATCH v1 01/12] avutil/frame: add AVFrameSideDataSet for passing sets of " Jan Ekström
2023-03-31 16:21 ` [FFmpeg-devel] [PATCH v1 02/12] avutil/frame: split side data list wiping out to non-AVFrame function Jan Ekström
@ 2023-03-31 16:21 ` Jan Ekström
2023-03-31 16:21 ` [FFmpeg-devel] [PATCH v1 04/12] avutil/frame: split side_data_from_buf to base and AVFrame func Jan Ekström
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Jan Ekström @ 2023-03-31 16:21 UTC (permalink / raw)
To: ffmpeg-devel
---
libavutil/frame.c | 5 +++++
libavutil/frame.h | 7 +++++++
2 files changed, 12 insertions(+)
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 019613e4d2..24038cc0fa 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -90,6 +90,11 @@ static void wipe_side_data_from_frame(AVFrame *frame) {
wipe_side_data(&frame->side_data, &frame->nb_side_data);
}
+void av_side_data_set_wipe(AVFrameSideDataSet *set)
+{
+ wipe_side_data(&set->side_data, &set->nb_side_data);
+}
+
AVFrame *av_frame_alloc(void)
{
AVFrame *frame = av_malloc(sizeof(*frame));
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 45024c2a03..734ac3fe75 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -991,6 +991,13 @@ int av_frame_apply_cropping(AVFrame *frame, int flags);
*/
const char *av_frame_side_data_name(enum AVFrameSideDataType type);
+/**
+ * Clear all side data from a side data set
+ *
+ * @param set the set which should be cleared
+ */
+void av_side_data_set_wipe(AVFrameSideDataSet *set);
+
/**
* @}
*/
--
2.39.2
_______________________________________________
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] 13+ messages in thread
* [FFmpeg-devel] [PATCH v1 04/12] avutil/frame: split side_data_from_buf to base and AVFrame func
2023-03-31 16:21 [FFmpeg-devel] [PATCH v1 00/12] encoder AVCodecContext configuration side data Jan Ekström
` (2 preceding siblings ...)
2023-03-31 16:21 ` [FFmpeg-devel] [PATCH v1 03/12] avutil/frame: add helper for clearing out side data sets Jan Ekström
@ 2023-03-31 16:21 ` Jan Ekström
2023-03-31 16:21 ` [FFmpeg-devel] [PATCH v1 05/12] avutil/frame: add helper for adding side data to set Jan Ekström
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Jan Ekström @ 2023-03-31 16:21 UTC (permalink / raw)
To: ffmpeg-devel
---
libavutil/frame.c | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 24038cc0fa..ab1a4e7f6a 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -648,23 +648,23 @@ FF_ENABLE_DEPRECATION_WARNINGS
return NULL;
}
-AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame,
- enum AVFrameSideDataType type,
- AVBufferRef *buf)
+static AVFrameSideData *add_side_data_to_set_from_buf(AVFrameSideDataSet *set,
+ enum AVFrameSideDataType type,
+ AVBufferRef *buf)
{
AVFrameSideData *ret, **tmp;
if (!buf)
return NULL;
- if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
+ if (set->nb_side_data > INT_MAX / sizeof(*set->side_data) - 1)
return NULL;
- tmp = av_realloc(frame->side_data,
- (frame->nb_side_data + 1) * sizeof(*frame->side_data));
+ tmp = av_realloc(set->side_data,
+ (set->nb_side_data + 1) * sizeof(*set->side_data));
if (!tmp)
return NULL;
- frame->side_data = tmp;
+ set->side_data = tmp;
ret = av_mallocz(sizeof(*ret));
if (!ret)
@@ -675,7 +675,23 @@ AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame,
ret->size = buf->size;
ret->type = type;
- frame->side_data[frame->nb_side_data++] = ret;
+ set->side_data[set->nb_side_data++] = ret;
+
+ return ret;
+}
+
+AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame,
+ enum AVFrameSideDataType type,
+ AVBufferRef *buf)
+{
+ AVFrameSideDataSet set = {
+ .side_data = frame->side_data,
+ .nb_side_data = frame->nb_side_data,
+ };
+ AVFrameSideData *ret = add_side_data_to_set_from_buf(&set, type, buf);
+
+ frame->side_data = set.side_data;
+ frame->nb_side_data = set.nb_side_data;
return ret;
}
--
2.39.2
_______________________________________________
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] 13+ messages in thread
* [FFmpeg-devel] [PATCH v1 05/12] avutil/frame: add helper for adding side data to set
2023-03-31 16:21 [FFmpeg-devel] [PATCH v1 00/12] encoder AVCodecContext configuration side data Jan Ekström
` (3 preceding siblings ...)
2023-03-31 16:21 ` [FFmpeg-devel] [PATCH v1 04/12] avutil/frame: split side_data_from_buf to base and AVFrame func Jan Ekström
@ 2023-03-31 16:21 ` Jan Ekström
2023-03-31 16:21 ` [FFmpeg-devel] [PATCH v1 06/12] avutil/frame: add helper for getting side data from set Jan Ekström
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Jan Ekström @ 2023-03-31 16:21 UTC (permalink / raw)
To: ffmpeg-devel
---
libavutil/frame.c | 12 ++++++++++++
libavutil/frame.h | 13 +++++++++++++
2 files changed, 25 insertions(+)
diff --git a/libavutil/frame.c b/libavutil/frame.c
index ab1a4e7f6a..29e9b631f8 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -708,6 +708,18 @@ AVFrameSideData *av_frame_new_side_data(AVFrame *frame,
return ret;
}
+
+AVFrameSideData *av_new_side_data_to_set(AVFrameSideDataSet *set,
+ enum AVFrameSideDataType type,
+ size_t size)
+{
+ AVBufferRef *buf = av_buffer_alloc(size);
+ AVFrameSideData *ret = add_side_data_to_set_from_buf(set, type, buf);
+ if (!ret)
+ av_buffer_unref(&buf);
+ return ret;
+}
+
AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
enum AVFrameSideDataType type)
{
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 734ac3fe75..167a8f0ff6 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -998,6 +998,19 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type);
*/
void av_side_data_set_wipe(AVFrameSideDataSet *set);
+/**
+ * Add a new side data entry to a set.
+ *
+ * @param set a set to which the side data should be added
+ * @param type type of the added side data
+ * @param size size of the side data
+ *
+ * @return newly added side data on success, NULL on error
+ */
+AVFrameSideData *av_new_side_data_to_set(AVFrameSideDataSet *set,
+ enum AVFrameSideDataType type,
+ size_t size);
+
/**
* @}
*/
--
2.39.2
_______________________________________________
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] 13+ messages in thread
* [FFmpeg-devel] [PATCH v1 06/12] avutil/frame: add helper for getting side data from set
2023-03-31 16:21 [FFmpeg-devel] [PATCH v1 00/12] encoder AVCodecContext configuration side data Jan Ekström
` (4 preceding siblings ...)
2023-03-31 16:21 ` [FFmpeg-devel] [PATCH v1 05/12] avutil/frame: add helper for adding side data to set Jan Ekström
@ 2023-03-31 16:21 ` Jan Ekström
2023-03-31 16:22 ` [FFmpeg-devel] [PATCH v1 07/12] avutil/frame: add helper for extending a set of side data Jan Ekström
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Jan Ekström @ 2023-03-31 16:21 UTC (permalink / raw)
To: ffmpeg-devel
---
libavutil/frame.c | 22 +++++++++++++++++-----
libavutil/frame.h | 10 ++++++++++
2 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 29e9b631f8..3386cda627 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -720,16 +720,28 @@ AVFrameSideData *av_new_side_data_to_set(AVFrameSideDataSet *set,
return ret;
}
-AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
- enum AVFrameSideDataType type)
+AVFrameSideData *av_get_side_data_from_set(const AVFrameSideDataSet set,
+ enum AVFrameSideDataType type)
{
- for (int i = 0; i < frame->nb_side_data; i++) {
- if (frame->side_data[i]->type == type)
- return frame->side_data[i];
+ for (int i = 0; i < set.nb_side_data; i++) {
+ if (set.side_data[i]->type == type)
+ return set.side_data[i];
}
return NULL;
}
+AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
+ enum AVFrameSideDataType type)
+{
+ return av_get_side_data_from_set(
+ (const AVFrameSideDataSet){
+ .side_data = frame->side_data,
+ .nb_side_data = frame->nb_side_data
+ },
+ type
+ );
+}
+
static int frame_copy_video(AVFrame *dst, const AVFrame *src)
{
const uint8_t *src_data[4];
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 167a8f0ff6..8aa50e3ad8 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1011,6 +1011,16 @@ AVFrameSideData *av_new_side_data_to_set(AVFrameSideDataSet *set,
enum AVFrameSideDataType type,
size_t size);
+/**
+ * @param set a set to which the side data should be added
+ * @param type type of the added side data
+ *
+ * @return a pointer to the side data of a given type on success, NULL if there
+ * is no side data with such type in this set.
+ */
+AVFrameSideData *av_get_side_data_from_set(const AVFrameSideDataSet set,
+ enum AVFrameSideDataType type);
+
/**
* @}
*/
--
2.39.2
_______________________________________________
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] 13+ messages in thread
* [FFmpeg-devel] [PATCH v1 07/12] avutil/frame: add helper for extending a set of side data
2023-03-31 16:21 [FFmpeg-devel] [PATCH v1 00/12] encoder AVCodecContext configuration side data Jan Ekström
` (5 preceding siblings ...)
2023-03-31 16:21 ` [FFmpeg-devel] [PATCH v1 06/12] avutil/frame: add helper for getting side data from set Jan Ekström
@ 2023-03-31 16:22 ` Jan Ekström
2023-03-31 16:22 ` [FFmpeg-devel] [PATCH v1 08/12] avcodec: add private side data set to AVCodecContext Jan Ekström
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Jan Ekström @ 2023-03-31 16:22 UTC (permalink / raw)
To: ffmpeg-devel
---
libavutil/frame.c | 21 +++++++++++++++++++++
libavutil/frame.h | 11 +++++++++++
2 files changed, 32 insertions(+)
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 3386cda627..ec4e44a11f 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -720,6 +720,27 @@ AVFrameSideData *av_new_side_data_to_set(AVFrameSideDataSet *set,
return ret;
}
+int av_extend_side_data_set(AVFrameSideDataSet *dst,
+ const AVFrameSideDataSet src)
+{
+ for (int i = 0; i < src.nb_side_data; i++) {
+ const AVFrameSideData *sd_src = src.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;
+}
+
AVFrameSideData *av_get_side_data_from_set(const AVFrameSideDataSet set,
enum AVFrameSideDataType type)
{
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 8aa50e3ad8..da8ac3237b 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1011,6 +1011,17 @@ AVFrameSideData *av_new_side_data_to_set(AVFrameSideDataSet *set,
enum AVFrameSideDataType type,
size_t size);
+/**
+ * Add multiple side data entries to a set in one go.
+ *
+ * @param dst a set to which the side data should be added
+ * @param src a set from which the side data should be copied from
+ *
+ * @return negative error code on failure, >=0 on success.
+ */
+int av_extend_side_data_set(AVFrameSideDataSet *dst,
+ const AVFrameSideDataSet src);
+
/**
* @param set a set to which the side data should be added
* @param type type of the added side data
--
2.39.2
_______________________________________________
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] 13+ messages in thread
* [FFmpeg-devel] [PATCH v1 08/12] avcodec: add private side data set to AVCodecContext
2023-03-31 16:21 [FFmpeg-devel] [PATCH v1 00/12] encoder AVCodecContext configuration side data Jan Ekström
` (6 preceding siblings ...)
2023-03-31 16:22 ` [FFmpeg-devel] [PATCH v1 07/12] avutil/frame: add helper for extending a set of side data Jan Ekström
@ 2023-03-31 16:22 ` Jan Ekström
2023-03-31 16:22 ` [FFmpeg-devel] [PATCH v1 09/12] ffmpeg: pass first video AVFrame's side data to encoder Jan Ekström
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Jan Ekström @ 2023-03-31 16:22 UTC (permalink / raw)
To: ffmpeg-devel
This allows configuring an encoder by using AVFrameSideData.
---
libavcodec/avcodec.h | 7 +++++++
libavcodec/options.c | 1 +
2 files changed, 8 insertions(+)
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 18ca0e2494..0ba0c390c4 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2084,6 +2084,13 @@ typedef struct AVCodecContext {
* an error.
*/
int64_t frame_num;
+
+ /**
+ * Set containing static side data, such as HDR10 CLL / MDCV structures.
+ * - encoding: set by user
+ * - decoding: unused
+ */
+ AVFrameSideDataSet side_data_set;
} AVCodecContext;
/**
diff --git a/libavcodec/options.c b/libavcodec/options.c
index a9b35ee1c3..b7ea6b6ab5 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -180,6 +180,7 @@ void avcodec_free_context(AVCodecContext **pavctx)
av_freep(&avctx->inter_matrix);
av_freep(&avctx->rc_override);
av_channel_layout_uninit(&avctx->ch_layout);
+ av_side_data_set_wipe(&avctx->side_data_set);
av_freep(pavctx);
}
--
2.39.2
_______________________________________________
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] 13+ messages in thread
* [FFmpeg-devel] [PATCH v1 09/12] ffmpeg: pass first video AVFrame's side data to encoder
2023-03-31 16:21 [FFmpeg-devel] [PATCH v1 00/12] encoder AVCodecContext configuration side data Jan Ekström
` (7 preceding siblings ...)
2023-03-31 16:22 ` [FFmpeg-devel] [PATCH v1 08/12] avcodec: add private side data set to AVCodecContext Jan Ekström
@ 2023-03-31 16:22 ` Jan Ekström
2023-03-31 16:22 ` [FFmpeg-devel] [PATCH v1 10/12] avcodec/libsvtav1: add support for writing out CLL and MDCV Jan Ekström
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Jan Ekström @ 2023-03-31 16:22 UTC (permalink / raw)
To: ffmpeg-devel
This enables further configuration of output based on the results
of input decoding and filtering in a similar manner as the color
information.
---
fftools/ffmpeg.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 438bee8fef..c26dd1ad0c 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3118,11 +3118,23 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame)
av_pix_fmt_desc_get(enc_ctx->pix_fmt)->comp[0].depth);
if (frame) {
+ int ret = AVERROR_BUG;
+
enc_ctx->color_range = frame->color_range;
enc_ctx->color_primaries = frame->color_primaries;
enc_ctx->color_trc = frame->color_trc;
enc_ctx->colorspace = frame->colorspace;
enc_ctx->chroma_sample_location = frame->chroma_location;
+
+ if ((ret = av_extend_side_data_set(&enc_ctx->side_data_set,
+ (const AVFrameSideDataSet){
+ .side_data = frame->side_data,
+ .nb_side_data = frame->nb_side_data
+ })) < 0) {
+ av_log(NULL, AV_LOG_ERROR, "failed to configure video encoder: %s!\n",
+ av_err2str(ret));
+ return ret;
+ }
}
enc_ctx->framerate = ost->frame_rate;
--
2.39.2
_______________________________________________
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] 13+ messages in thread
* [FFmpeg-devel] [PATCH v1 10/12] avcodec/libsvtav1: add support for writing out CLL and MDCV
2023-03-31 16:21 [FFmpeg-devel] [PATCH v1 00/12] encoder AVCodecContext configuration side data Jan Ekström
` (8 preceding siblings ...)
2023-03-31 16:22 ` [FFmpeg-devel] [PATCH v1 09/12] ffmpeg: pass first video AVFrame's side data to encoder Jan Ekström
@ 2023-03-31 16:22 ` Jan Ekström
2023-03-31 16:22 ` [FFmpeg-devel] [PATCH v1 11/12] avcodec/libx264: " Jan Ekström
2023-03-31 16:22 ` [FFmpeg-devel] [PATCH v1 12/12] avcodec/libx265: " Jan Ekström
11 siblings, 0 replies; 13+ messages in thread
From: Jan Ekström @ 2023-03-31 16:22 UTC (permalink / raw)
To: ffmpeg-devel
These two were added in 28e23d7f348c78d49a726c7469f9d4e38edec341
and 3558c1f2e97455e0b89edef31b9a72ab7fa30550 for version 0.9.0 of
SVT-AV1, which is also our minimum requirement right now.
In other words, no additional version limiting conditions seem
to be required.
---
libavcodec/libsvtav1.c | 70 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
index 9174e2753c..1bbda0b705 100644
--- a/libavcodec/libsvtav1.c
+++ b/libavcodec/libsvtav1.c
@@ -24,9 +24,11 @@
#include <EbSvtAv1ErrorCodes.h>
#include <EbSvtAv1Enc.h>
+#include "libavutil/bswap.h"
#include "libavutil/common.h"
#include "libavutil/frame.h"
#include "libavutil/imgutils.h"
+#include "libavutil/mastering_display_metadata.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/avassert.h"
@@ -146,6 +148,72 @@ static int alloc_buffer(EbSvtAv1EncConfiguration *config, SvtContext *svt_enc)
}
+static void handle_mdcv(struct EbSvtAv1MasteringDisplayInfo *dst,
+ const AVMasteringDisplayMetadata *mdcv)
+{
+ struct EbSvtAv1ChromaPoints *points[] = {
+ &dst->r,
+ &dst->g,
+ &dst->b,
+ };
+
+ if (!mdcv->has_primaries)
+ goto skip_primaries;
+
+ for (int i = 0; i < 3; i++) {
+ struct EbSvtAv1ChromaPoints *dst = points[i];
+ const AVRational *src = mdcv->display_primaries[i];
+
+ dst->x =
+ AV_BSWAP16C(av_rescale_q(1, src[0],
+ (AVRational){ 1, (1 << 16) }));
+ dst->y =
+ AV_BSWAP16C(av_rescale_q(1, src[1],
+ (AVRational){ 1, (1 << 16) }));
+ }
+
+ dst->white_point.x =
+ AV_BSWAP16C(av_rescale_q(1, mdcv->white_point[0],
+ (AVRational){ 1, (1 << 16) }));
+ dst->white_point.y =
+ AV_BSWAP16C(av_rescale_q(1, mdcv->white_point[1],
+ (AVRational){ 1, (1 << 16) }));
+
+skip_primaries:
+ if (!mdcv->has_luminance)
+ return;
+
+ dst->max_luma =
+ AV_BSWAP32C(av_rescale_q(1, mdcv->max_luminance,
+ (AVRational){ 1, (1 << 8) }));
+ dst->min_luma =
+ AV_BSWAP32C(av_rescale_q(1, mdcv->min_luminance,
+ (AVRational){ 1, (1 << 14) }));
+}
+
+static void handle_side_data(AVCodecContext *avctx,
+ EbSvtAv1EncConfiguration *param)
+{
+ const AVFrameSideDataSet set = avctx->side_data_set;
+ const AVFrameSideData *cll_sd =
+ av_get_side_data_from_set(set, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
+ const AVFrameSideData *mdcv_sd =
+ av_get_side_data_from_set(set, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
+
+ if (cll_sd) {
+ const AVContentLightMetadata *cll =
+ (AVContentLightMetadata *)cll_sd->data;
+
+ param->content_light_level.max_cll = AV_BSWAP16C(cll->MaxCLL);
+ param->content_light_level.max_fall = AV_BSWAP16C(cll->MaxFALL);
+ }
+
+ if (mdcv_sd) {
+ handle_mdcv(¶m->mastering_display,
+ (AVMasteringDisplayMetadata *)mdcv_sd->data);
+ }
+}
+
static int config_enc_params(EbSvtAv1EncConfiguration *param,
AVCodecContext *avctx)
{
@@ -256,6 +324,8 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param,
/* 2 = IDR, closed GOP, 1 = CRA, open GOP */
param->intra_refresh_type = avctx->flags & AV_CODEC_FLAG_CLOSED_GOP ? 2 : 1;
+ handle_side_data(avctx, param);
+
#if SVT_AV1_CHECK_VERSION(0, 9, 1)
while ((en = av_dict_get(svt_enc->svtav1_opts, "", en, AV_DICT_IGNORE_SUFFIX))) {
EbErrorType ret = svt_av1_enc_parse_parameter(param, en->key, en->value);
--
2.39.2
_______________________________________________
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] 13+ messages in thread
* [FFmpeg-devel] [PATCH v1 11/12] avcodec/libx264: add support for writing out CLL and MDCV
2023-03-31 16:21 [FFmpeg-devel] [PATCH v1 00/12] encoder AVCodecContext configuration side data Jan Ekström
` (9 preceding siblings ...)
2023-03-31 16:22 ` [FFmpeg-devel] [PATCH v1 10/12] avcodec/libsvtav1: add support for writing out CLL and MDCV Jan Ekström
@ 2023-03-31 16:22 ` Jan Ekström
2023-03-31 16:22 ` [FFmpeg-devel] [PATCH v1 12/12] avcodec/libx265: " Jan Ekström
11 siblings, 0 replies; 13+ messages in thread
From: Jan Ekström @ 2023-03-31 16:22 UTC (permalink / raw)
To: ffmpeg-devel
Both of these two structures were first available with X264_BUILD
163, so make relevant functionality conditional on the version
being at least such.
Keep handle_side_data available in all cases as this way X264_init
does not require additional version based conditions within it.
---
libavcodec/libx264.c | 79 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 92828fabc3..f841c66227 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -25,6 +25,7 @@
#include "libavutil/eval.h"
#include "libavutil/internal.h"
#include "libavutil/opt.h"
+#include "libavutil/mastering_display_metadata.h"
#include "libavutil/mem.h"
#include "libavutil/pixdesc.h"
#include "libavutil/stereo3d.h"
@@ -737,6 +738,82 @@ static int convert_pix_fmt(enum AVPixelFormat pix_fmt)
return AVERROR(EINVAL);\
}
+#if X264_BUILD >= 163
+static void handle_mdcv(x264_param_t *params,
+ const AVMasteringDisplayMetadata *mdcv)
+{
+ int *points[][2] = {
+ {
+ ¶ms->mastering_display.i_red_x,
+ ¶ms->mastering_display.i_red_y
+ },
+ {
+ ¶ms->mastering_display.i_green_x,
+ ¶ms->mastering_display.i_green_y
+ },
+ {
+ ¶ms->mastering_display.i_blue_x,
+ ¶ms->mastering_display.i_blue_y
+ },
+ };
+
+ if (!mdcv->has_primaries && !mdcv->has_luminance)
+ return;
+
+ params->mastering_display.b_mastering_display = 1;
+
+ if (!mdcv->has_primaries)
+ goto skip_primaries;
+
+ for (int i = 0; i < 3; i++) {
+ const AVRational *src = mdcv->display_primaries[i];
+ int *dst[2] = { points[i][0], points[i][1] };
+
+ *dst[0] = av_rescale_q(1, src[0], (AVRational){ 1, 50000 });
+ *dst[1] = av_rescale_q(1, src[1], (AVRational){ 1, 50000 });
+ }
+
+ params->mastering_display.i_white_x =
+ av_rescale_q(1, mdcv->white_point[0], (AVRational){ 1, 50000 });
+ params->mastering_display.i_white_y =
+ av_rescale_q(1, mdcv->white_point[1], (AVRational){ 1, 50000 });
+
+skip_primaries:
+ if (!mdcv->has_luminance)
+ return;
+
+ params->mastering_display.i_display_max =
+ av_rescale_q(1, mdcv->max_luminance, (AVRational){ 1, 10000 });
+ params->mastering_display.i_display_min =
+ av_rescale_q(1, mdcv->min_luminance, (AVRational){ 1, 10000 });
+}
+#endif // X264_BUILD >= 163
+
+static void handle_side_data(AVCodecContext *avctx, x264_param_t *params)
+{
+#if X264_BUILD >= 163
+ const AVFrameSideDataSet set = avctx->side_data_set;
+ const AVFrameSideData *cll_sd =
+ av_get_side_data_from_set(set, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
+ const AVFrameSideData *mdcv_sd =
+ av_get_side_data_from_set(set, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
+
+ if (cll_sd) {
+ const AVContentLightMetadata *cll =
+ (AVContentLightMetadata *)cll_sd->data;
+
+ params->content_light_level.i_max_cll = cll->MaxCLL;
+ params->content_light_level.i_max_fall = cll->MaxFALL;
+
+ params->content_light_level.b_cll = 1;
+ }
+
+ if (mdcv_sd) {
+ handle_mdcv(params, (AVMasteringDisplayMetadata *)mdcv_sd->data);
+ }
+#endif // X264_BUILD >= 163
+}
+
static av_cold int X264_init(AVCodecContext *avctx)
{
X264Context *x4 = avctx->priv_data;
@@ -1031,6 +1108,8 @@ static av_cold int X264_init(AVCodecContext *avctx)
if (avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED)
x4->params.vui.i_chroma_loc = avctx->chroma_sample_location - 1;
+ handle_side_data(avctx, &x4->params);
+
if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)
x4->params.b_repeat_headers = 0;
--
2.39.2
_______________________________________________
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] 13+ messages in thread
* [FFmpeg-devel] [PATCH v1 12/12] avcodec/libx265: add support for writing out CLL and MDCV
2023-03-31 16:21 [FFmpeg-devel] [PATCH v1 00/12] encoder AVCodecContext configuration side data Jan Ekström
` (10 preceding siblings ...)
2023-03-31 16:22 ` [FFmpeg-devel] [PATCH v1 11/12] avcodec/libx264: " Jan Ekström
@ 2023-03-31 16:22 ` Jan Ekström
11 siblings, 0 replies; 13+ messages in thread
From: Jan Ekström @ 2023-03-31 16:22 UTC (permalink / raw)
To: ffmpeg-devel
The newer of these two are the separate integers for content light
level, introduced in 3952bf3e98c76c31594529a3fe34e056d3e3e2ea ,
with X265_BUILD 75. As we already require X265_BUILD of at least
89, no further conditions are required.
---
libavcodec/libx265.c | 82 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 82 insertions(+)
diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 420d0953af..4378c04996 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -28,9 +28,11 @@
#include <float.h>
#include "libavutil/avassert.h"
+#include "libavutil/bprint.h"
#include "libavutil/buffer.h"
#include "libavutil/internal.h"
#include "libavutil/common.h"
+#include "libavutil/mastering_display_metadata.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avcodec.h"
@@ -179,6 +181,79 @@ static av_cold int libx265_param_parse_int(AVCodecContext *avctx,
return 0;
}
+static int handle_mdcv(AVCodecContext *avctx, const x265_api *api,
+ x265_param *params,
+ const AVMasteringDisplayMetadata *mdcv)
+{
+ int ret = AVERROR_BUG;
+ static const char *option = "master-display";
+ AVBPrint buf;
+ av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
+
+ // G(%hu,%hu)B(%hu,%hu)R(%hu,%hu)WP(%hu,%hu)L(%u,%u)
+ av_bprintf(
+ &buf,
+ "G(%"PRId64",%"PRId64")B(%"PRId64",%"PRId64")R(%"PRId64",%"PRId64")"
+ "WP(%"PRId64",%"PRId64")L(%"PRId64",%"PRId64")",
+ av_rescale_q(1, mdcv->display_primaries[1][0], (AVRational){ 1, 50000 }),
+ av_rescale_q(1, mdcv->display_primaries[1][1], (AVRational){ 1, 50000 }),
+ av_rescale_q(1, mdcv->display_primaries[2][0], (AVRational){ 1, 50000 }),
+ av_rescale_q(1, mdcv->display_primaries[2][1], (AVRational){ 1, 50000 }),
+ av_rescale_q(1, mdcv->display_primaries[0][0], (AVRational){ 1, 50000 }),
+ av_rescale_q(1, mdcv->display_primaries[0][1], (AVRational){ 1, 50000 }),
+ av_rescale_q(1, mdcv->white_point[0], (AVRational){ 1, 50000 }),
+ av_rescale_q(1, mdcv->white_point[1], (AVRational){ 1, 50000 }),
+ av_rescale_q(1, mdcv->max_luminance, (AVRational){ 1, 10000 }),
+ av_rescale_q(1, mdcv->min_luminance, (AVRational){ 1, 10000 }));
+
+ if (!av_bprint_is_complete(&buf)) {
+ ret = AVERROR(ENOMEM);
+ goto end;
+ }
+
+ if (api->param_parse(params, option, buf.str) ==
+ X265_PARAM_BAD_VALUE) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Invalid value \"%s\" for param \"%s\".\n",
+ buf.str, option);
+ ret = AVERROR(EINVAL);
+ goto end;
+ }
+
+ ret = 0;
+
+end:
+ av_bprint_finalize(&buf, NULL);
+
+ return ret;
+}
+
+static int handle_side_data(AVCodecContext *avctx, const x265_api *api,
+ x265_param *params)
+{
+ const AVFrameSideDataSet set = avctx->side_data_set;
+ const AVFrameSideData *cll_sd =
+ av_get_side_data_from_set(set, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
+ const AVFrameSideData *mdcv_sd =
+ av_get_side_data_from_set(set, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
+
+ if (cll_sd) {
+ const AVContentLightMetadata *cll =
+ (AVContentLightMetadata *)cll_sd->data;
+
+ params->maxCLL = cll->MaxCLL;
+ params->maxFALL = cll->MaxFALL;
+ }
+
+ if (mdcv_sd) {
+ int ret = handle_mdcv(avctx, api, params, (AVMasteringDisplayMetadata *)mdcv_sd->data);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
static av_cold int libx265_encode_init(AVCodecContext *avctx)
{
libx265Context *ctx = avctx->priv_data;
@@ -333,6 +408,13 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx)
return AVERROR_BUG;
}
+ ret = handle_side_data(avctx, ctx->api, ctx->params);
+ if (ret < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Failed handling side data! (%s)\n",
+ av_err2str(ret));
+ return ret;
+ }
+
if (ctx->crf >= 0) {
char crf[6];
--
2.39.2
_______________________________________________
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] 13+ messages in thread
end of thread, other threads:[~2023-03-31 16:24 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-31 16:21 [FFmpeg-devel] [PATCH v1 00/12] encoder AVCodecContext configuration side data Jan Ekström
2023-03-31 16:21 ` [FFmpeg-devel] [PATCH v1 01/12] avutil/frame: add AVFrameSideDataSet for passing sets of " Jan Ekström
2023-03-31 16:21 ` [FFmpeg-devel] [PATCH v1 02/12] avutil/frame: split side data list wiping out to non-AVFrame function Jan Ekström
2023-03-31 16:21 ` [FFmpeg-devel] [PATCH v1 03/12] avutil/frame: add helper for clearing out side data sets Jan Ekström
2023-03-31 16:21 ` [FFmpeg-devel] [PATCH v1 04/12] avutil/frame: split side_data_from_buf to base and AVFrame func Jan Ekström
2023-03-31 16:21 ` [FFmpeg-devel] [PATCH v1 05/12] avutil/frame: add helper for adding side data to set Jan Ekström
2023-03-31 16:21 ` [FFmpeg-devel] [PATCH v1 06/12] avutil/frame: add helper for getting side data from set Jan Ekström
2023-03-31 16:22 ` [FFmpeg-devel] [PATCH v1 07/12] avutil/frame: add helper for extending a set of side data Jan Ekström
2023-03-31 16:22 ` [FFmpeg-devel] [PATCH v1 08/12] avcodec: add private side data set to AVCodecContext Jan Ekström
2023-03-31 16:22 ` [FFmpeg-devel] [PATCH v1 09/12] ffmpeg: pass first video AVFrame's side data to encoder Jan Ekström
2023-03-31 16:22 ` [FFmpeg-devel] [PATCH v1 10/12] avcodec/libsvtav1: add support for writing out CLL and MDCV Jan Ekström
2023-03-31 16:22 ` [FFmpeg-devel] [PATCH v1 11/12] avcodec/libx264: " Jan Ekström
2023-03-31 16:22 ` [FFmpeg-devel] [PATCH v1 12/12] avcodec/libx265: " Jan Ekström
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