本文写于17年,FFMpeg 版本是3.0,demo在我的github可见:FFmpeg_decoder
av_registerall();
avformart_network_init();
AVDictionary *opts = NULL;
av_dict_set(&opts,"rtsp_transport","udp",0);
av_dict_set(&opts,"max_delay","0.3",0);//av_dict_set函数是实现将字典进行赋值操作的方式
if (avformat_open_input(&pFormartContext, [url UTF8String], inputFormart, &opts)!=0) {
NSLog(@"打开文件路径失败");
return nil;
}
if(avformart_find_stream(pFormartContext,&opt)<0){
NSLog(@"解码失败,拿不到formart信息");
//其实在avformart 操作的时候已经进行了一部分的解码操作
return;
}
videoStream=-1;
for(int i=0,i<pFormartContext->nb_streams;i++){
if(pFormartContext->streams[i]->codecpar->codec_type==AVMEDIA_TYPE_VIDEO){
videoStream=i;
//在这里找到需要的视频流AVStream
}
}
if(videoStream=-1){
NSLog(@"上下文中不包含视频流");
return;
}
pcodecPar=pFormartConetext->streams[videoStream]->codecpar;//AVCodecParameters 是新的ffmp