温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

ffplayer之video

发布时间:2020-07-02 21:18:39 来源:网络 阅读:721 作者:beizhong2501 栏目:编程语言

所使用的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; i<ic->nb_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);


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI