[Libav-user] About audio decoding

Nicolas George nicolas.george at normalesup.org
Sat Aug 10 16:32:14 CEST 2013


Le tridi 23 thermidor, an CCXXI, Lucas Soltic a écrit :
> Hello,
> However, there is one part of the audio decode example that I do not
> understand:
> if (avpkt.size < AUDIO_REFILL_THRESH) {
>     /* Refill the input buffer, to avoid trying to decode
>      * incomplete frames. Instead of this, one could also use
>      * a parser, or use a proper container format through
>      * libavformat. */
>     memmove(inbuf, avpkt.data, avpkt.size);
>     avpkt.data = inbuf;
>     len = fread(avpkt.data + avpkt.size, 1,
>                 AUDIO_INBUF_SIZE - avpkt.size, f);
>     if (len > 0)
>         avpkt.size += len;
> }
> 
> Does that mean that AVPacket can contain incomplete frames? I would have
> expected an AVPacket to contain one or several frames, but not incomplete
> ones…

Depends on what "can" you mean exactly.

If you read a file using libavformat, the packets it returns are supposed to
always contain exactly one frame, and never incomplete ones. In that sense,
a packet can not contain incomplete frames.

But if you give a packet with incomplete frames to libavcodec, it will
decode what can be decoded, return the number of bytes consumed and properly
leave the incomplete frame for later. In that sense, a packet can contain
incomplete frames.

> I also do not understand what the 'parser' and 'proper container format'
> solutions would be.

Look at what the code in the example does: it uses stdio to read directly
from a MP2 file. A proper container format is a file format designed to
store various streams in various codecs, such as Matroska, Ogg, NUT, MP4,
AVI, etc. The format has generic data structures to delimit packets and
store timestamps. That is the best way of storing audio-video content.

Some formats are just the packets concatenated together, without any header
or delimiter. It is called an elementary stream, and does not work with all
codecs. For example, it works with most MPEG codecs, but usually not with
the Vorbis codecs. A parser is a stripped-down decoder that is used to find
packet boundaries and various additional information in an elementary
stream; libavformat uses them for you whenever necessary.

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130810/104f0b04/attachment.asc>


More information about the Libav-user mailing list