[FFmpeg-devel] [PATCH/RFC] fix mp3 in wmv/wav for itunes and wmp

Michael Niedermayer michaelni
Fri Oct 10 15:10:20 CEST 2008


On Thu, Oct 09, 2008 at 07:36:50PM -0700, Baptiste Coudurier wrote:
> Hi,
>
> 2 patches:
>
> itunes_mp3_wav.patch, sets nBlockSize correctly according to specs:
> http://msdn.microsoft.com/en-us/library/cc307970(VS.85).aspx
> "nBlockSize
> Block size in bytes. This value equals the frame length in bytes x 
> nFramesPerBlock. For MP3 audio, the frame length is calculated as follows: 
> 144 x (bitrate / sample rate) + padding."
>
> This fixes mp3 in wav iTunes playback.
>
> This seems to not take mpeg2 audio into account though which would have a 
> 576 samples frame (144 == 1152 / 8)
>
> Set nCodecDelay to 0 instead of a weird value ? Quoting specs:
> "nCodecDelay
> Encoder delay in samples. If you do not know this value, set this structure 
> member to zero."
>
> Hunk can be splitted if wanted.
>
> wmv_mp3.patch, set blkalign to 1 for wmv, which fixes wmp playback, if set 
> to something else wmp chokes and says file is corrupted.
>
> Quoting MPEG1WAVEFORMAT specs:
> http://msdn.microsoft.com/en-us/library/ms787304(VS.85).aspx
> "nBlockAlign	
> For audio streams with a fixed audio frame length, this field specifies the 
> length of the audio frame. If the frame length is variable, set this field 
> to 1.
> If the sampling frequency is 32 kHz or 48 kHz and the bit rate is constant, 
> the audio frame size is constant. In that case, calculate nBlockAlign as 
> follows:
> Layer 1: 4 * (int)(12 * bitrate / sampling frequency)
> Layers 2 and 3: (int)(144 * bitrate / sampling frequency)
> If the bit rate is variable or the sampling frequency is 44.1 kHz, the 
> audio frame size is not constant and nBlockAlign should be 1.
> "
>
> It seems term frame length is weirdly used in their specifications, however 
> I think it refers to frame byte size.
>
> Based on this, it seems for .avi it really needs to be computed this way 
> otherwise wmp does not play video in sync.
>
> I tested mp2,mp3 in wav,wmv,avi against wmp, vlc and ffplay.
> mp2 in wmv does not play, saying codec is needed (???) while it plays fine 
> in .avi
>
> Michael, you did change value to frame size in which situation ?
> Because setting to frame size or calculate it this way (like in wma2 
> encoder btw) seems to make no difference.
>
> It seems .mkv uses put_wav_header too and I don't know if behaviour is .avi 
> or .wmv one, I can't get mp3 in wav work in vlc, however it works in 
> itunes, ffplay, wmp.
>
> I understand these modifications are delicate and I'd like comments and 
> suggestions.

my first and preliminary comment (i need to investigate this more fully)
is that mp3 can be (and often is) VBR, in vbr enc->bit_rate has pretty much
no meaning, and setting headers based on it likely is not correct.
Also ffmpeg does always assume VBR for mp3, thats also because in general
ffmpeg does not know if something will be CBR till the file end for
-acodec copy.

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The educated differ from the uneducated as much as the living from the
dead. -- Aristotle 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20081010/d35451f6/attachment.pgp>



More information about the ffmpeg-devel mailing list