[MPlayer-dev-eng] Re: [PATCH] encoding audio with libavcodec
Arpi
arpi at thot.banki.hu
Sun Nov 2 16:23:55 CET 2003
Hi,
> > in both cases (ac3 and mp2) alavc_ctx->block_align is 0, so
> > mux_a->wf->nBlockAlign ens up being 1152 for mp2 and
> > 1536 for ac3; mp2 is in sync and ac3 not.
>
> It would be nice to have some unambigous information about how to fill
> these structures.
> Some software seems to set nBlockalign to 1, other to the Same as
> mp3.nBlockSize and the third to the number of samples in one block
> (alavc_ctx->frame_size). And Microsoft of course defines the fields as
> to be "computed according to manufacturer's specification" if the format
> tag is not pcm. So it may very well be, that we really need different
> cases for each format.
it's not so easy at all. but at least i know it :)
normally, that field is only for teh codec, ie. only the decoder will
care of it. so it depends on the codec.
but actually, the m$ directshow avi parser also cares of it, it
rounds up audio packet size to that value when calculating timestamp.
this trick is used for vbr mp3 streams, by setting blockalign to the
max possible compressed size (usually 1152 or so) and setting samplerate
to 44100/1152 (ro 48000/1152). so no matter how big a compressed frame
is, be it 200 byte or 870, the dshow parser will calculate timestamp
by (packet_no*1152) * (44100/1152). so it can be whatever value, but
- must be >= possible max compressed frame size (avi audio packet size)
- must be the same value as samplerate divisor
this is true for VBR streams.
for CBR, it may be 1 or any larger value, depending on codec
(it's 33 or 62 afair for adpcm, and for other block-based codecs,
1 for raw streamable/seekable formats like mpeg audio), assuming
that avi audio packet size is divisable by this value.
so, its' best setting to real compressed block size for CBR formats,
(where block size is constant anyway), or set it to 1 for mp3.
for vbr, set it to _uncompressed_ block size, and be sure that
the same value is used as samplerate divisor.
>
> As far as I understand it now (I made a few more tests), nBlockAlign is
> supposed to the size of the elementary blocks the codec can decode.
> That only works for cbr though.
yes
> The MS imaadpcm codec sets mux_a->h.dwScale = mux_a->h.dwSampleSize =
> mux_a->wf->nBlockAlign, which seems to work well for mp3 and ac3 too.
yes
> > 2) there's this assignment that I don't understand:
> >
> > mux_a->wf->wBitsPerSample = 0;
> >
> > shouldn't it be 16?
>
> Well, it's zero on all my avis and I guess it does make sense because we
> describe the compressed stream here.
yes
A'rpi / Astral & ESP-team
--
Developer of MPlayer G2, the Movie Framework for all - http://www.MPlayerHQ.hu
More information about the MPlayer-dev-eng
mailing list