X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fav1_encoder.cpp;h=13f0e30e3e9162fd5689883290d448205ae07e22;hb=HEAD;hp=e571184585f33a5637b958d07215f0ef98dfab20;hpb=0f0780d0c2f321ecb72d3b6f3a70136cdc26265e;p=nageru diff --git a/nageru/av1_encoder.cpp b/nageru/av1_encoder.cpp index e571184..bb6c17b 100644 --- a/nageru/av1_encoder.cpp +++ b/nageru/av1_encoder.cpp @@ -132,6 +132,14 @@ void AV1Encoder::add_frame(int64_t pts, int64_t duration, YCbCrLumaCoefficients void AV1Encoder::init_av1() { EbSvtAv1EncConfiguration config; + + // svt_av1_enc_init_handle() is defined to fill config with the defaults; + // yet, seemingly, not everything is written, and some of it can cause + // Valgrind warnings and/or crashes. It should never hurt to put it + // into a known state beforehand, and it seems to fix the crashes, + // so we do that. + memset(&config, 0, sizeof(config)); + EbErrorType ret = svt_av1_enc_init_handle(&encoder, nullptr, &config); if (ret != EB_ErrorNone) { fprintf(stderr, "Error initializing SVT-AV1 handle (error %08x)\n", ret); @@ -147,6 +155,7 @@ void AV1Encoder::init_av1() config.frame_rate_numerator = global_flags.av1_fps_num; config.frame_rate_denominator = global_flags.av1_fps_den; config.encoder_bit_depth = global_flags.bit_depth; + config.rate_control_mode = 1; // VBR. config.target_bit_rate = global_flags.av1_bitrate * 1000; // NOTE: These should be in sync with the ones in quicksync_encoder.cpp (sps_rbsp()). @@ -203,7 +212,7 @@ void AV1Encoder::init_av1() global_headers = string(reinterpret_cast(header->p_buffer), header->n_filled_len); svt_av1_enc_stream_header_release(header); // Don't care about errors. - } + } } void AV1Encoder::encoder_thread_func() @@ -300,7 +309,7 @@ void AV1Encoder::encode_frame(AV1Encoder::QueuedFrame qf) hdr.n_alloc_len = (global_flags.width * global_flags.height * 3 / 2) * bytes_per_pixel; hdr.n_filled_len = hdr.n_alloc_len; hdr.n_tick_count = 0; - hdr.p_app_private = reinterpret_cast(intptr_t(qf.duration)); + hdr.p_app_private = nullptr; hdr.pic_type = EB_AV1_INVALID_PICTURE; // Actually means auto, according to FFmpeg. hdr.metadata = nullptr; hdr.flags = 0;