1、注册所有文件格式和解码器
av_register_all();
2、读取输入文件头,设置null自动检测格式
avformat_open_input(&pFormatCtx,argv[1],NULL,NULL) ;
3、获取流信息
avformat_find_stream_info(pFormatCtx,NULL);
4、寻找第一条视频流
videoStream =av_find_best_stream(pFormatCtx,AVMEDIA_TYPE_VIDEO,-1,-1,pCodec,0);
早期的版本没有这个函数,可以使用以下方式寻找:
for(i=0;i<pFormatCtx->nb_streams;i++)
{
if(pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
{
videoStream =i;
break;
}
}
<