MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / init_pass2

Function init_pass2

libavcodec/ratecontrol.c:333–494  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

331}
332
333static int init_pass2(MPVMainEncContext *const m)
334{
335 RateControlContext *const rcc = &m->rc_context;
336 MPVEncContext *const s = &m->s;
337 AVCodecContext *const avctx = s->c.avctx;
338 int i, toobig;
339 AVRational fps = get_fpsQ(avctx);
340 double complexity[5] = { 0 }; // approximate bits at quant=1
341 uint64_t const_bits[5] = { 0 }; // quantizer independent bits
342 uint64_t all_const_bits;
343 uint64_t all_available_bits = av_rescale_q(m->bit_rate,
344 (AVRational){rcc->num_entries,1},
345 fps);
346 double rate_factor = 0;
347 double step;
348 const int filter_size = (int)(avctx->qblur * 4) | 1;
349 double expected_bits = 0; // init to silence gcc warning
350 double *qscale, *blurred_qscale, qscale_sum;
351
352 /* find complexity & const_bits & decide the pict_types */
353 for (i = 0; i < rcc->num_entries; i++) {
354 RateControlEntry *rce = &rcc->entry[i];
355
356 rce->new_pict_type = rce->pict_type;
357 rcc->i_cplx_sum[rce->pict_type] += rce->i_tex_bits * rce->qscale;
358 rcc->p_cplx_sum[rce->pict_type] += rce->p_tex_bits * rce->qscale;
359 rcc->mv_bits_sum[rce->pict_type] += rce->mv_bits;
360 rcc->frame_count[rce->pict_type]++;
361
362 complexity[rce->new_pict_type] += (rce->i_tex_bits + rce->p_tex_bits) *
363 (double)rce->qscale;
364 const_bits[rce->new_pict_type] += rce->mv_bits + rce->misc_bits;
365 }
366
367 all_const_bits = const_bits[AV_PICTURE_TYPE_I] +
368 const_bits[AV_PICTURE_TYPE_P] +
369 const_bits[AV_PICTURE_TYPE_B];
370
371 if (all_available_bits < all_const_bits) {
372 av_log(avctx, AV_LOG_ERROR, "requested bitrate is too low\n");
373 return -1;
374 }
375
376 qscale = av_malloc_array(rcc->num_entries, sizeof(double));
377 blurred_qscale = av_malloc_array(rcc->num_entries, sizeof(double));
378 if (!qscale || !blurred_qscale) {
379 av_free(qscale);
380 av_free(blurred_qscale);
381 return AVERROR(ENOMEM);
382 }
383 toobig = 0;
384
385 for (step = 256 * 256; step > 0.0000001; step *= 0.5) {
386 expected_bits = 0;
387 rate_factor += step;
388
389 rcc->buffer_index = avctx->rc_buffer_size / 2;
390

Callers 1

ff_rate_control_initFunction · 0.85

Calls 11

get_fpsQFunction · 0.85
av_rescale_qFunction · 0.85
av_logFunction · 0.85
av_malloc_arrayFunction · 0.85
get_qscaleFunction · 0.85
get_diff_limited_qFunction · 0.85
modify_qscaleFunction · 0.85
qp2bitsFunction · 0.85
ff_vbv_updateFunction · 0.85
fabsFunction · 0.85
av_freeFunction · 0.50

Tested by

no test coverage detected