Ticket #6609: 0001-Properly-store-sampling-rate-for-FLAC-in-mp4.patch

File 0001-Properly-store-sampling-rate-for-FLAC-in-mp4.patch, 2.1 KB (added by jyavenard, 21 months ago)
  • libavformat/movenc.c

    From 9baa7166fa96ed6beac9146c7e3b4dcf425a67d0 Mon Sep 17 00:00:00 2001
    From: Jean-Yves Avenard <jyavenard@mythtv.org>
    Date: Fri, 25 Aug 2017 13:11:28 +0200
    Subject: [PATCH] Properly store sampling rate for FLAC in mp4
    
    Fixes ticket #6609
    
    Signed-off-by: Jean-Yves Avenard <jyavenard@mozilla.com>
    ---
     libavformat/movenc.c | 28 +++++++++++++++++++++++++---
     1 file changed, 25 insertions(+), 3 deletions(-)
    
    diff --git a/libavformat/movenc.c b/libavformat/movenc.c
    index 10b959ad02..aa4a9c962a 100644
    a b static int mov_write_audio_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex 
    10281028        avio_wb16(pb, 0); /* packet size (= 0) */
    10291029        if (track->par->codec_id == AV_CODEC_ID_OPUS)
    10301030            avio_wb16(pb, 48000);
    1031         else
    1032             avio_wb16(pb, track->par->sample_rate <= UINT16_MAX ?
    1033                           track->par->sample_rate : 0);
     1031        else {
     1032            uint32_t rate;
     1033            if (track->par->codec_id == AV_CODEC_ID_FLAC) {
     1034                /* When the bitstream's native sample rate is greater
     1035                 than the maximum expressible value of 65535 Hz,
     1036                 the samplerate field shall hold the greatest
     1037                 expressible regular division of that rate. I.e.
     1038                 the samplerate field shall hold 48000.0 for
     1039                 native sample rates of 96 and 192 kHz. In the
     1040                 case of unusual sample rates which do not have
     1041                 an expressible regular division, the maximum value
     1042                 of 65535.0 Hz should be used. */
     1043                rate = track->par->sample_rate;
     1044                while (rate > UINT16_MAX && (rate & 1) == 0) {
     1045                    rate = rate >> 1;
     1046                }
     1047                if (rate > UINT16_MAX) {
     1048                    rate = UINT16_MAX;
     1049                }
     1050            } else {
     1051                rate = track->par->sample_rate <= UINT16_MAX ?
     1052                       track->par->sample_rate : 0;
     1053            }
     1054            avio_wb16(pb, rate);
     1055        }
    10341056        avio_wb16(pb, 0); /* Reserved */
    10351057    }
    10361058