Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avformat/mov: read PCM audio configuration box ('pcmC') if available
@ 2022-06-07  8:26 Ivan Baykalov
  2022-06-19 21:51 ` Marton Balint
  0 siblings, 1 reply; 5+ messages in thread
From: Ivan Baykalov @ 2022-06-07  8:26 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Ivan Baykalov

For ipcm and fpcm streams, big-endian format is the default, but it can be changed
with additional 'pcmC' sub-atom of audio sample description.

Details can be found in ISO/IEC 23003-5:2020

Fixes ticket #9763
Fixes ticket #9790
---
 libavformat/mov.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index d7be593a86..f71a470d9c 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -7567,6 +7567,65 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     return atom.size;
 }
 
+static int mov_read_pcmc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+    int version, format_flags, pcm_sample_size;
+    AVStream *st;
+
+    if (atom.size < 6) {
+        av_log(c->fc, AV_LOG_ERROR, "Empty pcmC box\n");
+        return AVERROR_INVALIDDATA;
+    }
+
+    version = avio_r8(pb);
+    if (version) {
+        av_log(c->fc, AV_LOG_WARNING, "Unsupported pcmC box version %d\n", version);
+        return 0;
+    }
+
+    avio_rb24(pb);  // flags
+
+    if (c->fc->nb_streams < 1)
+        return 0;
+    st = c->fc->streams[c->fc->nb_streams-1];
+    if (!st || !st->codecpar)
+        return 0;
+
+    format_flags = avio_r8(pb);
+    if (format_flags == 1) { // indicates little-endian format. If not present, big-endian format is used
+        if (st->codecpar->codec_tag == MKTAG('i','p','c','m')) {
+            switch (st->codecpar->codec_id) {
+                case AV_CODEC_ID_PCM_S16BE:
+                    st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
+                    break;
+                case AV_CODEC_ID_PCM_S24BE:
+                    st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE;
+                    break;
+                case AV_CODEC_ID_PCM_S32BE:
+                    st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE;
+                    break;
+            }
+        }
+        else if (st->codecpar->codec_tag == MKTAG('f','p','c','m')) {
+            switch (st->codecpar->codec_id) {
+                case AV_CODEC_ID_PCM_F32BE:
+                    st->codecpar->codec_id = AV_CODEC_ID_PCM_F32LE;
+                    break;
+                case AV_CODEC_ID_PCM_F64BE:
+                    st->codecpar->codec_id = AV_CODEC_ID_PCM_F64LE;
+                    break;
+            }
+        }
+    }
+
+    pcm_sample_size = avio_r8(pb);
+    if (pcm_sample_size != st->codecpar->bits_per_coded_sample) {
+        av_log(c->fc, AV_LOG_WARNING, "Unexpected pcmC sample size (%d vs %d)\n", pcm_sample_size, st->codecpar->bits_per_coded_sample);
+    }
+
+    return 0;
+}
+
 static const MOVParseTableEntry mov_default_parse_table[] = {
 { MKTAG('A','C','L','R'), mov_read_aclr },
 { MKTAG('A','P','R','G'), mov_read_avid },
@@ -7670,6 +7729,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = {
 { MKTAG('S','A','3','D'), mov_read_SA3D }, /* ambisonic audio box */
 { MKTAG('S','A','N','D'), mov_read_SAND }, /* non diegetic audio box */
 { MKTAG('i','l','o','c'), mov_read_iloc },
+{ MKTAG('p','c','m','C'), mov_read_pcmc }, /* PCM configuration box */
 { 0, NULL }
 };
 
-- 
2.35.1

_______________________________________________
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] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avformat/mov: read PCM audio configuration box ('pcmC') if available
  2022-06-07  8:26 [FFmpeg-devel] [PATCH] avformat/mov: read PCM audio configuration box ('pcmC') if available Ivan Baykalov
@ 2022-06-19 21:51 ` Marton Balint
  2022-06-19 21:53   ` [FFmpeg-devel] [PATCH 1/2] avformat/mov: factorize setting little endian PCM streams Marton Balint
  0 siblings, 1 reply; 5+ messages in thread
From: Marton Balint @ 2022-06-19 21:51 UTC (permalink / raw)
  To: FFmpeg development discussions and patches



On Tue, 7 Jun 2022, Ivan Baykalov wrote:

> For ipcm and fpcm streams, big-endian format is the default, but it can be changed
> with additional 'pcmC' sub-atom of audio sample description.
>
> Details can be found in ISO/IEC 23003-5:2020
>
> Fixes ticket #9763
> Fixes ticket #9790

Thanks for this, I have factorized the duplicated code from 
existing endianness setting and also simplified your patch a bit. Will 
post it as a reply to this mail.

Regards,
Marton

> ---
> libavformat/mov.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 60 insertions(+)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index d7be593a86..f71a470d9c 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -7567,6 +7567,65 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
>     return atom.size;
> }
>
> +static int mov_read_pcmc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
> +{
> +    int version, format_flags, pcm_sample_size;
> +    AVStream *st;
> +
> +    if (atom.size < 6) {
> +        av_log(c->fc, AV_LOG_ERROR, "Empty pcmC box\n");
> +        return AVERROR_INVALIDDATA;
> +    }
> +
> +    version = avio_r8(pb);
> +    if (version) {
> +        av_log(c->fc, AV_LOG_WARNING, "Unsupported pcmC box version %d\n", version);
> +        return 0;
> +    }
> +
> +    avio_rb24(pb);  // flags
> +
> +    if (c->fc->nb_streams < 1)
> +        return 0;
> +    st = c->fc->streams[c->fc->nb_streams-1];
> +    if (!st || !st->codecpar)
> +        return 0;
> +
> +    format_flags = avio_r8(pb);
> +    if (format_flags == 1) { // indicates little-endian format. If not present, big-endian format is used
> +        if (st->codecpar->codec_tag == MKTAG('i','p','c','m')) {
> +            switch (st->codecpar->codec_id) {
> +                case AV_CODEC_ID_PCM_S16BE:
> +                    st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
> +                    break;
> +                case AV_CODEC_ID_PCM_S24BE:
> +                    st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE;
> +                    break;
> +                case AV_CODEC_ID_PCM_S32BE:
> +                    st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE;
> +                    break;
> +            }
> +        }
> +        else if (st->codecpar->codec_tag == MKTAG('f','p','c','m')) {
> +            switch (st->codecpar->codec_id) {
> +                case AV_CODEC_ID_PCM_F32BE:
> +                    st->codecpar->codec_id = AV_CODEC_ID_PCM_F32LE;
> +                    break;
> +                case AV_CODEC_ID_PCM_F64BE:
> +                    st->codecpar->codec_id = AV_CODEC_ID_PCM_F64LE;
> +                    break;
> +            }
> +        }
> +    }
> +
> +    pcm_sample_size = avio_r8(pb);
> +    if (pcm_sample_size != st->codecpar->bits_per_coded_sample) {
> +        av_log(c->fc, AV_LOG_WARNING, "Unexpected pcmC sample size (%d vs %d)\n", pcm_sample_size, st->codecpar->bits_per_coded_sample);
> +    }
> +
> +    return 0;
> +}
> +
> static const MOVParseTableEntry mov_default_parse_table[] = {
> { MKTAG('A','C','L','R'), mov_read_aclr },
> { MKTAG('A','P','R','G'), mov_read_avid },
> @@ -7670,6 +7729,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = {
> { MKTAG('S','A','3','D'), mov_read_SA3D }, /* ambisonic audio box */
> { MKTAG('S','A','N','D'), mov_read_SAND }, /* non diegetic audio box */
> { MKTAG('i','l','o','c'), mov_read_iloc },
> +{ MKTAG('p','c','m','C'), mov_read_pcmc }, /* PCM configuration box */
> { 0, NULL }
> };
>
> -- 
> 2.35.1
>
> _______________________________________________
> 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".
>
_______________________________________________
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] 5+ messages in thread

* [FFmpeg-devel] [PATCH 1/2] avformat/mov: factorize setting little endian PCM streams
  2022-06-19 21:51 ` Marton Balint
