enc_ctx->profile =FF_PROFILE_H264_MAIN ;
enc_ctx->time_base.den =
24;
enc_ctx->time_base.num = 1;
enc_ctx->gop_size = 8; /*
emit one intra frame every twelve frames at most */
enc_ctx->pix_fmt
= AV_PIX_FMT_YUV420P;
enc_ctx->max_b_frames =
0;
enc_ctx->has_b_frames = 0;
av_opt_set(enc_ctx->priv_data,
"preset", "slow", 0); ///
av_opt_set(enc_ctx->priv_data, "tune",
"zerolatency", 0);
enc_ctx->bit_rate = br ;
enc_ctx->rc_min_rate = br
;
enc_ctx->rc_max_rate = br ;
enc_ctx->bit_rate_tolerance =
br;
enc_ctx->rc_buffer_size =
br;
enc_ctx->rc_initial_buffer_occupancy =
enc_ctx->rc_buffer_size*3/4;
enc_ctx->rc_buffer_aggressivity =
(float)1.0;
enc_ctx->rc_initial_cplx =
0.5;
enc_ctx->i_quant_factor = -1;
基本设置,固定码率150k,enc_ctx->i_quant_factor默认为 -1,编码结果
[libx264 @ 005cbb40] frame I:38 Avg QP:36.34 size: 4044
[libx264 @
005cbb40] frame P:262 Avg QP:35.27 size: 339
I的质量比P还差。
ffmpeg中i_quant_factor的解释
/**
* qscale factor between P and I-frames
* If > 0 then
the last p frame quantizer will be used (q= lastp_q*factor+offset).
* If
< 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
* - encoding: Set by user.
* - decoding: unused
*/
float
i_quant_factor;
enc_ctx->i_quant_factor = -0.7;时:
[libx264 @ 006ecb40] frame I:38 Avg QP:36.11 size: 4067
[libx264 @
006ecb40] frame P:262 Avg QP:34.89 size: 337
enc_ctx->i_quant_factor = -1.4;时
[libx264 @ 0276cb40] frame I:38 Avg QP:35.34 size: 4439
[libx264 @
0276cb40] frame P:262 Avg QP:35.17 size: 280
enc_ctx->i_quant_factor = -2;时
[libx264 @ 02beda40] frame I:38 Avg QP:34.59 size: 4155
[libx264 @
02beda40] frame P:262 Avg QP:33.71 size: 323
默认值:1.40
修改I帧量化值相比P帧量化值的目标平均增量。越大的值会提高I帧的品质。
原因估计:应该是i_quant_factor 绝对值越大,I帧质量越好。还有猜测可能是码率不够,限制了I帧的比特数。
设置固定码率300k时:
[libx264 @ 016dbb40] frame I:38 Avg QP:29.21 size: 6367
[libx264 @
016dbb40] frame P:262 Avg QP:29.60 size: 622
ffmpeg,X264编码结果I帧QP比P帧还大,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/mlj318/p/3770349.html