FFmpeg curiously uses 'sowt' as the fourcc when writing 8-bit signed QuickTime data, so cater for this as well. Description follows:

Since mkvmerge doesn't set the bit depth for A_QUICKTIME audio (as far as I know), the track->audio.bitdepth variable will be zero, and its value needs to be retrieved from the sound sample description. Also, confine the 0x00000000 to 'raw '/'twos' fourcc mapping to old version 0 sound sample descriptions, since they are the only valid sample descriptions for this type of mapping.

Also, 'twos' and 'sowt' audio can be signed 8-bit.

--
Mats Peterson
http://matsp888.no-ip.org/~mats/
>From 0fce7d158725fe9c3fe673cebba3c42e328a8aad Mon Sep 17 00:00:00 2001
From: Mats Peterson <matsp...@yahoo.com>
Date: Fri, 15 Jan 2016 13:01:40 +0100
Subject: [PATCH v3] lavf/matroskadec: Set A_QUICKTIME bit depth

Since mkvmerge doesn't set the bit depth for A_QUICKTIME audio (as far
as I know), the track->audio.bitdepth variable will be zero, and its
value needs to be retrieved from the sound sample description. Also,
confine the 0x00000000 to 'raw '/'twos' fourcc mapping to old version 0
sound sample descriptions, since they are the only valid sample
descriptions for this type of mapping.

Also, 'twos' and 'sowt' audio can be signed 8-bit.

---
 libavformat/matroskadec.c |   25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index cc5ec19..95faf4a 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -1891,17 +1891,28 @@ static int matroska_parse_tracks(AVFormatContext *s)
                    /* Normally 36, but allow noncompliant private data */
                    && (track->codec_priv.size >= 32)
                    && (track->codec_priv.data)) {
+            uint16_t stsd_version;
             int ret = get_qt_codec(track, &fourcc, &codec_id);
             if (ret < 0)
                 return ret;
-            if (fourcc == 0) {
-                if (track->audio.bitdepth == 8) {
-                    fourcc = MKTAG('r','a','w',' ');
-                    codec_id = ff_codec_get_id(ff_codec_movaudio_tags, fourcc);
-                } else if (track->audio.bitdepth == 16) {
-                    fourcc = MKTAG('t','w','o','s');
-                    codec_id = ff_codec_get_id(ff_codec_movaudio_tags, fourcc);
+            stsd_version = AV_RB16(track->codec_priv.data + 16);
+            if (stsd_version == 0) {
+                /* Currently not set by mkvmerge, so get the bit depth
+                 * from the sample description. */
+                track->audio.bitdepth = AV_RB16(track->codec_priv.data + 26);
+                if (fourcc == 0) {
+                    if (track->audio.bitdepth == 8) {
+                        fourcc = MKTAG('r','a','w',' ');
+                        codec_id = ff_codec_get_id(ff_codec_movaudio_tags, fourcc);
+                    } else if (track->audio.bitdepth == 16) {
+                        fourcc = MKTAG('t','w','o','s');
+                        codec_id = ff_codec_get_id(ff_codec_movaudio_tags, fourcc);
+                    }
                 }
+                /* 'twos' and 'sowt' audio can be 8-bit */
+                if ((fourcc == MKTAG('t','w','o','s') || fourcc == MKTAG('s','o','w','t')) &&
+                        track->audio.bitdepth == 8)
+                    codec_id = AV_CODEC_ID_PCM_S8;
             }
         } else if (!strcmp(track->codec_id, "V_QUICKTIME") &&
                    (track->codec_priv.size >= 21)          &&
-- 
1.7.10.4

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to