ffplayer之video
所使用的ffmpeg版本:3.2.4
网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了围场免费建站欢迎大家使用!
configuration: --disable-yasm --disable-ffmpeg --disable-ffprobe --disable-ffserver
SDL版本:2.0
实例代码放在如下路径:~/ffmpeg/tutorial/video
video.c代码罗列如下:
// Register all formats and codecs av_register_all();
这一句不废话。
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)){ }
SDL初始化。
// Open video file //这个地方为什么用ic这个简写呢?搞不明白,input context ? if(avformat_open_input(&ic, argv[1], NULL, NULL)!=0) return -1; // Couldn't open file // Retrieve stream information if(avformat_find_stream_info(ic, NULL)<0) return -1; // Couldn't find stream information // Dump information about file onto standard error av_dump_format(ic, 0, argv[1], 0); // Find the first video stream videoStream = -1; for(i=0; inb_streams; i++) { if(AVMEDIA_TYPE_VIDEO == ic->streams[i]->codecpar->codec_type) { videoStream = i; break; } } if(videoStream == -1) { return -1; // Didn't find a video stream } // Find the decoder for the video stream pCodec = avcodec_find_decoder(ic->streams[videoStream]->codecpar->codec_id); if(pCodec == NULL) { fprintf(stderr, "Unsupported codec!\n"); return -1; // Codec not found } AVCodecParameters * pCodecCtxPar = ic->streams[videoStream]->codecpar; pCodecCtx = avcodec_alloc_context3(pCodec); avcodec_parameters_to_context(pCodecCtx, pCodecCtxPar); // Open codec if(avcodec_open2(pCodecCtx, pCodec, &optionsDict)<0) return -1; // Could not open codec // Allocate video frame pFrame = av_frame_alloc(); AVFrame* pFrameYUV = av_frame_alloc(); if( pFrameYUV == NULL ) return -1; screen = SDL_CreateWindow("My Game Window", 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: could not set video mode - 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); int numBytes = av_p_w_picpath_get_buffer_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height,1);
当前名称:ffplayer之video
本文URL:http://myzitong.com/article/jjdjjg.html