OpenCV视频编码器参数修改

OpenCV版本

  • OpenCV 4.1.2

视频编码

  • h264视频编码参考代码,outputVideo.write(frame) 需要有视频raw数据;
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/imgproc.hpp>

int main(){
    // init
    cv::VideoWriter outputVideo;
    cv::Size S = cv::Size(width_output, height_output);
    int fourcc = cv::VideoWriter::fourcc('H','2','6','4');
    int fps = 25;
    outputVideo.open(output_file, fourcc, fps, S);
    
    // write frame
    outputVideo.write(frame);
    
    // deinit
    outputVideo.release();
    
    return 0;    
}

h264视频编码参数调整

  • 修改文件 master/modules/videoio/src/cap_ffmpeg_impl.hpp
#if LIBAVUTIL_BUILD > CALC_FFMPEG_VERSION(51,11,0)
    /* Some settings for libx264 encoding, restore dummy values for gop_size
     and qmin since they will be set to reasonable defaults by the libx264
     preset system. Also, use a crf encode with the default quality rating,
     this seems easier than finding an appropriate default bitrate. */
    if (c->codec_id == AV_CODEC_ID_H264) {
      c->gop_size = -1;
      c->qmin = -1;
      c->bit_rate = 0;
      if (c->priv_data)
          av_opt_set(c->priv_data,"crf","21", 0);
          av_opt_set(c->priv_data,"preset","faster", 0);
    }
#endif

上面的代码,修改了crf参数,23修改为21
添加了preset参数的设置;
大家可以参考一下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值