remove judder in video stream
Algorithm:
If the old packets had PTS of old_pts[i]. Replace these with new value based on the running average of the last n=cycle frames. So
new_pts[i] = Sum(k=i-n+1, i, old_pts[k])/n
- (old_pts[i]-old_pts[i-n])*(n-1)/2n
For any repeating pattern of length n of judder this will produce an even progression of PTS's.
- In order to avoid calculating this sum ever frame, a running tally is maintained in ctx->new_pts. Each frame the new term at the start of the sum is added, the one and the end is removed, and the offset terms (second line in formula above) are recalculated.
- To aid in this a ringbuffer of the last n-2 PTS's is maintained in ctx->ringbuff. With the indices of the first two and last two entries stored in i1, i2, i3, & i4.
- To ensure that the new PTS's are integers, time_base is divided by 2n. This removes the division in the new_pts calculation.
- frame_rate is also multiplied by 2n to allow the frames to fall where they may in what may now be a VFR output. This produces more even output then setting frame_rate=1/0 in practice.
Definition in file vf_dejudder.c.