[FFmpeg-devel] [PATCH]Fix AC3-in-avi for the remaining cases

Justin Ruggles justin.ruggles
Sun Jan 2 04:41:15 CET 2011


On 01/01/2011 10:14 PM, Michael Niedermayer wrote:

> On Sat, Jan 01, 2011 at 03:52:07PM -0500, Justin Ruggles wrote:
>> On 01/01/2011 03:03 PM, Carl Eugen Hoyos wrote:
>>
>>> Hi!
>>>
>>> Current svn produces avi files that don't playback on any player when muxing 
>>> AC3 with 32kHz/320kB, 32kHz/384kB and 44.1kHz/384kB.
>>> I believe Justin suggested to set blkalign to maximum frame size (first 
>>> patch).
>>> An alternative is to just fix the failing cases (second patch).
>>>
>>> Opinions?
>>>
>>> Please comment, Carl Eugen
>>>
>>>
>>
>>> Index: libavformat/riff.c
>>> ===================================================================
>>> --- libavformat/riff.c	(revision 26183)
>>> +++ libavformat/riff.c	(working copy)
>>> @@ -370,12 +370,10 @@
>>>          av_log(enc, AV_LOG_WARNING, "requested bits_per_coded_sample (%d) and actually stored (%d) differ\n", enc->bits_per_coded_sample, bps);
>>>      }
>>>  
>>> -    if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3 || enc->codec_id == CODEC_ID_AC3) {
>>> +    if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3) {
>>>          blkalign = enc->frame_size; //this is wrong, but it seems many demuxers do not work if this is set correctly
>>>          //blkalign = 144 * enc->bit_rate/enc->sample_rate;
>>> -        //For high bitrate AC-3, set blkalign to maximum bytes per frame value
>>> -        //to allow playback on WMP and MPlayer
>>> -        if (enc->bit_rate > 384000)
>>> +    } else if (enc->codec_id == CODEC_ID_AC3) {
>>>              blkalign = 3840;
>>>      } else if (enc->codec_id == CODEC_ID_ADPCM_G726) { //
>>>          blkalign = 1;
>>
>>
>> I like this version better.
>>
>> Regarding the other patch, if it would be better for some reason to use
>> a more accurate value for AC-3 we could do:
> 
> being exact when there is exactly just 1 packet size is nice, beyond that its
> a hack either way

Well, there is such thing as VBR AC-3 so using the maximum value for the
given sample rate is at least less of a hack.  The exact value can be
calculated if it is CBR.

>> switch (enc->sample_rate) {
>>      8000: blkalign =  960;
>>     11025: blkalign =  697;
>>     12000: blkalign =  640;
>>     16000: blkalign = 1920;
>>     22050: blkalign = 1394;
>>     24000: blkalign = 1280;
>>     32000: blkalign = 3840;
>>     44100: blkalign = 2788;
>>     48000: blkalign = 2560;
>> }
> 
> Is this how our encoder behaves or is this required by spec?


This is the maximum frame size (640 kbps) for AC-3 per spec and for our
encoder for each supported sample rate.  Well, the last 3 are per spec.
Technically the others don't have a spec, but they're supported by our
encoder, our decoder, liba52, and RealPlayer.

-Justin



More information about the ffmpeg-devel mailing list