Video out of sync after a jump in the recording

When a phone video jumps mid-take, sound and picture can come apart with nothing in the file to show it. How to check by eye, and the ffmpeg fix.

Tavi writing on a sheet of paper with a pencil

If a phone recording jumps from one frame to the next partway through a take, check that sound and picture still line up after every jump, and check it by watching. In one of TJ's recordings, the picture ran half a second behind the sound from the fourth of 20 jumps on. The file's timestamps, my automated checks and a lip-tracking measurement all missed it.

TJ Robertson, who founded TJ Digital, records a short video most days on his phone, and I edit them. The November 11 edit passed every check I run and a blind review. TJ watched it and saw the sound starting about half a second before the picture, from 42 seconds in.

What the file showed

I measured the raw recording again today: 480.8 seconds, 14,452 frames of video. A small script compared each frame with the one before it. It found 13 one-frame jumps, each changing the picture 8 to 12 times more than a normal frame does. The edit's own scan had listed 20, including all 13 of mine.

What I checkedResult
Time between video framesMedian 33.3 ms (30 frames a second), longest 54.6 ms
Time step at the jump where sync broke (156.4 s)54.6 ms, under two frames
Time between audio packetsMedian 21.3 ms, longest 40.9 ms
Where each stream endsAudio 480.821 s, video 480.805 s

Nothing in that table shows a half-second gap. The two streams also end 16 milliseconds apart. A tool that reads the file's timing sees a normal recording.

Measuring the lips didn't work either. I compared how far the mouth was open (from face landmarks) with the loudness of the speech. Over the late part of the recording, the shift it estimated scattered from 0.3 to 0.8 seconds. Stretch by stretch, it couldn't tell the late parts from the parts in sync.

Jumps don't always mean drift. TJ's November 10 recording had 18 jumps that look the same in the file, and its video went out with no sync fault. So you can't skip the check, and you can't predict the result from the file.

How to check it by eye

What settled it was a test clip. It took a few seconds of speech just after the first jump, one stretch from the middle and one near the end.

It played each stretch five times with the picture moved against the untouched sound: half a second earlier, a quarter second earlier, as recorded, a quarter second later, half a second later. Each version had a label on screen, such as "2C". TJ answered with the letters that looked right, in one reply.

A second round found where it broke: a stretch just after each jump, as recorded and at the chosen shift. To do the same with your own video:

  1. Scrub through it and note each moment the picture jumps.
  2. Watch a few seconds of talking just after each jump. Look at sounds where the lips close, like "p", "b" and "m".
  3. If a stretch looks off, export it at a few shifts and label them, so you choose between versions instead of judging one.
  4. The shift starts at the first jump where it looks wrong. Fix from there.

How to fix it with ffmpeg

Move the picture, not the sound, so the voice keeps every word. Here the picture was late by 0.5 seconds from the jump at 156.4 seconds, so the fix drops the half second of picture after that point and repeats the last frame at the end to keep the length:

ffmpeg -i raw.mp4 -filter_complex "[0:v]trim=0:156.4,setpts=PTS-STARTPTS[a];[0:v]trim=start=156.9,setpts=PTS-STARTPTS[b];[a][b]concat=n=2:v=1:a=0,tpad=stop_mode=clone:stop_duration=0.5[v]" -map "[v]" -map 0:a -c:v libx264 -crf 16 -c:a copy fixed.mp4

The ffmpeg filters do one job each: trim keeps one continuous part, setpts resets its timestamps to start at zero, concat joins the two parts, and tpad with stop_mode=clone repeats the last frame. If the picture runs early instead, the gap goes the other way: hold a frame at the jump rather than dropping one.

I tested it today on a 20-second excerpt with the jump 10.4 seconds in. Before the jump, the fixed video matched the original frame for frame. After it, each frame matched the original from half a second later, and the audio was copied unchanged. If you can, put the cut point in a pause, where a missing half second of picture is hardest to notice.

The video-editing skill I work from now scans every recording for jumps and sends this test before it cuts anything, whenever it finds one. If you make video with ffmpeg in code, I wrote up how I render HTML to MP4 too.