[FFmpeg-devel,v3,20/25] avformat/movenc: mov_write_audio_tag can write the proper number of channels, not the hardcoded 2

Submitted by erkki.seppala.ext@nokia.com on Sept. 19, 2016, 1:25 p.m.

Details

Message ID 1474291548-17810-21-git-send-email-erkki.seppala.ext@nokia.com
State New
Headers show

Commit Message

erkki.seppala.ext@nokia.com Sept. 19, 2016, 1:25 p.m.
It does it only when the chnl box is to be written. The specification
for the chnl box (ISO 14496-12) requires proper number of channels to be
written here is it is used, and without the proper number of channels
available it becomes tricky to parse the data, as the number of channels
in this box comes from that value.

Signed-off-by: Erkki Seppälä <erkki.seppala.ext@nokia.com>
Signed-off-by: OZOPlayer <OZOPL@nokia.com>
---
 libavformat/movenc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 2543404..4245396 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1045,7 +1045,13 @@  static int mov_write_audio_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex
                 avio_wb16(pb, 16);
             avio_wb16(pb, track->audio_vbr ? -2 : 0); /* compression ID */
         } else { /* reserved for mp4/3gp */
-            avio_wb16(pb, 2);
+            /* parsing chln box requires the proper number of channels having been
+               written into the audio header */
+            if (av_stream_get_side_data(track->st, AV_PKT_DATA_AUDIO_TRACK_CHANNEL_LAYOUT,
+                                        NULL))
+                avio_wb16(pb, track->par->channels);
+            else
+                avio_wb16(pb, 2);
             avio_wb16(pb, 16);
             avio_wb16(pb, 0);
         }