ffmpeg 编解码 码率设置问题 CBR 、VBR

之前都是利用硬件进行视频流的编解码

最近 在利用ffmpeg 编解码在CPU上进行软解软编码

之前别的硬件平台设置码率和vbr cbr的时候 提供了接口直接设置一下就可以

但是ffmpeg这里 并没有直接提供这样的接口

网上搜了很多  比如下面这个:

	av_opt_set(encoder->av_encode_ctx->priv_data, "preset", "superfast", 0);
		//av_opt_set(encoder->av_encode_ctx->priv_data, "tune", "zerolatency", 0);
		av_opt_set(encoder->av_encode_ctx->priv_data, "nal-hrd", "cbr", 0);
		//av_opt_set(encoder->av_encode_ctx->priv_data, "crf", "51", AV_OPT_SEARCH_CHILDREN);
			
		encoder->av_encode_ctx->rc_min_rate = bitrate;
		encoder->av_encode_ctx->rc_max_rate = bitrate;
		encoder->av_encode_ctx->rc_buffer_size = bitrate*2 ;
		encoder->av_encode_ctx->bit_rate = bitrate;
		//encoder->av_encode_ctx->bit_rate_tolerance = bitrate;
		//encoder->av_encode_ctx->rc_initial_buffer_occupancy = encoder->av_encode_ctx->rc_buffer_size*3/4;


		encoder->av_encode_ctx->refs = 2;


		encoder->av_encode_ctx->me_range = 16;
		encoder->av_encode_ctx->max_qdiff = 4;
		encoder->av_encode_ctx->qmin = 10;
		encoder->av_encode_ctx->qmax = 51;
		encoder->av_encode_ctx->qcompress = 0.6;

		encoder->av_encode_ctx->qblur = 0.0;
		
		encoder->av_encode_ctx->spatial_cplx_masking = 0.3;

		
		encoder->av_encode_ctx->me_pre_cmp = 2;
		encoder->av_encode_ctx->b_quant_factor = 1.25;
		

		encoder->av_encode_ctx->b_quant_offset = 1.25;
		encoder->av_encode_ctx->i_quant_factor = 0.8;
		encoder->av_encode_ctx->i_quant_offset = 0.0;
		encoder->av_encode_ctx->dct_algo = 0;
		
		encoder->av_encode_ctx->mb_lmin = 1;
		encoder->av_encode_ctx->mb_lmax = 5;

		 encoder->av_encode_ctx->lumi_masking = 0.0;
		 encoder->av_encode_ctx->dark_masking = 0.0;

		encoder->av_encode_ctx->global_quality = 10;
		encoder->av_encode_ctx->qblur = 0;
		encoder->av_encode_ctx->spatial_cplx_masking =0.3f;
		encoder->av_encode_ctx->dct_algo =0;

这个证明不行 

包括网上有个什么聊天记录的 那个 试了也不行 (也许他用的是老版本吧  反正我的试了不行4.3.2版本)

后来 同事给了一个 ffmpeg推流 码率能设置的参数 如下

ffmpeg -rtsp_transport tcp -r 25 -i rtsp://uer:gd123456@192.168.2.121:554/Streaming/Channels/101 -an -vcodec libx264 -g 30 -crf 30 -strict -2 -s 600*400 -preset faster -profile:v main -x264-params bitrate=300 -sc_threshold 1000000000 -f flv rtmp://192.168.35.75:1987/live/qmcy1111

然后分析 ffmpeg.c文件  百度 google  

最终发现如下方式 可以设置可以实现 CBR方式 

别的都没用 

这么一行就可以  结果很简单  探索的过程 确相当坎坷 。。。。。。。。。

  哎 !!!!!!!!!!!!!!!!

 明天试试VBR 怎么搞

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

QMCY_jason

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值