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

Baptiste Coudurier baptiste.coudurier
Fri Oct 10 04:36:50 CEST 2008


2 patches:

itunes_mp3_wav.patch, sets nBlockSize correctly according to specs:
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:
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:
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 

Baptiste COUDURIER                              GnuPG Key Id: 0x5C1ABAAA
Smartjog USA Inc.                                http://www.smartjog.com
Key fingerprint                 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: itunes_mp3_wav.patch
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20081009/3ad9ef40/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: wmv_mp3.patch
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20081009/3ad9ef40/attachment.asc>

More information about the ffmpeg-devel mailing list