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

Function dejitterVideo

libhb/sync.c:876–924  ·  view source on GitHub ↗

Look for a sequence of packets whose duration as measure by vrate closely matches the duration as measured by timestamp differences. When close matches are found, smooth the timestamps. Most often, video dejitter is applied when there is jitter due to soft telecine. I also have a couple sample files that have very bad video jitter that this corrects.

Source from the content-addressed store, hash-verified

874// soft telecine. I also have a couple sample files that have very
875// bad video jitter that this corrects.
876static void dejitterVideo( sync_stream_t * stream )
877{
878 int ii, count, jitter_stop;
879 double frame_duration, duration;
880 hb_buffer_t * buf;
881
882 count = hb_list_count(stream->in_queue);
883 if (count < 2)
884 {
885 return;
886 }
887
888 frame_duration = 90000. * stream->common->job->title->vrate.den /
889 stream->common->job->title->vrate.num;
890
891 // Look for start of jittered sequence
892 buf = hb_list_item(stream->in_queue, 1);
893 duration = buf->s.start - stream->next_pts;
894 if (ABS(duration - frame_duration) < 1.1)
895 {
896 // Ignore small jitter
897 buf->s.start = stream->next_pts + frame_duration;
898 buf = hb_list_item(stream->in_queue, 0);
899 buf->s.start = stream->next_pts;
900 buf->s.duration = frame_duration;
901 buf->s.stop = stream->next_pts + frame_duration;
902 return;
903 }
904
905 // Look for end of jittered sequence
906 jitter_stop = 0;
907 for (ii = 1; ii < count; ii++)
908 {
909 buf = hb_list_item(stream->in_queue, ii);
910 duration = buf->s.start - stream->next_pts;
911
912 // Only dejitter video that aligns periodically
913 // with the frame durations.
914 if (ABS(duration - ii * frame_duration) < frame_duration / 3)
915 {
916 jitter_stop = ii;
917 }
918 }
919
920 if (jitter_stop > 0)
921 {
922 removeVideoJitter(stream, jitter_stop);
923 }
924}
925
926// Fix video overlaps that could not be corrected by dejitter
927static void fixVideoOverlap( sync_stream_t * stream )

Callers 1

fixStreamTimestampsFunction · 0.85

Calls 3

hb_list_countFunction · 0.85
hb_list_itemFunction · 0.85
removeVideoJitterFunction · 0.85

Tested by

no test coverage detected