Skip to main content

av-drift-detector (Python)

Measure audio/video sync to a fraction of a millisecond, frame by frame.

Python bindings to av-drift-detector, the Rust library behind the av-drift command. Generate a test video whose every frame, and every frame's worth of audio, carries its own frame number. Play it through whatever you want to test (an encoder, a streaming pipeline, a TV, a video call), record the result, and measure how far the sound has drifted from the picture at every frame.

import av_drift_detector as avd

avd.generate("sync.mp4", fps="29.97", duration=10, audio_offset=0.040)
# ... play sync.mp4 through the system under test and record it as captured.mp4 ...
report = avd.analyze("captured.mp4")
print(report["summary"]["mean_ms"])  # positive means the audio is late

Install

pip install av-drift-detector

Python 3.11 or later. Wheels cover macOS (Apple silicon and Intel), Linux (x64 and arm64, manylinux) and Windows (x64); elsewhere pip builds from source, which needs Rust.

Reading and writing files runs the ffmpeg and ffprobe programs, so install FFmpeg 5.1 or later (brew install ffmpeg, sudo apt install ffmpeg, winget install Gyan.FFmpeg) and keep them on your PATH, or set AV_DRIFT_FFMPEG and AV_DRIFT_FFPROBE to their paths. Writing H.264 needs an FFmpeg with libx264, as those packages have. The in-memory functions below don't need FFmpeg.

Files

  • generate(output, *, fps="30", duration=10.0, width=1280, height=720, sample_rate=48000, video_codec="h264", audio_codec="aac", audio_offset=0.0, music=True, on_progress=None) writes a test video and returns a summary. audio_offset (seconds) deliberately delays the audio; negative makes it early. music plays a tune under the tones that doesn't affect analysis. on_progress(frames_done, frames_total) is called about once a percent. FFV1 video and PCM audio need .mov or .mkv.
  • analyze(path, *, offset=0.0, duration=None, fps=None, use_qr=True, capture="auto") measures every frame of a capture. offset and duration choose a window in seconds, and capture is "auto", "file" (a digital copy) or "camera" (a phone filming a screen).

Reports are the dicts av-drift analyze --json writes (format), typed as DriftReport, so json.dump(report, f) saves the CLI's format:

s = report["summary"]
print(f"{s['mean_ms']:+.2f} ms ± {s['stddev_ms']:.2f}, skew {s['skew_ppm']:+.1f} ppm")
for f in report["frames"]:
    if f["status"] == "ok":
        print(f["time"], f["video_frame"], f["drift_ms"])

Frames and audio from elsewhere

If you already have decoded frames and audio (a capture card, WebRTC, a camera), measure them without files:

reader = avd.StampReader()
for time, luma in my_frames():           # 8-bit luma (Y) planes: bytes, numpy uint8, ...
    reader.read(luma, width, height, time)

audio = {"sample_rate": 48_000, "start_time": t0, "samples": mono_float32}  # array("f"), numpy float32, ...
report = avd.analyze_frames(reader.finish(), audio, width=width, height=height)

Frame times and start_time must be on the same clock, in seconds.

  • StampReader(*, try_qr=True) reads the frames of one capture in order. read(luma, width, height, time, stride=None) returns the frame ({"time", "stamp", "qr_located"}); finish() returns every frame read, with any that could only be identified from later frames filled in. It follows the QR code from frame to frame, which is faster than reading each frame alone, and it reads pictures a camera caught while the screen switched frames, measuring how far through the switch each was (the stamp's blend). Use it for camera footage.
  • read_frame(luma, width, height, stride=None, *, try_qr=True) reads one frame's stamp (barcode, then QR code), or returns None.
  • PatternRenderer(*, fps="30", width=1280, height=720, sample_rate=48000, duration=None).render(frame_id) draws a test-pattern frame as luma bytes. With duration (seconds), the info line shows the file's length.
  • synthesize_audio(count, *, fps="30", sample_rate=48000, delay=0.0, start=0, music=True) makes the test audio as an array("f"), with the music unless music is false.

Errors raise AvDriftError. Slow calls release the GIL, so they run in parallel from threads.

More

The repository has the guides: measuring with a camera, the test pattern specification, and how the analysis works. Licensed under the BSD-2-Clause Plus Patent License.

Metadata

Release files for av-drift-detector 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for av-drift-detector 0.4.0
File Size Uploaded Provenance Actions
av_drift_detector-0.4.0.tar.gz 152.6 kB With provenance Details for av_drift_detector-0.4.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for av-drift-detector 0.4.0
File Actions
av_drift_detector-0.4.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for av_drift_detector-0.4.0-cp311-abi3-win_amd64.whl
av_drift_detector-0.4.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details for av_drift_detector-0.4.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
av_drift_detector-0.4.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details for av_drift_detector-0.4.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
av_drift_detector-0.4.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for av_drift_detector-0.4.0-cp311-abi3-macosx_11_0_arm64.whl
av_drift_detector-0.4.0-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details for av_drift_detector-0.4.0-cp311-abi3-macosx_10_12_x86_64.whl

Total release size: 5.4 MB

Release files / av_drift_detector-0.4.0.tar.gz

Download URL av_drift_detector-0.4.0.tar.gz
Size 152.6 kB
Tags Source
SHA-256 checksum
How to use checksums
21943cd28333d1f7ec71eb189e8f1cf7eb6ac08a805914340f50767759caa90f
BLAKE2b-256 checksum
How to use checksums
a3d332c88e74a2c7d1a328adbd89e7a41a30108fbf0c528e7868067bbf4cf09e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Release files / av_drift_detector-0.4.0-cp311-abi3-win_amd64.whl

Download URL av_drift_detector-0.4.0-cp311-abi3-win_amd64.whl
Size 980.4 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
db767865aaaa86f2c7aeb418e1b6defd588efb3801a75901a0cf1b920ed1433d
BLAKE2b-256 checksum
How to use checksums
015e7f22faacdfb7ce0d25b74aba93f968f30446c9a1a3c1629f09bde8bec6f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Release files / av_drift_detector-0.4.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL av_drift_detector-0.4.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.2 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
5bcaf4b3ad8281527febe8095f288975b486cf1f4b41255b0e71d40470290754
BLAKE2b-256 checksum
How to use checksums
3153277faba705fcd94a061eb323286c4e505d336a8bb3a496aad586ca2c5ebf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Release files / av_drift_detector-0.4.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL av_drift_detector-0.4.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.0 MB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
9abaa0006d9236e69b05d1d354a0b170571a4e63094bb9aeea0d1f7e1f70f776
BLAKE2b-256 checksum
How to use checksums
993956e8f982579fc23fe977b1771a48b32d6015a9de49321000bd7a0f54111d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Release files / av_drift_detector-0.4.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL av_drift_detector-0.4.0-cp311-abi3-macosx_11_0_arm64.whl
Size 932.7 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
75a7b490edd1f80998d4ea3638e4b8305ca6140a06ff2ebcecfade59ce3d7b89
BLAKE2b-256 checksum
How to use checksums
89545904f15e55178180c65e5869c16065963e020c80189afeab281103720e98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Release files / av_drift_detector-0.4.0-cp311-abi3-macosx_10_12_x86_64.whl

Download URL av_drift_detector-0.4.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 1.1 MB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
488ce1d6d4ffdb1aa2b106609712e303d300df2e4d9dd8d4e211f0894887760f
BLAKE2b-256 checksum
How to use checksums
250e897da79839250cef2be915463bb57ddd28d11a1c31c97b504c310b1d5cf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Security for av-drift-detector 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for av_drift_detector-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page