Skip to main content

Standalone Python shot boundary detection package for splitting videos into shots

Project description

Shot Detection Python

PyPI version

Standalone Python package for shot boundary detection.

It takes a video file, runs TransNetV2-style ONNX inference on low-resolution RGB frames, and returns shot ranges with millisecond timestamps.

Built by Seeknetic. If you want to make video shots searchable and enable more professional video understanding workflows, visit seeknetic.com.

What it does

  • Probes the input video with ffprobe
  • Extracts low-resolution frames with ffmpeg
  • Runs sliding-window ONNX inference
  • Finds shot boundaries
  • Converts them into {start_ms, end_ms} shot segments

Installation

pip install shot-detection

Import from shot_detection:

from shot_detection import ShotDetector

You also need:

  • ffmpeg
  • ffprobe

On first run, the package downloads the default model automatically:

  • URL: https://download.shotai.io/model/shot-detection/transnetv2_open_fp16.onnx
  • cache dir:
    • Linux/macOS: ~/.cache/shot-detection/models/
    • Windows: %LOCALAPPDATA%\\shot-detection\\models\\

You can override the cache root with SHOT_DETECTION_CACHE_DIR.

Usage

from shot_detection import ShotDetector

detector = ShotDetector()
shots = detector.detect("/path/to/video.mp4")

for shot in shots:
    print(shot.start_ms, shot.end_ms)

Advanced usage

from shot_detection import detect_shots

shots = detect_shots(
    video_path="/path/to/video.mp4",
    threshold=0.5,
    min_shot_duration_ms=500,
)

Custom model path

from shot_detection import ShotDetector

detector = ShotDetector(model_path="/path/to/custom-transnetv2.onnx")

Notes

  • The package expects the ONNX model input to accept 100-frame windows at 48x27 RGB.
  • ffmpeg decode is adaptive: it prefers system-native hardware decoding when available and falls back to software decoding automatically.
  • CUDA is intentionally not part of the default decode plan.

Integration with Seeknetic SDK

If you want to run shot-level embedding or tagging jobs after boundary detection, you can combine this package with the Seeknetic Python SDK.

For the full workflow, see docs/seeknetic-sdk-integration.md.

Install the SDK separately:

pip install seeknetic

Set SEEKNETIC_API_KEY before calling the SDK:

export SEEKNETIC_API_KEY="your_api_key"

A paid Seeknetic account and API access are required. You can get an API key from accounts.seeknetic.com.

Quick example

import os
import uuid

from seeknetic import Seeknetic
from shot_detection import ShotDetector

video_path = "/path/to/video.mp4"
shots = ShotDetector().detect(video_path)
client = Seeknetic(api_key=os.environ["SEEKNETIC_API_KEY"])
submitted_requests = {}

for shot in shots:
    request_id = str(uuid.uuid4())
    submitted_requests[shot.index] = {
        "request_id": request_id,
        "start_ms": shot.start_ms,
        "end_ms": shot.end_ms,
    }

    upload = client.preprocess_and_upload(
        video_path=video_path,
        service="embedding",
        request_id=request_id,
        start_ms=shot.start_ms,
        end_ms=shot.end_ms,
    )

    client.video_embedding.encode_video.submit_async(
        tensor={
            "video_input_key": upload.r2_keys["video_input"],
            "audio_input_key": upload.r2_keys["audio_input"],
        },
        request_id=upload.request_id,
    )

print(submitted_requests)

For tagging, switch service="embedding" to service="tagging" and use client.video_tagging.submit_async_job(...).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shot_detection-0.1.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shot_detection-0.1.1-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file shot_detection-0.1.1.tar.gz.

File metadata

  • Download URL: shot_detection-0.1.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for shot_detection-0.1.1.tar.gz
Algorithm Hash digest
SHA256 adc9e9763189c84f9712702ee5b2eea94d912bb4c3451732c3ed9dc8d78f0101
MD5 b4ca8c5c0112821955b6b1893f5651ad
BLAKE2b-256 f3fbb4f2f08e92ca20d119edca4ef2884f63a5dc75a7954cc81663d9cd9c1464

See more details on using hashes here.

Provenance

The following attestation bundles were made for shot_detection-0.1.1.tar.gz:

Publisher: publish-pypi.yml on Seeknetic/shot-detection-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file shot_detection-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: shot_detection-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for shot_detection-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7c740ad95f76c6a8d38c6cdc7e2e8eef672c9b3474c885298c40c9b599526500
MD5 69f90e93d84998507e28b881e98dd46b
BLAKE2b-256 0e8be5ab11d5b99e4e4e3c7a5048de1144856950c6887de669c78df2399dd304

See more details on using hashes here.

Provenance

The following attestation bundles were made for shot_detection-0.1.1-py3-none-any.whl:

Publisher: publish-pypi.yml on Seeknetic/shot-detection-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page