[Libav-user] avcodec_decode_video2 got_picture_ptr Differing Behaviour (FFMpeg Version 2.8)

Whiz Kid whizkid667 at gmail.com
Sun Nov 15 11:06:22 CET 2015


Am Currently updating our FFMPEG library usage from a pretty old
version(0.5) to 2.8. As part of the change, had replaced
avcodec_decode_video to avcodec_decode_video2. However, am noticing quite a
difference in the way avcodec_decode_video2 functions compared to the old
avcodec_decode_video. For the same packet (same data),
'avcodec_decode_video2' gives got_picture_ptr as zeo whereas the old
'avcodec_decode_video' was giving a non-zero value. In the example that am
describing here, am decoding an FLV file with VideoCodec:H264-MPEG-4 AVC
(part 10) and AudioCodec:MPEG AAC Audio (I have uploaded a part of the Hex
Version of the FLV file Link :
https://drive.google.com/file/d/0B3tyQGRngqX-Zy02OVVnU1NuNUk/view?usp=sharing).
For the first AVPacket (obtained from av_read_frame), got_picture_ptr from
'avcodec_decode_video2' is zero but old 'avcodec_decode_video' gives 296(I
have uploaded the entire AVPacket data obtained and the outputs obtained
from the two functions Link:
https://drive.google.com/file/d/0B3tyQGRngqX-STF6TkhWN3JyM0k/view?usp=sharing).
Continuing on, the new 'avcodec_decode_video2' keeps giving 'Zero' till the
23rd Packet where it gives 1. So its not like avcodec_decode_video2 keeps
giving zero. My main dilemma is that am not sure if this difference in
behaviour is due to the changes in 'avcodec_decode_video2' or any errors
that I have made in using the Decoder. I have put a snippet of the code
that am using to query the decoder below. Any suggestions will be helpful.

Thanks in Advance

[Code]
AVFormatContext *pFormatCtx;
AVCodecContext  *pCodecCtx;
AVCodec         *pCodec;
AVFrame *pFrameRGB;
#if FFMPEG_2_8
avformat_open_input(&pFormatCtx, strFileName, NULL, NULL) ;
#else
av_open_input_file(&pFormatCtx, strFileName, NULL, 0, NULL) ;
#endif //FFMPEG_2_8

size_t videoStream=pFormatCtx->nb_streams;
bool streamFound = false ;
for(size_t i=0; i<pFormatCtx->nb_streams; i++)
{
#if FFMPEG_2_8
if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
#else
if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
#endif //FFMPEG_2_8
{
videoStream = i;
streamFound = true ;
break;
}
}

if(streamFound)
{
pCodecCtx=pFormatCtx->streams[videoStream]->codec;

// Find the decoder for the video stream
pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
if(pCodec==NULL)
return false; // Codec not found

// Open codec
#if FFMPEG_2_8
if(avcodec_open2(pCodecCtx, pCodec,NULL)<0)
#else
if(avcodec_open(pCodecCtx, pCodec)<0)
#endif //FFMPEG_2_8
{
return false; // Could not open codec
}
#if FFMPEG_2_8
pFrameRGB=av_frame_alloc() ;
#else
pFrameRGB=avcodec_alloc_frame();
#endif //FFMPEG_2_8
if(pFrameRGB==NULL)
return false; //No Memory
while(true)
{
AVPacket packet ;
if (av_read_frame(pFormatCtx, &packet) < 0)
{
break ;
}

int frameFinished;
if (packet.stream_index == videoStream)
{
#if FFMPEG_2_8
avcodec_decode_video2(pCodecCtx, pFrameRGB, &frameFinished, &packet);
#else
avcodec_decode_video(pCodecCtx, pFrameRGB, &frameFinished, packet.data,
packet.size);
#endif //FFMPEG_2_8
}
if(frameFinished !=0)
{
break ;
}
}
}
[/Code]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20151115/b9231587/attachment.html>


More information about the Libav-user mailing list