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:

frames = []
for time, luma in my_frames():           # 8-bit luma (Y) planes: bytes, numpy uint8, ...
    frames.append({"time": time, "stamp": avd.read_frame(luma, width, height)})

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

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

  • read_frame(luma, width, height, stride=None, *, try_qr=True) reads a 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. MIT licensed.

Metadata

Release files for av-drift-detector 0.3.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.3.0
File Size Uploaded Provenance
av_drift_detector-0.3.0.tar.gz 108.4 kB With provenance Details

Built distributions (wheels)

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

Total release size: 5.0 MB

Release files / av_drift_detector-0.3.0.tar.gz

Download URL av_drift_detector-0.3.0.tar.gz
Size 108.4 kB
Tags Source
SHA-256 checksum
How to use checksums
735ebf38ad1e0999eb2023780aba0325e79ca8311204511273866fd317d378ef
BLAKE2b-256 checksum
How to use checksums
d67b6bcc33c8ad96b316b6a5a0f8d44358e210b78e63c41a51526b0d9b79aef3
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 22, 2026.

Transparency log

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

Download URL av_drift_detector-0.3.0-cp311-abi3-win_amd64.whl
Size 912.6 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
c54ba0821abb6bc99c0c8b35be016be5ef4a731d8b3862b91465f9ec26886a92
BLAKE2b-256 checksum
How to use checksums
8f7f769f80b2fd1ae2ccebff810315256599c765cc79c4e9c03f2b40ced50605
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 22, 2026.

Transparency log

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

Download URL av_drift_detector-0.3.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.1 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
e60b49dc77e4f84c4f7c92c05312626e571f4e38939a6bb950eaeacf5e0e1054
BLAKE2b-256 checksum
How to use checksums
81fb004ba1a5aadae147cb7fc72ced9979630b2128be7bd9e2221e72f0f8aba2
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 22, 2026.

Transparency log

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

Download URL av_drift_detector-0.3.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 945.7 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
d5e8656f218fc0cafc1a74483930583aa02d24ea4e90ae02b009e5c6cbd42cb6
BLAKE2b-256 checksum
How to use checksums
8528f616a5b1d20d647357ba85661606de40f4efe5982dcedde461dc665993fa
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 22, 2026.

Transparency log

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

Download URL av_drift_detector-0.3.0-cp311-abi3-macosx_11_0_arm64.whl
Size 868.0 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5c353e2122acede852a6e210219d575781b16d2b478ec9ed31c942fe277bf4d0
BLAKE2b-256 checksum
How to use checksums
8e8687945d4c9b527ea360400f5a454601cea6ca99c9576a618fa21c57c54cbb
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 22, 2026.

Transparency log

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

Download URL av_drift_detector-0.3.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 1.0 MB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
3e333f3344dc2335b501ac04d2af586d6773d7699cb8a375828e902c311d9a5b
BLAKE2b-256 checksum
How to use checksums
445e0bf2317770814b87a4a78697f77efe6daeee9e9829ff3e4185523e59a9fe
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 22, 2026.

Transparency log

Security for av-drift-detector 0.3.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.3.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 22, 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.

Release history Release notifications | RSS feed

This release

0.3.0 This release

6 release files Full provenance

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