zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    JS第一次课
    第四课:盒子模型+浮动+定位
    第三课:CSS
    第二课:HTML和CSS
    第一节课!HTML
    大家好
    MVC5 Views文件夹访问不了css,js
    数据挖掘之关联分析七(非频繁模式)
    数据挖掘之关联分析六(子图模式)
    数据挖掘之关联分析五(序列模式)
  • 原文地址:https://www.cnblogs.com/wanggang123/p/6346787.html
Copyright © 2011-2022 走看看