X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fx264_encoder.cpp;h=b38711cb571c3085b6dfb72436ba5eacff665956;hb=734a8b9f5d2baaadc3762b4abd25032898a2653b;hp=23a1359d70fc6083307dd456a1cd53889c30c290;hpb=8202dbe236c5e206989c383004f9dba116ea12bd;p=nageru diff --git a/nageru/x264_encoder.cpp b/nageru/x264_encoder.cpp index 23a1359..b38711c 100644 --- a/nageru/x264_encoder.cpp +++ b/nageru/x264_encoder.cpp @@ -60,24 +60,16 @@ void update_vbv_settings(x264_param_t *param) if (global_flags.x264_bitrate == -1) { return; } - if (global_flags.x264_vbv_buffer_size < 0) { - param->rc.i_vbv_buffer_size = param->rc.i_bitrate; // One-second VBV. - } else { - param->rc.i_vbv_buffer_size = global_flags.x264_vbv_buffer_size; - } - if (global_flags.x264_vbv_max_bitrate < 0) { - param->rc.i_vbv_max_bitrate = param->rc.i_bitrate; // CBR. - } else { - param->rc.i_vbv_max_bitrate = global_flags.x264_vbv_max_bitrate; - } + param->rc.i_vbv_buffer_size = param->rc.i_bitrate; // One-second VBV. + param->rc.i_vbv_max_bitrate = param->rc.i_bitrate; // CBR. } } // namespace -X264Encoder::X264Encoder(AVOutputFormat *oformat, bool use_separate_disk_params) +X264Encoder::X264Encoder(const AVOutputFormat *oformat, bool use_separate_disk_params) : wants_global_headers(oformat->flags & AVFMT_GLOBALHEADER), use_separate_disk_params(use_separate_disk_params), - dyn(load_x264_for_bit_depth(global_flags.x264_bit_depth)) + dyn(load_x264_for_bit_depth(global_flags.bit_depth)) { if (use_separate_disk_params) { call_once(x264_disk_metrics_inited, []{ @@ -107,7 +99,7 @@ X264Encoder::X264Encoder(AVOutputFormat *oformat, bool use_separate_disk_params) }); } - size_t bytes_per_pixel = global_flags.x264_bit_depth > 8 ? 2 : 1; + size_t bytes_per_pixel = global_flags.bit_depth > 8 ? 2 : 1; frame_pool.reset(new uint8_t[global_flags.width * global_flags.height * 2 * bytes_per_pixel * X264_QUEUE_LENGTH]); for (unsigned i = 0; i < X264_QUEUE_LENGTH; ++i) { free_frames.push(frame_pool.get() + i * (global_flags.width * global_flags.height * 2 * bytes_per_pixel)); @@ -152,7 +144,7 @@ void X264Encoder::add_frame(int64_t pts, int64_t duration, YCbCrLumaCoefficients free_frames.pop(); } - size_t bytes_per_pixel = global_flags.x264_bit_depth > 8 ? 2 : 1; + size_t bytes_per_pixel = global_flags.bit_depth > 8 ? 2 : 1; memcpy(qf.data, data, global_flags.width * global_flags.height * 2 * bytes_per_pixel); { @@ -179,7 +171,7 @@ void X264Encoder::init_x264() param.i_width = global_flags.width; param.i_height = global_flags.height; param.i_csp = X264_CSP_NV12; - if (global_flags.x264_bit_depth > 8) { + if (global_flags.bit_depth > 8) { param.i_csp |= X264_CSP_HIGH_DEPTH; } param.b_vfr_input = 1; @@ -190,7 +182,7 @@ void X264Encoder::init_x264() param.i_frame_reference = 16; // Because speedcontrol is never allowed to change this above what we set at start. } #if X264_BUILD >= 153 - param.i_bitdepth = global_flags.x264_bit_depth; + param.i_bitdepth = global_flags.bit_depth; #endif // NOTE: These should be in sync with the ones in quicksync_encoder.cpp (sps_rbsp()). @@ -212,16 +204,11 @@ void X264Encoder::init_x264() } else { param.rc.i_rc_method = X264_RC_ABR; param.rc.i_bitrate = bitrate; - } - if (!use_separate_disk_params) { - update_vbv_settings(¶m); - } - if (param.rc.i_vbv_max_bitrate > 0) { - // If the user wants VBV control to cap the max rate, it is - // also reasonable to assume that they are fine with the stream - // constantly being around that rate even for very low-complexity - // content; the obvious and extreme example being a static - // black picture. + + // If the user wants to cap the max rate, it is also reasonable + // to assume that they are fine with the stream constantly + // being around that rate even for very low-complexity content; + // the obvious and extreme example being a static black picture. // // One would think it's fine to have low-complexity content use // less bitrate, but it seems to cause problems in practice; @@ -243,6 +230,9 @@ void X264Encoder::init_x264() // thus ignores the parameter.) param.rc.b_filler = 1; } + if (!use_separate_disk_params) { + update_vbv_settings(¶m); + } // Occasionally players have problem with extremely low quantizers; // be on the safe side. Shouldn't affect quality in any meaningful way. @@ -265,7 +255,7 @@ void X264Encoder::init_x264() } } - if (global_flags.x264_bit_depth > 8) { + if (global_flags.bit_depth > 8) { dyn.x264_param_apply_profile(¶m, "high10"); } else { dyn.x264_param_apply_profile(¶m, "high"); @@ -361,7 +351,7 @@ void X264Encoder::encode_frame(X264Encoder::QueuedFrame qf) dyn.x264_picture_init(&pic); pic.i_pts = qf.pts; - if (global_flags.x264_bit_depth > 8) { + if (global_flags.bit_depth > 8) { pic.img.i_csp = X264_CSP_NV12 | X264_CSP_HIGH_DEPTH; pic.img.i_plane = 2; pic.img.plane[0] = qf.data;