hi all. i'm one of developer which using ffmpeg to write program.
problem is that it always fails that try to decode png file.
with few experience, i found some weird bug. i hope it it my mistake.
here's the code.
-------------------------------------------------------------------------------------------------------------------------------
int imageToFrame(const char* fileName, const int& width, const int&
height, AVFrame** frame)
{
AVFormatContext* pFormatContext = NULL;
AVCodecContext* pCodecContext = NULL;
bool gotCodecContext = false;
AVFrame* rawFrame = NULL;
// No Problem
if(avformat_open_input(&pFormatContext, fileName, NULL, NULL) < 0
|| pFormatContext == NULL)
{
return 1;
}
// This is Problem!
/*
if(avformat_find_stream_info(pFormatContext, NULL) < 0)
{
return 1;
}
*/
for(unsigned int index=0; index<pFormatContext->nb_streams; index++)
{
pCodecContext = pFormatContext->streams[index]->codec;
if(pCodecContext->codec_type == AVMEDIA_TYPE_VIDEO)
{
gotCodecContext = true;
break;
}
}
if(gotCodecContext == false)
{
return 2;
}
// No Problem
if(avcodec_open2(pCodecContext,
avcodec_find_decoder(pCodecContext->codec_id), NULL) < 0)
{
return 3;
}
rawFrame = av_frame_alloc();
if(rawFrame == NULL)
{
return 4;
}
AVPacket packet;
int gotFrame=0;
// NO Problem
while (av_read_frame(pFormatContext, &packet) >= 0)
{
if(packet.stream_index != 0) continue;
// Always gotFrame is 0 until remove avformat_find_stream_info
if(avcodec_decode_video2(pCodecContext, rawFrame, &gotFrame,
&packet) == 0 && gotFrame)
{
break;
}
}
-------------------------------------------------------------------------------------------------------------------------------
this is simple code that extract one frame from image file.
when i use avformat_find_stream_info function with AVFormatContext which
contain PNG file,
avcodec_decode_video2 is always fail to decode.
(return code is 0 but gotframe is always 0)
but it can decode from packet if i remove avformat_find_stream_info.
it appears only png file. jpg was no problem with decode even using
avformat_find_stream_info.
_______________________________________________
ffmpeg-devel mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel