Opened 4 months ago

Last modified 4 months ago

#6609 open defect

SamplingRateBox should be used if the value is greater than INT16_MAX

Reported by: fbeaufort Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: mov
Cc: jya@mozilla.com Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:

SamplingRateBox? should be used if the value is greater than INT16_MAX

How to reproduce:

  1. Grab file from https://storage.googleapis.com/media-session/bear-1280x720.mp4
  2. Run ffmpeg command below
    % ffmpeg -i bear-1280x720.mp4 -map 0:0 -acodec flac -strict -2 -ar 192000 bear-flac-192kHz.mp4
    
  3. The bear-flac-192kHz.mp4 file should have a valid sample rate, not 0.

Here are some #ffmpeg logs for some context:

12:58:08 PM <jya> you can create a bug that the SamplingRateBox (as per ISO 14496-2 12.2.3.2) is to be used if the value is greater than INT16_MAX
12:59:14 PM <jya> they have provision for that inthe SoundDescription V2, but i can't find this anywhere in the spec
12:59:20 PM <jya> must be a QT thing
1:00:14 PM <jya> and if they properly create a SamplingRateBox, need to file a bug in Firefox that our mp4 demuxer doesn't support it :)

And here's the ffmpeg version:

% ffmpeg -version
ffmpeg version 3.3.3-static http://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2017 the FFmpeg developers

Attachments (1)

0001-Properly-store-sampling-rate-for-FLAC-in-mp4.patch (2.1 KB) - added by jyavenard 4 months ago.

Download all attachments as: .zip

Change History (10)

comment:1 follow-up: Changed 4 months ago by cehoyos

  • Component changed from ffmpeg to avformat
  • Keywords mov added; flac isobmff mp4 removed

Is this issue only reproducible with flac encoding?

Please test current FFmpeg git head (nothing else is supported here) and provide a command line that allows to reproduce the issue together with the complete, uncut console output.

comment:2 Changed 4 months ago by jyavenard

  • Component changed from avformat to ffmpeg
  • Keywords flac isobmff mp4 added; mov removed

As present, ffmpeg if MODE_MOV is set, and a sampling rate greater thant UINT16_MAX, can generate a .mov with SoundDescription? that would be using a 64 bits float for sampling rate.

For a mp4 (as defined in ISO 14496-12 12.2.3.2), it should be using a AudioSampleEntryV1 defined as follow:

class AudioSampleEntryV1(codingname) extends SampleEntry (codingname){ 
   unsigned int(16) entry_version;  // must be 1,  
                              //   and   must   be   in   an   stsd   with   version   ==1   
   const unsigned int(16)[3] reserved = 0; 
   template unsigned int(16) channelcount;  // must be correct 
   template unsigned int(16) samplesize = 16; 
   unsigned int(16) pre_defined = 0; 
   const unsigned int(16) reserved = 0 ; 
   template unsigned int(32) samplerate = 1<<16; 
   // optional boxes follow 
   SamplingRateBox();   
   ChannelLayout();   
   // we permit any number of DownMix or DRC boxes: 
   DownMixInstructions()   [];   
   DRCCoefficientsBasic()   [];   
   DRCInstructionsBasic()   [];   
   DRCCoefficientsUniDRC()   [];   
   DRCInstructionsUniDRC()   [];   
   Box ();     // further boxes as needed 
}

The samplerate would then be 65536 and there would be a SamplingRateBox?

aligned(8) class SamplingRateBox extends FullBox(‘srat’) { 
   unsigned int(32) sampling_rate; 
} 

FFmpeg when generating a mp4 and if the sampling rate is greater than 65535, always write 0 as the sampling rate.
see https://github.com/FFmpeg/FFmpeg/blame/5f4e555dc7caea343838e9f6f218525bb80216bf/libavformat/movenc.c#L974

Expected:
It should instead use a AudioSampleEntryV1 and a SamplingRateBox? (srat)

