ffplayer之video
所使用的ffmpeg版本:3.2.4
configuration: --disable-yasm --disable-ffmpeg --disable-ffprobe --disable-ffserver
SDL版本:2.0
实例代码放在如下路径:~/ffmpeg/tutorial/video
video.c代码罗列如下:
//Registerallformatsandcodecsav_register_all();
这一句不废话。
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER)){}
SDL初始化。
//Openvideofile//这个地方为什么用ic这个简写呢?搞不明白,inputcontext?if(avformat_open_input(&ic,argv[1],NULL,NULL)!=0)return-1;//Couldn'topenfile//Retrievestreaminformationif(avformat_find_stream_info(ic,NULL)<0)return-1;//Couldn'tfindstreaminformation//Dumpinformationaboutfileontostandarderrorav_dump_format(ic,0,argv[1],0);//FindthefirstvideostreamvideoStream=-1;for(i=0;i<ic->nb_streams;i++){if(AVMEDIA_TYPE_VIDEO==ic->streams[i]->codecpar->codec_type){videoStream=i;break;}}if(videoStream==-1){return-1;//Didn'tfindavideostream}//FindthedecoderforthevideostreampCodec=avcodec_find_decoder(ic->streams[videoStream]->codecpar->codec_id);if(pCodec==NULL){fprintf(stderr,"Unsupportedcodec!\n");return-1;//Codecnotfound}AVCodecParameters*pCodecCtxPar=ic->streams[videoStream]->codecpar;pCodecCtx=avcodec_alloc_context3(pCodec);avcodec_parameters_to_context(pCodecCtx,pCodecCtxPar);//Opencodecif(avcodec_open2(pCodecCtx,pCodec,&optionsDict)<0)return-1;//Couldnotopencodec//AllocatevideoframepFrame=av_frame_alloc();AVFrame*pFrameYUV=av_frame_alloc();if(pFrameYUV==NULL)return-1;screen=SDL_CreateWindow("MyGameWindow",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,pCodecCtx->width,pCodecCtx->height,/*SDL_WINDOW_FULLSCREEN|*/SDL_WINDOW_OPENGL);SDL_Renderer*renderer=SDL_CreateRenderer(screen,-1,0);if(!screen){fprintf(stderr,"SDL:couldnotsetvideomode-exiting\n");exit(1);}bmp=SDL_CreateTexture(renderer,SDL_PIXELFORMAT_YV12,SDL_TEXTUREACCESS_STREAMING,pCodecCtx->width,pCodecCtx->height);sws_ctx=sws_getContext(pCodecCtx->width,pCodecCtx->height,pCodecCtx->pix_fmt,pCodecCtx->width,pCodecCtx->height,AV_PIX_FMT_YUV420P,SWS_BILINEAR,NULL,NULL,NULL);intnumBytes=av_p_w_picpath_get_buffer_size(AV_PIX_FMT_YUV420P,pCodecCtx->width,pCodecCtx->height,1);
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。