[Libav-user] avcodec_decode_video2 missing the first 8 frames
nfxjfg at googlemail.com
Wed Jul 23 01:11:16 CEST 2014
On Tue, 22 Jul 2014 16:40:22 -0400
Matt Orlando <morlando616 at gmail.com> wrote:
> So this tutorial looks like it's covering 2 things that I don't do within
> my plugin, which is great news since the answer is somewhere within!
> Unfortunately, I'm a bit confused with some things from the tutorial.
> Can anyone explain this to me, and/or perhaps provide a more legible code
> example (c++ / c#)?
> // we need to make a copy of videoStream->codec->extradata and give it
> to the context
> // make sure that this vector exists as long as the avVideoCodec exists
> std::vector codecContextExtraData(stream->codec->extradata,
> stream->codec->extradata + stream->codec->extradata_size);
> avVideoCodec->extradata = reinterpret_cast(codecContextExtraData.data());
> avVideoCodec->extradata_size = codecContextExtraData.size();
This is completely wrong. Extradata needs alignment and input padding.
Whether or not this actually can cause problems, I don't know.
But, the explanation is: you need to pass some codec headers from
libavformat codec context to the decoder codec context. This includes
the extradata, and some other fields (like width and height). Look what
fields are marked as "set by user" for decoding.
> The other part I don't understand is what he's doing with the offsetInData
> variable. I'm almost definitely misunderstanding his usage, but it looks
> as though he's increasing packet.packet.Data by this ever-growing
> offsetInData. So hypothetically, if he had a 3 hour movie, that
> offsetInData would be enormous! How could his packet.packet.Data array be
> large enough to shift the pointer by that amount? I also don't understand
> why he's only reading (through the reset function of his packet) if that
> offsetInData is larger than the packet size.
AFAIK this is not needed for video at all, just audio.
> Both of these things confuse me...and both of these things I need to
> implement. If anyone can explain any/all of this in as much detail as
> possible, I'd be forever grateful. I've got a terrible deadline to hit and
> I simply need this to work. Thank you sincerely for the help, folks!
More information about the Libav-user