Skip to main content

Simple Video Utils

Lightweight utilities for extracting frames and metadata from videos. Built for sign language processing workflows.

Python License

Goal

Provide simple, efficient tools for video processing in sign language research and applications. Uses PyAV for fast frame extraction with support for multiple formats (MP4, WebM) and remote URLs.

Installation

pip install simple-video-utils

Usage

Extract Video Metadata

from simple_video_utils.metadata import video_metadata

meta = video_metadata("video.mp4")
print(f"{meta.width}x{meta.height} @ {meta.fps} fps, {meta.duration}s")
# Output: VideoMetadata(width=1920, height=1080, fps=30.0, nb_frames=450, time_base='1/15360', duration=15.0)

Keyframe Indices (GOP Structure)

from simple_video_utils.metadata import keyframe_indices

keys = keyframe_indices("video.mp4")
# Presentation-order frame indices of the keyframes, e.g. [0, 250, 500]
# Demux-only (no decoding) — cheap even for long videos.

Read Frames from File

from simple_video_utils.frames import read_frames_exact

# Read specific frame range (inclusive)
frames = list(read_frames_exact("video.mp4", start_frame=0, end_frame=10))
# Returns 11 frames as numpy arrays (H, W, 3) in RGB format

# Read from frame to end of video
frames = list(read_frames_exact("video.mp4", start_frame=5, end_frame=None))

# Downsample to a target frame rate (drops frames uniformly, never duplicates)
frames = list(read_frames_exact("video.mp4", fps=15))

One Open, Many Reads

from simple_video_utils.metadata import open_video, video_metadata_from_container, keyframe_indices
from simple_video_utils.frames import read_frames_exact

# Metadata + windowed frame reads from a single container open —
# e.g. sampling indices from metadata, then decoding just that window.
with open_video("video.mp4") as video:
    meta = video_metadata_from_container(video)
    keys = keyframe_indices(video)
    frames = list(read_frames_exact(video, start_frame=10, end_frame=20))

Every helper rewinds the container before reading, so call order doesn't matter. Requires seekable input; consume one frame read at a time.

open_video sets the container's decode thread_type up front (default "AUTO") — PyAV forbids changing it once a stream's codec is open, which happens on first metadata probe or frame read. Pass thread_type="NONE" if you fork worker processes around decoding (e.g. a DataLoader): an inherited AUTO-threaded decoder can deadlock post-fork.

Read Frames from Stream

from simple_video_utils.frames import read_frames_from_stream

# Useful for uploaded files or in-memory video data
with open("video.mp4", "rb") as f:
    meta, frames_gen = read_frames_from_stream(f)
    for frame in frames_gen:
        # Process each frame (numpy array)
        pass

Slice into Clips

from simple_video_utils.slicing import slice_video

# One MP4 (bytes) per (start, end) second range
clips = slice_video("video.mp4", [(0.0, 1.5), (2.0, 3.2)])

# Center-crop to a square and resize to 256x256 (e.g. for model input)
clips = slice_video("video.mp4", [(0.0, 1.5)], size=256)

Split an incoming video stream into packet-copied clips as it arrives — each clip is yielded as soon as its window has been read, without re-encoding:

from simple_video_utils.slicing import slice_video_stream

with open("video.mp4", "rb") as stream:
    for clip in slice_video_stream(stream, duration=0.5):
        process(clip)

Join clips in order. Overlapping slices from the same encoded stream are de-duplicated and remuxed losslessly; anything else is decoded and encoded once as H.264 MP4:

from simple_video_utils.joining import join_videos

video = join_videos(clips)

Remote Videos

from simple_video_utils.metadata import video_metadata
from simple_video_utils.frames import read_frames_exact

# Works with remote URLs
url = "https://example.com/video.mp4"
meta = video_metadata(url)
frames = list(read_frames_exact(url, 0, 5))

Development

pip install -e ".[dev]"
pytest tests/
ruff check .

Download files

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

Source Distribution

simple_video_utils-0.8.0.tar.gz (41.6 kB view details)

Uploaded Source

Built Distribution

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

simple_video_utils-0.8.0-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file simple_video_utils-0.8.0.tar.gz.

File metadata

  • Download URL: simple_video_utils-0.8.0.tar.gz
  • Upload date:
  • Size: 41.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for simple_video_utils-0.8.0.tar.gz
Algorithm Hash digest
SHA256 5c64e31a08acc0df1452b782beb3099bdcb742a4c74462c81963085bd60d9042
MD5 15e7935d8203d871db60e1623c2cb55c
BLAKE2b-256 9dff5c9a5881bf0af7360d514adbcf9ae459c5d39b45ec48db20d5a0acb65de4

See more details on using hashes here.

Provenance

The following attestation bundles were made for simple_video_utils-0.8.0.tar.gz:

Publisher: release.yaml on sign/simple-video-utils

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

File details

Details for the file simple_video_utils-0.8.0-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_video_utils-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0b2be11c886968292e2d9b24a8179b21b124ed92768f4facfe2cd0ffbc019bd2
MD5 e7ef9de78bdd862e69a1b342a03872dc
BLAKE2b-256 8af0f048c3ecaeb2767bc18069b962ba41117dc5c14744ac221fa17b9bd02b14

See more details on using hashes here.

Provenance

The following attestation bundles were made for simple_video_utils-0.8.0-py3-none-any.whl:

Publisher: release.yaml on sign/simple-video-utils

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

Release history Release notifications | RSS feed

0.9.1

2 files

0.9.0

2 files

This release

0.8.0 This release

2 files

0.7.4

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.0

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

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