A command-line utility to measure audio sync offsets between MKV files
Project description
Sync Offset Tool
A command‑line utility to measure audio sync offsets between two MKV files. It extracts audio tracks, cross‑correlates them, and reports the best alignment offset in milliseconds. As of v1.2.0, the tool also detects and reports MKV container audio delays and calculates the effective offset including those delays.
Features
- 🎵 Audio extraction: Uses ffmpeg to pull raw PCM samples directly from MKV audio tracks.
- ⚡ Fast correlation: Defaults to FFT‑based cross‑correlation for speed.
- 🧮 Direct correlation option: More precise but slower.
- ⏱ Runtime reporting: Displays the exact runtime of both MKV files (hh:mm:ss.mmm).
- 🎬 FPS reporting: Displays the frames per second of the primary video stream in both files.
- ⏳ Container delay detection: Reports per‑track MKV audio delay metadata (start_time).
- 📐 Effective offset reporting: Combines raw correlation offset with container delays for a net sync difference.
- 📌 Version reporting:
--versionoption shows the current tool version.
Requirements
- Python 3.8+
- NumPy
- SciPy
- FFmpeg installed and available in your PATH
Usage
./sync_offset.py original.mkv async.mkv [lang1] [lang2] [duration_seconds] [start_seconds] [method]
Arguments:
original.mkv— reference fileasync.mkv— file suspected of being out of synclang1— language code for original track (default: eng)lang2— language code for async track (default: eng)duration_seconds— slice length to analyze (default: 120)start_seconds— offset into the file to start slice (default: 0)method— correlation method: fft (default) or direct
Options:
--version— display the tool’s version string
Examples
Run FFT correlation on a 120‑second slice from the start, English vs English (default):
./sync_offset.py movie1.mkv movie2.mkv
Analyze a German audio track against an English one for 90 s:
./sync_offset.py movie1.mkv movie2.mkv deu eng 90
Run FFT correlation on a long 300‑second slice starting at 600 s:
./sync_offset.py movie1.mkv movie2.mkv eng eng 300 600 fft
Compare 10‑second slices starting at 320 s using direct correlation:
./sync_offset.py movie1.mkv movie2.mkv eng eng 10 320 direct
Show version:
./sync_offset.py --version
Output
- Runtime (original): hh:mm:ss.mmm | FPS: xx.xxx fps
- Runtime (async): hh:mm:ss.mmm | FPS: xx.xxx fps
- Container delay (original track): Reported in milliseconds.
- Container delay (async track): Reported in milliseconds.
- Best alignment offset (raw): Correlation‑based offset in milliseconds.
- Peak correlation strength: Value between 0 and 1 indicating match quality.
- Effective offset (including container delays): Net sync difference after accounting for MKV metadata delays.
Interpreting correlation strength
- > 0.80 → Excellent match, high confidence in the offset measurement
- 0.50 – 0.80 → Moderate match, offset is usable but less certain
- < 0.50 → Weak match, results may be unreliable (consider shorter slices or different segments)
Tips for Better Results
- Choose slices with dialogue, sharp sounds, or clear audio events — they produce stronger correlations than background noise or music alone.
- Use shorter slices (10–60 s) if correlation strength is weak; smaller segments often align more clearly.
- Try analyzing different parts of the file (e.g., start, middle, end) to confirm consistency of offsets.
Notes
- Use FFT mode for long slices — it’s much faster.
- Use Direct mode only for short slices or when you need maximum precision.
- The script will refuse to run direct mode on slices >60 s without confirmation.
- On interruption, the worker process is terminated immediately — no orphan processes left behind.
- Container delays are reported directly from MKV metadata and may explain sync differences even before correlation.
Troubleshooting
- No audio track found: Check the language codes (eng, deu, fra, etc.) with ffprobe.
- FFmpeg errors: Ensure ffmpeg and ffprobe are installed and accessible in your PATH.
- Negative offsets: A negative offset means the async file is ahead of the original.
- Performance: Direct mode is O(n²). For slices longer than ~30 s, prefer FFT mode.
- Effective offset mismatch: If raw offset and container delays differ, the MKV metadata may already compensate for sync.
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sync_offset_tool-1.2.0.tar.gz.
File metadata
- Download URL: sync_offset_tool-1.2.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a949438e2e4b65a24b7eda9c273d3304190bca218ebd704a9cde276d8dcfd479
|
|
| MD5 |
a40f0419a33a84572af06d94167b1292
|
|
| BLAKE2b-256 |
de07144a0f8626142511342dd46400a635da573c1510ec626c7d9dcf70dc9388
|
File details
Details for the file sync_offset_tool-1.2.0-py3-none-any.whl.
File metadata
- Download URL: sync_offset_tool-1.2.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be4421a5ffd4575316e294eb23147e57fbd812a87671523f66793b0499990a4f
|
|
| MD5 |
d5d26b8c70b5a93a1c5923799da8c09b
|
|
| BLAKE2b-256 |
b21d2534caaf02bd060efb8a0f205a7345d373533ced604a15fbb9c688013f98
|