[FFmpeg-devel] [PATCH v2] avformat/nut: Store display matrix side data

Matthias Neugebauer mtneug at mailbox.org
Wed Nov 4 03:14:08 EET 2020


Stream side data such as display matrix is currently lost when using NUT.

Signed-off-by: Matthias Neugebauer <mtneug at mailbox.org>
---
libavformat/nutdec.c |  9 +++++++++
libavformat/nutenc.c | 18 ++++++++++++++++++
2 files changed, 27 insertions(+)

diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index 53a052503e..3747a74402 100644
--- a/libavformat/nutdec.c
+++ b/libavformat/nutdec.c
@@ -589,6 +589,15 @@ static int decode_info_header(NUTContext *nut)
                 continue;
             }

+            if (stream_id_plus1 && !strcmp(name, "X-st_sd_displaymatrix")) {
+                uint32_t *display_matrix = (uint32_t *)av_stream_new_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, 9 * sizeof(uint32_t));
+                sscanf(str_value, "%u:%u:%u:%u:%u:%u:%u:%u:%u",
+                       &display_matrix[0], &display_matrix[1], &display_matrix[2],
+                       &display_matrix[3], &display_matrix[4], &display_matrix[5],
+                       &display_matrix[6], &display_matrix[7], &display_matrix[8]);
+                continue;
+            }
+
             if (metadata && av_strcasecmp(name, "Uses") &&
                 av_strcasecmp(name, "Depends") && av_strcasecmp(name, "Replaces")) {
                 if (event_flags)
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 1dcb2be1b1..65806fb46e 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -524,6 +524,7 @@ static int write_streaminfo(NUTContext *nut, AVIOContext *bc, int stream_id) {
     AVStream* st = s->streams[stream_id];
     AVDictionaryEntry *t = NULL;
     AVIOContext *dyn_bc;
+    AVPacketSideData *sd;
     uint8_t *dyn_buf=NULL;
     int count=0, dyn_size, i;
     int ret = avio_open_dyn_buf(&dyn_bc);
@@ -536,6 +537,23 @@ static int write_streaminfo(NUTContext *nut, AVIOContext *bc, int stream_id) {
         if (st->disposition & ff_nut_dispositions[i].flag)
             count += add_info(dyn_bc, "Disposition", ff_nut_dispositions[i].str);
     }
+
+    for (i = 0; i < st->nb_side_data; i++) {
+        sd = &st->side_data[i];
+
+        switch (sd->type) {
+        case AV_PKT_DATA_DISPLAYMATRIX:;
+            uint8_t buf[128];
+            uint32_t *display_matrix = (uint32_t *)sd->data;
+            snprintf(buf, sizeof(buf), "%u:%u:%u:%u:%u:%u:%u:%u:%u",
+                     display_matrix[0], display_matrix[1], display_matrix[2],
+                     display_matrix[3], display_matrix[4], display_matrix[5],
+                     display_matrix[6], display_matrix[7], display_matrix[8]);
+            count += add_info(dyn_bc, "X-st_sd_displaymatrix", buf);
+            break;
+        }
+    }
+
     if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
         uint8_t buf[256];
         if (st->r_frame_rate.num>0 && st->r_frame_rate.den>0)
-- 
2.29.2



More information about the ffmpeg-devel mailing list