【发布时间】:2015-11-14 01:36:56
【问题描述】:
我目前正在将我们的 FFMPEG 库使用从相当旧的版本 (0.5) 更新到 2.8。作为更改的一部分,已将 avcodec_decode_video 替换为 avcodec_decode_video2。但是,与旧的 avcodec_decode_video 相比,我注意到 avcodec_decode_video2 的功能方式存在很大差异。对于相同的数据包(相同的数据),'avcodec_decode_video2' 给出 got_picture_ptr 作为 zeo,而旧的 'avcodec_decode_video' 给出一个非零值。在此处描述的示例中,我使用 VideoCodec:H264-MPEG-4 AVC(第 10 部分)和 AudioCodec:MPEG AAC 音频(我在 FLV_Sample.Hex 中附加了 FLV 文件的十六进制版本的一部分 @ 987654321@)。原来的 flv 文件太大)。对于第一个 AVPacket(从 av_read_frame 获得),来自 'avcodec_decode_video2' 的 got_picture_ptr 为零,但旧的 'avcodec_decode_video' 给出 296(我将获得的整个 AVPacket 数据和从文件 FFMPEG_Decoding_Packet_Info.txt FFMPEG_Decoding_Packet_Info 中的两个函数获得的输出附加在一起) .继续,新的“avcodec_decode_video2”一直给出“零”,直到第 23 个数据包给出 1。所以它不像 avcodec_decode_video2 一直给出零。我的主要困境是不确定这种行为差异是否是由于“avcodec_decode_video2”的变化或我在使用解码器时犯的任何错误。我在下面放置了用于使用解码器的代码的 sn-p。任何建议都会有所帮助。
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 ;
}
}
}
【问题讨论】:
标签: ffmpeg