ffmpeg H264 編解碼配置


ffmpeg H264編解碼前面有文章介紹下,本文主要介紹一些參數配置。

編碼:

int InitEncoderCodec( int iWidth, int iHeight)
{
	AVCodec *  pH264Codec = avcodec_find_encoder(AV_CODEC_ID_H264);
	if(NULL == pH264Codec)
	{
		printf("%s", "avcodec_find_encoder failed");
		return  -1;
	}
	outPutEncContext = avcodec_alloc_context3(pH264Codec);
	outPutEncContext->gop_size = 30;
	outPutEncContext->has_b_frames = 0;
	outPutEncContext->max_b_frames = 0;
	outPutEncContext->codec_id = pH264Codec->id;
	outPutEncContext->time_base.num = 2;
	outPutEncContext->time_base.den = 15;
	outPutEncContext->pix_fmt            = *pH264Codec->pix_fmts;
	outPutEncContext->width              =  iWidth;
	outPutEncContext->height             = iHeight;
	outPutEncContext->qmin = 34;
	outPutEncContext->qmax = 50;
	AVDictionary *options = nullptr;
	outPutEncContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; 
	av_opt_set(outPutEncContext->priv_data,"tune","zerolatency",0);
     av_dict_set(&options,"preset","ultrafast",0); int ret = avcodec_open2(outPutEncContext, pH264Codec, &options); if (ret < 0) { printf("%s", "open codec failed"); return ret; } return 1; }

  解碼:

codecContext->flags |=CODEC_FLAG_LOW_DELAY;

  

編碼codec 的time_base實際上表示視頻的幀率,qmin,qmax決定了編碼的質量,qmin,qmax越大編碼的質量越差。zerolatency參數的作用是提搞編碼的實時性。

解碼codec 加上CODEC_FLAG_LOW_DELAY,可提高解碼速度(低延時)。

QQ群:1038388075 

視頻教程 播放地址: http://www.iqiyi.com/u/1426749687

視頻下載地址:http://www.chungen90.com/?news_3/

 Demo下載地址: http://www.chungen90.com/?news_2


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM