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

Function compute_frame_duration

libhb/decavcodec.c:2307–2379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2305}
2306
2307static void compute_frame_duration( hb_work_private_t *pv )
2308{
2309 int64_t max_fps = 256LL;
2310 int64_t min_fps = 8LL;
2311 double duration = 0.;
2312
2313 // context->time_base may be in fields, so set the max *fields* per second
2314 const AVCodecDescriptor *desc = avcodec_descriptor_get(pv->context->codec_id);
2315 int ticks_per_frame = desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1;
2316
2317 if (pv->title->opaque_priv)
2318 {
2319 // If ffmpeg is demuxing for us, it collects some additional
2320 // information about framerates that is often accurate
2321 AVFormatContext *ic = (AVFormatContext*)pv->title->opaque_priv;
2322 AVStream *st = ic->streams[pv->title->video_id];
2323 if (st->nb_frames && st->duration > 0)
2324 {
2325 // compute the average frame duration from the total number
2326 // of frames & the total duration.
2327 duration = ( (double)st->duration * (double)st->time_base.num ) /
2328 ( (double)st->nb_frames * (double)st->time_base.den );
2329 }
2330 else
2331 {
2332 AVRational *tb = NULL;
2333 // We don't have a frame count or duration so try to use the
2334 // far less reliable avg_frame_rate info in the stream.
2335 if (st->avg_frame_rate.den && st->avg_frame_rate.num)
2336 {
2337 tb = &(st->avg_frame_rate);
2338 }
2339 // Try r_frame_rate, which is usually set for cfr streams
2340 else if (st->r_frame_rate.num && st->r_frame_rate.den)
2341 {
2342 tb = &(st->r_frame_rate);
2343 }
2344 // Because the time bases are so screwed up, we only take values
2345 // in a restricted range.
2346 else if (st->time_base.num * max_fps > st->time_base.den &&
2347 st->time_base.den > st->time_base.num * min_fps)
2348 {
2349 tb = &(st->time_base);
2350 }
2351
2352 if (tb != NULL)
2353 {
2354 duration = (double)tb->den / (double)tb->num;
2355 }
2356 }
2357 }
2358 else if (pv->context->framerate.num && pv->context->framerate.den)
2359 {
2360 duration = (double)pv->context->framerate.den / (double)pv->context->framerate.num;
2361 }
2362
2363 int clock_min, clock_max, clock;
2364 hb_video_framerate_get_limits(&clock_min, &clock_max, &clock);

Callers 2

decodeFrameFunction · 0.85
decavcodecvInfoFunction · 0.85

Calls 1

Tested by

no test coverage detected