A custom FFmpeg and FFprobe wrapper for precise frame extraction and video metadata
Project description
Custom FFmpeg
A custom FFmpeg and FFprobe wrapper for precise frame extraction and video metadata without OpenCV dependencies.
Features
- Variable Frame Rate (VFR) support: Extracts precise timestamps using ffprobe.
- Lazy Frame Loader: Exact 1-to-1 mapping of encoded video frames to extracted images.
- Video Utilities: Extract rotation, dimensions, and FPS relying purely on FFmpeg/FFprobe.
- Zero third-party dependencies: Does not require
opencv-pythonor other heavy image processing libraries.
Prerequisites
This library requires FFmpeg and FFprobe to be installed on your system and available in your system's PATH. You can verify your installation by running:
ffmpeg -version
ffprobe -version
Installation
You can install this module directly into any project using pip.
Install Locally
If you have cloned or downloaded this repository, navigate to your new project's environment and install it using the path to the custom_ffmpeg directory:
# Standard installation
pip install /path/to/custom_ffmpeg
# Editable installation (useful if you are actively developing the custom_ffmpeg module)
pip install -e /path/to/custom_ffmpeg
Install via Git
If this module is hosted in a git repository, you can install it directly via Git:
pip install git+https://github.com/yourusername/your-repo.git#subdirectory=scripts/custom_ffmpeg
Usage
1. Extracting Frames (LazyFrameLoader)
The LazyFrameLoader will use FFmpeg to extract frames into a temporary folder. Since there are no OpenCV dependencies, accessing an index will return the absolute file path to the extracted PNG frame.
from custom_ffmpeg import LazyFrameLoader
# Initialize the loader (this will automatically run ffmpeg to extract frames)
video_path = "sample_video.mp4"
loader = LazyFrameLoader(video_path)
print(f"Total frames extracted: {len(loader)}")
print(f"Video FPS: {loader.fps}")
# Access the first frame
frame_path = loader[0]
print(f"Path to first frame: {frame_path}")
# Calculate true time delta (dt) between frames for accurate kinematics
# This is especially important for VFR (Variable Frame Rate) videos.
dt = loader.get_dt(1)
print(f"Time delta between frame 0 and 1: {dt} seconds")
# Cleanup the temporary extracted frames directory when done
loader.release()
2. Getting Video Metadata (VideoUtils)
VideoUtils uses FFprobe to extract accurate metadata from the video without loading any frames.
from custom_ffmpeg import VideoUtils
video_path = "sample_video.mp4"
stats = VideoUtils.get_video_stats(video_path)
if stats:
print(f"Resolution: {stats['width']}x{stats['height']}")
print(f"FPS: {stats['fps']}")
print(f"Total Frames: {stats['frame_count']}")
print(f"Rotation: {stats['rotation']} degrees")
Publishing to PyPI
If you want to publish this package to the public Python Package Index (PyPI) or a private repository, follow these steps:
-
Install Build Tools: Ensure you have
buildandtwineinstalled in your environment.pip install build twine
-
Build the Package: Run the following command from the same directory as
pyproject.toml. It will create adist/folder containing a.tar.gzsource archive and a.whlbuilt distribution.python -m build
-
Test the Build Locally (Optional but Recommended): Before uploading, it is a good idea to verify the built package locally.
First, check if the package description will render correctly on PyPI:
twine check dist/*
Next, you can test installing the compiled
.whlfile in a fresh virtual environment to ensure it works exactly as the end-user will experience it:# Create a test virtual environment python -m venv test_env source test_env/bin/activate # Install the built wheel file pip install dist/custom_ffmpeg-0.1.0-py3-none-any.whl # Verify the import works python -c "import custom_ffmpeg; print('Success!')" # Clean up and exit deactivate rm -rf test_env
-
Upload to PyPI: Use twine to upload the generated archives. You will be prompted for your PyPI API token (username is
__token__).python -m twine upload dist/*
(To test the upload safely without publishing to the real PyPI, use TestPyPI:
python -m twine upload --repository testpypi dist/*)
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 custom_ffmpeg_v-0.1.0.tar.gz.
File metadata
- Download URL: custom_ffmpeg_v-0.1.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee5b753371e73f88365bfdbab25e09bc5eacc1abf2d51b78fc9e958490b1cd19
|
|
| MD5 |
e34cfc217d4c5aad56f835c4a0599725
|
|
| BLAKE2b-256 |
c2fe42f3ae22b633f29ee9b9555165ce9a0be0f0150abe506a1d8549dfd71a38
|
File details
Details for the file custom_ffmpeg_v-0.1.0-py3-none-any.whl.
File metadata
- Download URL: custom_ffmpeg_v-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d687d0dfacec9387ac3b1289785108fecc0779498855cc85c7327bd054b998a0
|
|
| MD5 |
cfce5bd3b520b83b6f7769d5d00b05de
|
|
| BLAKE2b-256 |
c773453514cfc97aff1ae67844152ee4168a23a892aea36a096d253e32983dda
|