您好,登錄后才能下訂單哦!
所使用的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);
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。