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' audio can be signed 8-bit.

Mats

--
Mats Peterson
http://matsp888.no-ip.org/~mats/
>From 8de708387f9bff7f20c825ccad59352b0fd7fc33 Mon Sep 17 00:00:00 2001
From: Mats Peterson <matsp...@yahoo.com>
Date: Fri, 15 Jan 2016 10:49:45 +0100
Subject: [PATCH v2] 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' audio can be signed 8-bit.

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

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index cc5ec19..687929a 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -1891,17 +1891,27 @@ 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' audio can be 8-bit */
+                if (fourcc == MKTAG('t','w','o','s') && 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