[Libav-user] regarding libavcodec method - av_parser_parse2 usage
Alex Cohn
alexcohn at netvision.net.il
Mon Mar 5 14:40:57 CET 2012
On Fri, Mar 2, 2012 at 13:32, Shiju Sasi <sasishiju at gmail.com> wrote:
> Hi,
>
> I have a multi threaded video application using x264 and ffmpeg. In the
> decoding flow, I have a question on av_parser_parse2.
>
> I use it as below.
>
> int len = 0;
>
> len =
> av_parser_parse2(m_pDecoderParserContext,m_pCodecCtx,&avpkt.data,&avpkt.size,in_buf,
> in_buf_size,0,0,0);
>
>
>
> Here I get the return value len = in_buf_size. But the avpkt.data is not
> getting filled in. It gets zero, so is the avpkt.size
>
> To check if the error is due to the usage of AVPacket, I changed it to
>
>
>
> uint8_t* pOutBuf = new uint8_t[50000];
>
> memset(pOutBuf,5,50000);
>
> int iOutSize = 100;
>
> len =
> av_parser_parse2(m_pDecoderParserContext,m_pCodecCtx,&pOutBuf,&iOutSize_buf,
> in_buf_size,0,0,0);
>
>
>
> Here, av_parser_parse2 changed the '5' returned to all the pOutBuf locations
> to zero and the output size varable also got set as 0. I tried a uint8_t
> pointer without any memory allocated as well.
>
> Nothing gives me a valid output pointer, but in all cases, the parsing
> happens for the entire input variable ( as indicated by the return value of
> the function).
>
> Could any of you please give me more information on this?
>
> Thanks in advance,
> Shiju
The function returns the the number of bytes of the input bitstream
used. It's fine that for some while you will not receive valid packets
out of it. I don't know what kind of input stream you are using, but
it could contain quite a lot of header bytes that are necessary for
the codec context to be able to process the stream. In avcodec.h file
itself you can see an example of usage, which involves a loop:
while(in_len){
len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
in_data, in_len,
pts, dts, pos);
in_data += len;
in_len -= len;
if(size)
decode_frame(data, size);
}
It is normal to skip decode_frame() sometimes, when size is 0.
BR,
Alex
More information about the Libav-user
mailing list