[FFmpeg-devel] [PATCH 1/2] examples: demuxing: do partial audio packet decoding

Stefano Sabatini stefasab at gmail.com
Sun Jul 14 17:38:40 CEST 2013


On date Sunday 2013-07-14 11:52:00 +0200, Reimar Döffinger encoded:
> On Sun, Jul 14, 2013 at 11:43:46AM +0200, Stefano Sabatini wrote:
> > On date Saturday 2013-07-13 15:53:19 +0200, wm4 encoded:
> > > This assumes one audio packet is decoded one time. This is not true:
> > > packets can be partially decoded. Then you have to "adjust" the packet
> > > and pass the undecoded part of the packet to the decode function again.
> > > ---
> > >  doc/examples/demuxing.c | 19 ++++++++++++++++---
> > >  1 file changed, 16 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/doc/examples/demuxing.c b/doc/examples/demuxing.c
> > > index 8a1b69b..1c0f1ff 100644
> > > --- a/doc/examples/demuxing.c
> > > +++ b/doc/examples/demuxing.c
> > > @@ -60,6 +60,7 @@ static int audio_frame_count = 0;
> > >  static int decode_packet(int *got_frame, int cached)
> > >  {
> > >      int ret = 0;
> > > +    int decoded = pkt.size;
> > 
> > After re-reading the docs, avcodec_decode_video2 should return the
> > consumed bytes as well, so we can assume that ret will contain
> > pkt.size after decoding.
> 

> NO! Maybe you meant the right thing, but "consumed bytes" can be
> less than pkt.size, e.g. if there is garbage/padding or multiple
> frames in one packet.

>From the docs:
avcodec_decode_video2():
@return On error a negative value is returned, otherwise the number of bytes
used or zero if no frame could be decompressed.

It is not really clear what is "used" in this context, also in case
the data is used but no frame is returned it will return 0, even if
the data was indeed "consumed" by the decoder.

[...]
-- 
FFmpeg = Frightening & Fundamental Meaningless Patchable Ermetic Glue


More information about the ffmpeg-devel mailing list