Note that that it's also not correct for other codecs when the sampling rate is greater than 65536. Right now it stores 0. If in quicktime mode, it could use a SoundDescription v2 box, but in mp4 that doesn't exist.
Per ISO 14496-12 , it should be using a AudioSampleEntryV1 along a SamplingRateBox ('srat') which uses a 32 bits unsigned integer. There's no handling of that in the current ffmpeg. If time permit I will submit something for this. Rgds JY On 25 August 2017 at 13:25, Jean-Yves Avenard <jyaven...@gmail.com> wrote: > From 9baa7166fa96ed6beac9146c7e3b4dcf425a67d0 Mon Sep 17 00:00:00 2001 > From: Jean-Yves Avenard <jyaven...@mozilla.com> > 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 <jyaven...@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/libavformat/movenc.c > +++ b/libavformat/movenc.c > @@ -1028,9 +1028,31 @@ static int mov_write_audio_tag(AVFormatContext > *s, AVIOContext *pb, MOVMuxContex > avio_wb16(pb, 0); /* packet size (= 0) */ > if (track->par->codec_id == AV_CODEC_ID_OPUS) > avio_wb16(pb, 48000); > - else > - avio_wb16(pb, track->par->sample_rate <= UINT16_MAX ? > - track->par->sample_rate : 0); > + else { > + uint32_t rate; > + if (track->par->codec_id == AV_CODEC_ID_FLAC) { > + /* When the bitstream's native sample rate is greater > + than the maximum expressible value of 65535 Hz, > + the samplerate field shall hold the greatest > + expressible regular division of that rate. I.e. > + the samplerate field shall hold 48000.0 for > + native sample rates of 96 and 192 kHz. In the > + case of unusual sample rates which do not have > + an expressible regular division, the maximum value > + of 65535.0 Hz should be used. */ > + rate = track->par->sample_rate; > + while (rate > UINT16_MAX && (rate & 1) == 0) { > + rate = rate >> 1; > + } > + if (rate > UINT16_MAX) { > + rate = UINT16_MAX; > + } > + } else { > + rate = track->par->sample_rate <= UINT16_MAX ? > + track->par->sample_rate : 0; > + } > + avio_wb16(pb, rate); > + } > avio_wb16(pb, 0); /* Reserved */ > } > > -- > 2.11.0 (Apple Git-81) _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel