A two-hour recording that drifts out of sync by the end
The first ten minutes are perfect. By the end of a two-hour recording, the audio is running several seconds ahead of the picture. Nudging the audio track fixes the beginning and ruins the end, because the error is not a fixed offset. It grows.
This is clock drift, and it is a property of the recording setup rather than a mistake anyone made. Once you can measure it, the correction is exact.
Offset versus drift, and why the distinction decides the fix
A constant offset means audio and video are misaligned by the same amount throughout. Sliding one track fixes it everywhere. This is what you get when a camera has a fixed processing delay, or when someone started a separate recorder a moment late.
Drift means the misalignment grows over time. At the start it is imperceptible, at the end it is obvious. Sliding the track cannot fix it, because there is no single number that is correct for the whole file.
Test which one you have in under a minute. Find a sharp sync point near the start (a clap, a door, a consonant) and note how far apart audio and picture are. Find another near the end and measure again. Same figure both times means offset. A larger figure at the end means drift.
Why clocks drift
Every device that records audio has an oscillator setting its sample rate, and every camera has one setting its frame rate. Neither is perfect. A crystal specified at 48 kHz might actually run at 47,995 Hz or 48,005 Hz, and the deviation is stable but nonzero.
When one device records both streams, this does not matter, because both are timed against the same imperfect clock and stay together. Record audio on a separate recorder and the two clocks free-run against each other, and the gap accumulates.
The arithmetic is unforgiving over long takes. For two devices whose clocks differ by a given amount:
| Clock difference | Drift over 30 min | Drift over 2 hours |
|---|---|---|
| 0.01% | 0.18 s | 0.72 s |
| 0.1% | 1.80 s | 7.20 s |
| 0.5% | 9.00 s | 36.00 s |
A tenth of one percent sounds like nothing and produces seven seconds of error across a feature-length recording. This is why the problem is invisible in short clips and unmissable in long ones, and why it seems to appear out of nowhere the first time you record something lengthy.
The other cause: a sample rate that was mislabelled
There is a second, sharper version of this problem, and it is worth ruling out first because the numbers are dramatically larger.
If audio was recorded at 48 kHz but the file claims 44.1 kHz, playback runs at the wrong speed entirely. The ratio is 48000/44100, about 1.088, so:
- 5 minutes plays as 5 min 26 s, drifting 26.5 seconds
- 30 minutes plays as 32 min 39 s, drifting 159 seconds
- 2 hours plays as 2 h 10 min, drifting 637 seconds
If your drift is measured in minutes rather than seconds, this is your cause, and the audio will also sound noticeably low-pitched. Check what the file claims:
ffprobe -v error -show_entries stream=codec_type,sample_rate,duration \
-of default=noprint_wrappers=1 recording.wav
A mislabelled file is corrected by reinterpreting it at the true rate rather than by stretching:
ffmpeg -f s16le -ar 48000 -ac 2 -i raw.pcm -c:a pcm_s16le fixed.wav
That path applies when you have raw audio. For a WAV whose header is simply wrong, rewriting the header is the correct fix rather than resampling, since resampling would bake the error in.
Measuring your actual drift
For genuine clock drift, you need one number: how far apart the two streams are at the end.
Find a sync event as close to the start as you can and note its timestamp in both the audio and the video. Do the same as close to the end as possible. The drift is the difference between the two errors, and the total duration is your baseline.
Suppose the audio is aligned at 00:00:05 and runs 7.2 seconds early at 02:00:00. Your correction factor is the ratio of the true duration to the recorded one:
7200 / 7207.2 = 0.9990010
That is the factor to apply to the audio.
Applying the correction
ffmpeg stretches audio without changing its pitch using the atempo filter:
ffmpeg -i audio.wav -filter:a "atempo=0.9990010" -c:a pcm_s16le audio-corrected.wav
atempo accepts values between 0.5 and 2.0, which covers any realistic drift comfortably. Because it preserves pitch, voices do not go strange; the recording simply lasts fractionally longer or shorter.
Then check your work by measuring the sync at the end again. Expect to be within a frame or two. If you are still out by a consistent amount everywhere, that residue is a constant offset, and now a simple slide will fix it, because you have removed the growing component first.
To combine the stretch with a fixed offset in one pass:
ffmpeg -i video.mp4 -itsoffset 0.35 -i audio-corrected.wav \
-map 0:v -map 1:a -c:v copy -c:a aac -b:a 192k output.mp4
-c:v copy matters: it passes the video through untouched, so you are not re-encoding the picture to fix an audio problem.
Preventing it next time
Drift is much easier to avoid than to correct.
Record a sync reference at both ends of a long take, not just the beginning. A clap at the start and another at the end gives you exactly the two measurements the correction needs, and turns a guessing exercise into arithmetic.
Where the equipment supports it, feed both devices from the same clock, or record a scratch audio track on the camera as a reference even if you will not use it in the edit. Matching a good recording against a poor one is far easier than matching it against nothing.
For very long sessions, break the recording into segments. Two one-hour files drift half as far as one two-hour file, and each can be corrected independently.
When the file also will not play properly
Drift assumes a healthy file. If the audio is also stuttering, cutting out, or the video shows a black screen while sound continues, you have a different problem layered on top. Manatee will read a damaged video or audio file and write a clean copy from a duplicate, leaving the original as it is, which is the sensible first step before attempting any sync work on a file you cannot trust. When audio plays but the video is black covers that specific failure, and audio out of sync after a conversion covers the case where the misalignment appeared during a format change rather than during recording.
Questions
Can I fix drift by changing the video frame rate instead? You can, and generally you should not. Altering the video’s timing means re-encoding the picture or introducing duplicate frames, both of which are visible. Stretching the audio by a fraction of a percent is inaudible.
Why does my phone never have this problem? Because it records both streams against one clock. Drift needs two independent clocks, which means two devices.
The drift is not linear. It jumps at one point. That is not drift; that is a dropout. Something stopped recording for a moment and resumed. Look for the jump, split the file there, and align the two halves separately.
Does atempo reduce audio quality?
Slightly, in principle, because it resamples. At corrections of a fraction of a percent the change is not audible. Chaining several atempo filters for large corrections does degrade quality, but no realistic drift needs that.