@ 2022-06-19 21:53   ` Marton Balint
  2022-06-19 21:53     ` [FFmpeg-devel] [PATCH 2/2] avformat/mov: read PCM audio configuration box ('pcmC') if available Marton Balint
  0 siblings, 1 reply; 5+ messages in thread
From: Marton Balint @ 2022-06-19 21:53 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Marton Balint

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavformat/mov.c | 51 +++++++++++++++++++++++++----------------------
 1 file changed, 27 insertions(+), 24 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 3ec0ea2361..0660a51492 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1544,35 +1544,38 @@ static int mov_read_mvhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     return 0;
 }
 
-static int mov_read_enda(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+static void set_last_stream_little_endian(AVFormatContext *fc)
 {
     AVStream *st;
-    int little_endian;
 
-    if (c->fc->nb_streams < 1)
-        return 0;
-    st = c->fc->streams[c->fc->nb_streams-1];
+    if (fc->nb_streams < 1)
+        return;
+    st = fc->streams[fc->nb_streams-1];
 
-    little_endian = avio_rb16(pb) & 0xFF;
-    av_log(c->fc, AV_LOG_TRACE, "enda %d\n", little_endian);
-    if (little_endian == 1) {
-        switch (st->codecpar->codec_id) {
-        case AV_CODEC_ID_PCM_S24BE:
-            st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE;
-            break;
-        case AV_CODEC_ID_PCM_S32BE:
-            st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE;
-            break;
-        case AV_CODEC_ID_PCM_F32BE:
-            st->codecpar->codec_id = AV_CODEC_ID_PCM_F32LE;
-            break;
-        case AV_CODEC_ID_PCM_F64BE:
-            st->codecpar->codec_id = AV_CODEC_ID_PCM_F64LE;
-            break;
-        default:
-            break;
-        }
+    switch (st->codecpar->codec_id) {
+    case AV_CODEC_ID_PCM_S24BE:
+        st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE;
+        break;
+    case AV_CODEC_ID_PCM_S32BE:
+        st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE;
+        break;
+    case AV_CODEC_ID_PCM_F32BE:
+        st->codecpar->codec_id = AV_CODEC_ID_PCM_F32LE;
+        break;
+    case AV_CODEC_ID_PCM_F64BE:
+        st->codecpar->codec_id = AV_CODEC_ID_PCM_F64LE;
+        break;
+    default:
+        break;
     }
+}
+
+static int mov_read_enda(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+    int little_endian = avio_rb16(pb) & 0xFF;
+    av_log(c->fc, AV_LOG_TRACE, "enda %d\n", little_endian);
+    if (little_endian == 1)
+        set_last_stream_little_endian(c->fc);
     return 0;
 }
 
-- 
2.35.3

_______________________________________________
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] 5+ messages in thread

* [FFmpeg-devel] [PATCH 2/2] avformat/mov: read PCM audio configuration box ('pcmC') if available
  2022-06-19 21:53   ` [FFmpeg-devel] [PATCH 1/2] avformat/mov: factorize setting little endian PCM streams Marton Balint
@ 2022-06-19 21:53     ` Marton Balint
  2022-06-27 18:36       ` Marton Balint
  0 siblings, 1 reply; 5+ messages in thread
From: Marton Balint @ 2022-06-19 21:53 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Ivan Baykalov, Marton Balint

From: Ivan Baykalov <4rusxg@gmail.com>

For ipcm and fpcm streams, big-endian format is the default, but it can be changed
with additional 'pcmC' sub-atom of audio sample description.

Details can be found in ISO/IEC 23003-5:2020

Fixes ticket #9763.
Fixes ticket #9790.

Patch simplified by Marton Balint.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavformat/mov.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 0660a51492..c6fbe511c0 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1553,6 +1553,9 @@ static void set_last_stream_little_endian(AVFormatContext *fc)
     st = fc->streams[fc->nb_streams-1];
 
     switch (st->codecpar->codec_id) {
+    case AV_CODEC_ID_PCM_S16BE:
+        st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
+        break;
     case AV_CODEC_ID_PCM_S24BE:
         st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE;
         break;
@@ -1579,6 +1582,24 @@ static int mov_read_enda(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     return 0;
 }
 
+static int mov_read_pcmc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+    int format_flags;
+
+    if (atom.size < 6) {
+        av_log(c->fc, AV_LOG_ERROR, "Empty pcmC box\n");
+        return AVERROR_INVALIDDATA;
+    }
+
+    avio_r8(pb);    // version
+    avio_rb24(pb);  // flags
+    format_flags = avio_r8(pb);
+    if (format_flags == 1) // indicates little-endian format. If not present, big-endian format is used
+        set_last_stream_little_endian(c->fc);
+
+    return 0;
+}
+
 static int mov_read_colr(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
     AVStream *st;
@@ -7674,6 +7695,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = {
 { MKTAG('S','A','3','D'), mov_read_SA3D }, /* ambisonic audio box */
 { MKTAG('S','A','N','D'), mov_read_SAND }, /* non diegetic audio box */
 { MKTAG('i','l','o','c'), mov_read_iloc },
+{ MKTAG('p','c','m','C'), mov_read_pcmc }, /* PCM configuration box */
 { 0, NULL }
 };
 
-- 
2.35.3

_______________________________________________
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] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/2] avformat/mov: read PCM audio configuration box ('pcmC') if available
  2022-06-19 21:53     ` [FFmpeg-devel] [PATCH 2/2] avformat/mov: read PCM audio configuration box ('pcmC') if available Marton Balint
@ 2022-06-27 18:36       ` Marton Balint
  0 siblings, 0 replies; 5+ messages in thread
From: Marton Balint @ 2022-06-27 18:36 UTC (permalink / raw)
  To: FFmpeg development discussions and patches



On Sun, 19 Jun 2022, Marton Balint wrote:

> From: Ivan Baykalov <4rusxg@gmail.com>
>
> For ipcm and fpcm streams, big-endian format is the default, but it can be changed
> with additional 'pcmC' sub-atom of audio sample description.
>
> Details can be found in ISO/IEC 23003-5:2020
>
> Fixes ticket #9763.
> Fixes ticket #9790.
>
> Patch simplified by Marton Balint.

Applied the series.

Regards,
Marton

>
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
> libavformat/mov.c | 22 ++++++++++++++++++++++
> 1 file changed, 22 insertions(+)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 0660a51492..c6fbe511c0 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -1553,6 +1553,9 @@ static void set_last_stream_little_endian(AVFormatContext *fc)
>     st = fc->streams[fc->nb_streams-1];
>
>     switch (st->codecpar->codec_id) {
> +    case AV_CODEC_ID_PCM_S16BE:
> +        st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
> +        break;
>     case AV_CODEC_ID_PCM_S24BE:
>         st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE;
>         break;
> @@ -1579,6 +1582,24 @@ static int mov_read_enda(MOVContext *c, AVIOContext *pb, MOVAtom atom)
>     return 0;
> }
>
> +static int mov_read_pcmc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
> +{
> +    int format_flags;
> +
> +    if (atom.size < 6) {
> +        av_log(c->fc, AV_LOG_ERROR, "Empty pcmC box\n");
> +        return AVERROR_INVALIDDATA;
> +    }
> +
> +    avio_r8(pb);    // version
> +    avio_rb24(pb);  // flags
> +    format_flags = avio_r8(pb);
> +    if (format_flags == 1) // indicates little-endian format. If not present, big-endian format is used
> +        set_last_stream_little_endian(c->fc);
> +
> +    return 0;
> +}
> +
> static int mov_read_colr(MOVContext *c, AVIOContext *pb, MOVAtom atom)
> {
>     AVStream *st;
> @@ -7674,6 +7695,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = {
> { MKTAG('S','A','3','D'), mov_read_SA3D }, /* ambisonic audio box */
> { MKTAG('S','A','N','D'), mov_read_SAND }, /* non diegetic audio box */
> { MKTAG('i','l','o','c'), mov_read_iloc },
> +{ MKTAG('p','c','m','C'), mov_read_pcmc }, /* PCM configuration box */
> { 0, NULL }
> };
>
> -- 
> 2.35.3
>
> _______________________________________________
> 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".
>
_______________________________________________
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] 5+ messages in thread

end of thread, other threads:[~2022-06-27 18:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-07  8:26 [FFmpeg-devel] [PATCH] avformat/mov: read PCM audio configuration box ('pcmC') if available Ivan Baykalov
2022-06-19 21:51 ` Marton Balint
2022-06-19 21:53   ` [FFmpeg-devel] [PATCH 1/2] avformat/mov: factorize setting little endian PCM streams Marton Balint
2022-06-19 21:53     ` [FFmpeg-devel] [PATCH 2/2] avformat/mov: read PCM audio configuration box ('pcmC') if available Marton Balint
2022-06-27 18:36       ` Marton Balint

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