diff mbox series

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

Message ID F7848CEE-46C1-4CAF-9191-A7BABF5D61B4@mailbox.org
State New
Headers show
Series [FFmpeg-devel] avformat/nut: Store display matrix side data | expand

Checks

Context Check Description
andriy/x86_make_warn warning New warnings during build
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Matthias Neugebauer Nov. 1, 2020, 9:05 p.m. UTC
Stream side data such as display matrix is currently lost when using NUT.

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

Comments

Michael Niedermayer Nov. 2, 2020, 11:23 p.m. UTC | #1
On Sun, Nov 01, 2020 at 10:05:16PM +0100, Matthias Neugebauer wrote:
> Stream side data such as display matrix is currently lost when using NUT.
> 
> Signed-off-by: Matthias Neugebauer <mtneug@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..9ac484f9bc 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, "st_sd_displaymatrix")) {

"st_sd_displaymatrix" is not listed in nut.txt
that either needs to be added or if its a non standard field it needs a
X- prefix

Thanks


[...]
Matthias Neugebauer Nov. 2, 2020, 11:37 p.m. UTC | #2
Am 03.11.2020 um 00:23 schrieb Michael Niedermayer <michael@niedermayer.cc>:
> "st_sd_displaymatrix" is not listed in nut.txt
> that either needs to be added or if its a non standard field it needs a
> X- prefix

Thanks for the feedback.

Adding X- is not a problem, but what is the difference to "r_frame_rate“
for storing the frame rate? Shouldn’t that be prefixed as well?
Matthias Neugebauer Nov. 4, 2020, 1:14 a.m. UTC | #3
Stream side data such as display matrix is currently lost when using NUT.

Signed-off-by: Matthias Neugebauer <mtneug@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)
Michael Niedermayer Nov. 4, 2020, 9:30 a.m. UTC | #4
On Tue, Nov 03, 2020 at 12:37:01AM +0100, Matthias Neugebauer wrote:
> Am 03.11.2020 um 00:23 schrieb Michael Niedermayer <michael@niedermayer.cc>:
> > "st_sd_displaymatrix" is not listed in nut.txt
> > that either needs to be added or if its a non standard field it needs a
> > X- prefix
> 
> Thanks for the feedback.
> 
> Adding X- is not a problem, but what is the difference to "r_frame_rate“
> for storing the frame rate? Shouldn’t that be prefixed as well?

you are correct
I will suggest to add this to nut.txt, given that its already stored for
a long time, it should be documented which should resolve this

Thanks

[...]
Michael Niedermayer Nov. 4, 2020, 6:24 p.m. UTC | #5
On Wed, Nov 04, 2020 at 02:14:08AM +0100, Matthias Neugebauer wrote:
> Stream side data such as display matrix is currently lost when using NUT.
> 
> Signed-off-by: Matthias Neugebauer <mtneug@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")) {

Is this FFmpeg specific or why is the X- prefix preferred over adding
this to nut.txt ?

thx

[...]
Matthias Neugebauer Nov. 5, 2020, 3:48 p.m. UTC | #6
Am 04.11.2020 um 19:24 schrieb Michael Niedermayer <michael@niedermayer.cc>:
> 
> Is this FFmpeg specific or why is the X- prefix preferred over adding
> this to nut.txt ?
> 
> thx

No, side data such as the display matrix is commonly used in other formats and
outside of FFmpeg. Having it in the NUT spec is probably better. Is nut.txt in the
Git repository. I couldn’t find it.
Michael Niedermayer Nov. 6, 2020, 9:25 p.m. UTC | #7
On Thu, Nov 05, 2020 at 04:48:31PM +0100, Matthias Neugebauer wrote:
> Am 04.11.2020 um 19:24 schrieb Michael Niedermayer <michael@niedermayer.cc>:
> > 
> > Is this FFmpeg specific or why is the X- prefix preferred over adding
> > this to nut.txt ?
> > 
> > thx
> 
> No, side data such as the display matrix is commonly used in other formats and
> outside of FFmpeg. Having it in the NUT spec is probably better. Is nut.txt in the
> Git repository. I couldn’t find it.

see:

https://git.ffmpeg.org/nut.git
svn://svn.mplayerhq.hu/nut
https://lists.ffmpeg.org/mailman/listinfo/nut-devel

thx

[...]
Matthias Neugebauer Dec. 11, 2020, 8:34 a.m. UTC | #8
> Am 06.11.2020 um 22:25 schrieb Michael Niedermayer <michael@niedermayer.cc>:
> 
> see:
> 
> https://git.ffmpeg.org/nut.git
> svn://svn.mplayerhq.hu/nut
> https://lists.ffmpeg.org/mailman/listinfo/nut-devel
> 
> thx

I submitted a patch for nut.txt some time ago. Is there still something missing on my part?
Paul B Mahol Dec. 11, 2020, 11:42 a.m. UTC | #9
Perhaps Michael failed to see it, if nut stuff is still not merged ping
Michael directly.

On Fri, Dec 11, 2020 at 9:35 AM Matthias Neugebauer <mtneug@mailbox.org>
wrote:

>
> > Am 06.11.2020 um 22:25 schrieb Michael Niedermayer
> <michael@niedermayer.cc>:
> >
> > see:
> >
> > https://git.ffmpeg.org/nut.git
> > svn://svn.mplayerhq.hu/nut
> > https://lists.ffmpeg.org/mailman/listinfo/nut-devel
> >
> > thx
>
> I submitted a patch for nut.txt some time ago. Is there still something
> missing on my part?
>
> _______________________________________________
> 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".
diff mbox series

Patch

diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index 53a052503e..9ac484f9bc 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, "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..0a14a400d1 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, "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)