MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / hb_vfr_init

Function hb_vfr_init

libhb/vfr.c:367–462  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

365}
366
367static int hb_vfr_init(hb_filter_object_t *filter, hb_filter_init_t *init)
368{
369 filter->private_data = calloc(1, sizeof(struct hb_filter_private_s));
370 hb_filter_private_t *pv = filter->private_data;
371
372 pv->cfr = init->cfr;
373 pv->input_vrate = pv->vrate = init->vrate;
374 hb_dict_extract_int(&pv->cfr, filter->settings, "mode");
375 hb_dict_extract_rational(&pv->vrate, filter->settings, "rate");
376
377 if (pv->cfr)
378 {
379 pv->metric = hb_motion_metric_init(init);
380 if (pv->metric == NULL)
381 {
382 return -1;
383 }
384 }
385
386 // frame-drop analysis always looks at at least 2 buffers
387 pv->frame_analysis_depth = 2;
388
389 // Calculate the number of frames we need to keep in order to
390 // detect "best" candidate frames to drop.
391 double in_vrate = (double)pv->input_vrate.num / pv->input_vrate.den;
392 double out_vrate = (double)pv->vrate.num / pv->vrate.den;
393 if (in_vrate > out_vrate)
394 {
395 // in_vrate / out_vrate tells us how many consecutive repeated
396 // frames we can expect to see. if the number of consecutive
397 // repeated frame is < 2, we need the number of consecutive
398 // non-repeated frames. Then add 1 so that we should have
399 // transitions that we can detect at both ends of a sequence.
400 double factor = in_vrate / out_vrate;
401 if (factor > 1.0 && factor < 2.0)
402 {
403 factor = 1 / (factor - 1);
404 }
405 pv->frame_analysis_depth = ceil(factor) + 1;
406
407 // if we end up with an absurdly large value, limit it
408 if (pv->frame_analysis_depth > MAX_FRAME_ANALYSIS_DEPTH)
409 {
410 pv->frame_analysis_depth = MAX_FRAME_ANALYSIS_DEPTH;
411 }
412 }
413 pv->frame_analysis_duration = pv->frame_analysis_depth * 90000 / in_vrate;
414 pv->frame_metric = calloc(pv->frame_analysis_depth, sizeof(double));
415 pv->frame_metric[0] = INT_MAX;
416
417 pv->job = init->job;
418
419 /* Setup FIFO queue for subtitle cache */
420 pv->delay_queue = hb_fifo_init( 8, 1 );
421 pv->frame_rate_list = hb_list_init();
422
423
424 /* VFR IVTC needs a bunch of time-keeping variables to track

Callers

nothing calls this directly

Calls 5

hb_dict_extract_intFunction · 0.85
hb_dict_extract_rationalFunction · 0.85
hb_fifo_initFunction · 0.85
hb_list_initFunction · 0.85
hb_motion_metric_initFunction · 0.70

Tested by

no test coverage detected