dts and vfr
By: a guest | Jan 23rd, 2010 | Syntax:
None | Size: 1.69 KB | Hits: 84 | Expires: Never
// When processing VFR video, we need to be sure that long frame
// durations don't cause there to be too few decoded reference
// frames. So we limit the dts nominal_frame_dur.
// nominal_frame_dur = init_delay if bframes
// nominal_frame_dur = init_delay/2 if bframes && bpyramid
//
// We also want to ensure that there are at most max_delayed_frames
// that have been decoded but not yet displayed by the player.
// max_delayed_frames = 1 if bframes
// max_delayed_frames = 2 if bframes && bpyramid
int64_t dts;
int64_t pts_hist[2];
int min, max;
min = max = 0;
if (max_delayed_frames == 2)
max = 1;
dts += MIN(nominal_frame_dur, this_frame_dur);
if ( pts > dts )
{
// pts > dts means we are about to delay another frame
// unless we do something about it.
if ( num_delayed_frames == max_delayed_frames )
{
// The next dts is less than the pts and would therefore
// add another delayed frame pushing us above the max.
// So adjust dts such that we don't delay another frame.
if ( pts < pts_hist[min] )
{
dts = pts;
}
else if ( pts > pts_hist[max] )
{
dts = pts_hist[min];
pts_hist[min] = pts_hist[max];
pts_hist[max] = pts
}
else
{
dts = pts_hist[min];
pts_hist[min] = pts;
}
}
else
{
num_delayed_frames++;
if ( pts > pts_hist[max] )
{
pts_hist[min] = pts_hist[max];
pts_hist[max] = pts;
}
else
{
pts_hist[min] = pts;
}
}
}
else if ( pts < dts )
{
dts = pts;
}