For related bug, I've lodged gecko's bug 1393045 (https://bugzilla.mozilla.org/show_bug.cgi?id=1393045) and bug 1393039 (https://bugzilla.mozilla.org/show_bug.cgi?id=1393039)

comment:3 Changed 4 months ago by jyavenard

  • Component changed from ffmpeg to avformat

comment:4 in reply to: ↑ 1 Changed 4 months ago by jyavenard

Replying to cehoyos:

Is this issue only reproducible with flac encoding?

Please test current FFmpeg git head (nothing else is supported here) and provide a command line that allows to reproduce the issue together with the complete, uncut console output.

The issue can be reproduced with any codec. So long as you attempt to create a mp4 with a sampling rate >= 65536

The AudioSampleEntry? (version 0) that ffmpeg uses, only have a 16 bits field to store sampling rate, so can't use more. and so it writes 0

comment:5 Changed 4 months ago by jyavenard

the command line to use is provided in the bug description. It's the same as in ffmpeg (master branch)
You don't have to use the same input, and file will do.
It's the -ar 192000 that causes the problem.

comment:6 Changed 4 months ago by jyavenard

jyapro:ffmpeg jyavenard$ build.master/bin/ffmpeg -i bear-1280x720.mp4 -movflags frag_keyframe+empty_moov -map 0:0 -acodec flac -strict -2 -ar 192000 bear-flac-192kHz.mp4
ffmpeg version N-87034-geca2a49716 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 8.1.0 (clang-802.0.42)
  configuration: --enable-debug --disable-shared --prefix=build.master
  libavutil      55. 74.100 / 55. 74.100
  libavcodec     57.103.100 / 57.103.100
  libavformat    57. 76.100 / 57. 76.100
  libavdevice    57.  7.101 / 57.  7.101
  libavfilter     6.100.100 /  6.100.100
  libswscale      4.  7.102 /  4.  7.102
  libswresample   2.  8.100 /  2.  8.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'bear-1280x720.mp4':
  Metadata:
    major_brand     : M4V 
    minor_version   : 1
    compatible_brands: isomavc1M4V mp42
    creation_time   : 2010-01-07T23:51:02.000000Z
  Duration: 00:00:02.76, start: 0.023220, bitrate: 2074 kb/s
    Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 72 kb/s (default)
    Metadata:
      creation_time   : 2010-01-07T23:51:02.000000Z
      handler_name    : GPAC ISO Audio Handler
    Stream #0:1(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 2010 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 2010-01-07T23:51:02.000000Z
      handler_name    : bear.264 - Imported with GPAC 0.4.6-DEV (build 1 - Sep 20 2009) - compiled by Kurtnoise
Stream mapping:
  Stream #0:0 -> #0:0 (aac (native) -> flac (native))
Press [q] to stop, [?] for help
[flac @ 0x7feca7004800] encoding as 24 bits-per-sample
Output #0, mp4, to 'bear-flac-192kHz.mp4':
  Metadata:
    major_brand     : M4V 
    minor_version   : 1
    compatible_brands: isomavc1M4V mp42
    encoder         : Lavf57.76.100
    Stream #0:0(und): Audio: flac (fLaC / 0x43614C66), 192000 Hz, stereo, s32 (24 bit), 128 kb/s (default)
    Metadata:
      creation_time   : 2010-01-07T23:51:02.000000Z
      handler_name    : GPAC ISO Audio Handler
      encoder         : Lavc57.103.100 flac
size=     325kB time=00:00:02.73 bitrate= 973.1kbits/s speed=65.2x    
video:0kB audio:324kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.348056%

comment:7 Changed 4 months ago by cehoyos

  • Keywords mov added; flac isobmff mp4 removed
  • Status changed from new to open
  • Version changed from unspecified to git-master

Don't you both agree that using flac to show an issue with the mp4 muxer is at least unusual (as strict -2 proves)?

comment:8 Changed 4 months ago by fbeaufort

We happened to stumble upon this issue as we were setting a sample rate of 192kHz which can happens for Flac in MP4.

comment:9 Changed 4 months ago by fbeaufort

cehoyos what do you think of jyavenard's patch?

Note: See TracTickets for help on using tickets.