VTrim
VTrim is a lightweight, efficient video analysis and trimming tool. It automatically finds segments containing people and can output a trimmed video instantly—without re-encoding, preserving original quality at blazing speed.
• ⚡ Lossless • 🎥 Professional edit-ready XML • 🔍 AI-powered detection
Features
- 🚀 Fast Analysis: Model caching and batch inference for 50-80% faster processing
- ✂️ Lossless Trimming: FFmpeg stream copy (-c copy) - no quality degradation
- 🎬 Professional XML: Export FCP7 XML for DaVinci Resolve/Premiere Pro
- 🤖 AI Detection: YOLOv8 human detection with configurable sensitivity
- ⚙️ Flexible Configuration: Centralized config for easy customization
- 📊 JSON Output: Machine-readable results for automation
Installation
Install via pip:
pip install vtrim
Quick Start
Basic Usage
Analyze Video (Detect Humans)
vtrim --input video.mp4
# or use the short form:
vtrim -i video.mp4
Output:
{"segments": [{"start": 2.3, "end": 5.8}, {"start": 10.1, "end": 14.7}]}
Trim Video Directly
vtrim --input your_video.mp4 --output output.mp4
# or use short forms:
vtrim -i your_video.mp4 -o output.mp4
- Uses FFmpeg stream copy (-c copy) → no re-encoding, no quality loss.
- Automatically merges nearby detections and adds padding for smooth transitions.
Export Edit Timeline to DaVinci Resolve / Premiere Pro
Preserve the full timeline (including gaps) as an FCP7 XML for professional editing:
vtrim --input your_video.mp4 --export-xml timeline.xml
# or:
vtrim -i your_video.mp4 --export-xml timeline.xml
Audio and video are perfectly synchronized and split per segment.
Advanced Examples
High Sensitivity Detection
vtrim --input video.mp4 \
--conf-threshold 0.15 \
--output sensitive_trim.mp4
Lower threshold = more detections (including false positives)
Conservative Detection with Large Padding
vtrim --input video.mp4 \
--conf-threshold 0.4 \
--padding 3.0 \
--output conservative_trim.mp4
Higher threshold + more padding = fewer, longer segments
Merge All Nearby Detections
vtrim --input video.mp4 \
--gap-tolerance 10.0 \
--output merged_trim.mp4
Large gap tolerance merges nearby segments into continuous blocks
Combined Workflow
vtrim --input your_video.mp4 \
--output output.mp4 \
--export-xml timeline.xml
# or use short forms for faster typing:
vtrim -i your_video.mp4 -o output.mp4 --export-xml timeline.xml
Get Raw Detection Results (JSON)
Print detected time segments to stdout for scripting or integration:
vtrim --input meeting.mp4
Output:
{
"segments": [
{ "start": 2.3, "end": 5.8 },
{ "start": 10.1, "end": 14.7 }
]
}
Programmatic Usage (Python API)
from vtrim.analyzer import detect_human
from vtrim.segment_utils import merge_segments, apply_padding
from vtrim.ffmpeg_utils import cut_video_with_ffmpeg
from vtrim.xml_export import export_fcp7_xml
from vtrim import Config
# Detect humans
raw_segments = detect_human("video.mp4", conf_threshold=0.25)
# Process segments
merged = merge_segments(raw_segments, gap_tolerance=4.0)
padded = apply_padding(merged, padding=1.0)
# Cut video
cut_video_with_ffmpeg("video.mp4", padded, "output.mp4")
# Export XML
export_fcp7_xml("video.mp4", padded, "timeline.xml", video_duration=120.5)
# Access configuration
print(f"Default threshold: {Config.CONF_THRESHOLD}")
print(f"Default padding: {Config.PADDING}")
Command-Line Options
| Option | Type | Default | Description |
|---|---|---|---|
--input, -i |
Required | - | Path to input video file |
--output, -o |
Optional | - | Path to save trimmed video |
--export-xml |
String | - | Path to export FCP7 XML |
--conf-threshold |
Float | 0.25 | Detection confidence (0.0-1.0) |
--padding |
Float | 1.0 | Seconds added before/after segments |
--gap-tolerance |
Float | 4.0 | Max gap to merge segments |
--verbose |
Flag | Off | Show detailed progress |
📌 Note: Human detection is always enabled. Just provide the input video and VTrim will automatically detect human presence.
Performance
Optimizations (v0.1.4+)
- Model Caching: 50-80% faster on subsequent runs (singleton pattern)
- Batch Inference: 20-30% faster processing (batch size = 4)
- Dynamic Resolution: Automatic video metadata detection
- Enhanced Error Handling: Better validation and error messages
Benchmark Example
For a 10-minute video at 30 FPS:
- Before: ~3-4 minutes total
- After: ~2-2.5 minutes (with cached model)
Configuration
All defaults are defined in vtrim/config.py:
from vtrim import Config
# Customize settings
Config.CONF_THRESHOLD = 0.15 # Higher sensitivity
Config.PADDING = 2.0 # More padding
Config.GAP_TOLERANCE = 10.0 # Merge nearby detections
Config.SAMPLE_FPS = 2.0 # Analysis sample rate (2 FPS)
Config.BATCH_SIZE = 4 # Inference batch size
Output Formats
JSON Output (stdout)
Machine-readable format for scripting:
{
"segments": [
{"start": 2.3, "end": 5.8},
{"start": 10.1, "end": 14.7}
]
}
FCP7 XML (DaVinci Resolve / Premiere Pro)
Compatible with:
- DaVinci Resolve
- Adobe Premiere Pro
- Final Cut Pro 7
Features:
- Full timeline (valid + invalid segments)
- Color-coded clips (blue=keep, gray=skip)
- Synchronized audio/video
- Frame-accurate timing
Trimmed Video
- Format: MP4 (same as input)
- Codec: Unchanged (stream copy)
- Quality: Lossless (no re-encoding)
Troubleshooting
Error: "FFmpeg not found"
Solution: Install FFmpeg:
# macOS
brew install ffmpeg
# Ubuntu/Debian
sudo apt-get install ffmpeg
# Windows
# Download from https://ffmpeg.org/download.html
Error: "Input video file not found"
Solution: Check that the file path is correct (absolute or relative to current directory).
Error: "No human segments detected"
Solutions:
- Lower
--conf-threshold(e.g., 0.15 for higher sensitivity) - Verify the video actually contains people
- Check that
vtrim/yolov8n.ptmodel file exists
Slow Analysis
Tips:
- First run downloads the model (one-time delay)
- Subsequent runs are 50-80% faster (model cached)
- Reduce
Config.SAMPLE_FPSfor faster but less accurate analysis
Best Practices
- Test with short videos first: Verify settings before processing long videos
- Keep original backups: Always preserve source files until satisfied
- Use verbose mode for debugging:
vtrim --input video.mp4 --verbose - Combine outputs for flexibility: Generate both trimmed video AND XML timeline
Requirements
- Python 3.7+
- FFmpeg (must be in PATH)
- Dependencies:
- opencv-python
- ultralytics
- setuptools
Environment Variables
| Variable | Values | Effect |
|---|---|---|
ANALYZER_PROGRESS_JSON |
"0" (default), "1" | Output progress as JSON to stderr |
Example:
ANALYZER_PROGRESS_JSON=1 vtrim --input video.mp4
Project Structure
vtrim/
├── __init__.py # Package initialization, exports Config
├── analyzer.py # Human detection logic
├── cli.py # Command-line interface
├── config.py # Configuration settings
├── ffmpeg_utils.py # FFmpeg video processing
├── model.py # YOLO model loading
├── segment_utils.py # Segment merging/padding
├── xml_export.py # FCP7 XML export
└── yolov8n.pt # Pre-trained YOLO model
Notes
- The underlying model is YOLOv8n (PyTorch format), optimized for CPU inference.
- Video trimming uses FFmpeg stream copy (
-c copy), so it's fast and lossless—no quality degradation. - Progress updates are printed to
stderrduring analysis (every 5% for known-length videos). - For automation, set the environment variable
ANALYZER_PROGRESS_JSON=1to receive machine-readable progress messages onstderr.
Documentation
- README.md: This file - comprehensive overview and quick start guide
- CHANGELOG.md: Detailed version history, optimizations, and upgrade notes
For more detailed usage examples and advanced configurations, see the inline documentation in vtrim/config.py and individual module docstrings.
Support
- GitHub: https://github.com/chiaweilee/vtrim
- Issues: https://github.com/chiaweilee/vtrim/issues
- License: Apache License v2
Version
Current version: 0.2.0
See CHANGELOG.md for the latest updates and migration notes.
Metadata
Release files for vtrim 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| vtrim-0.2.1.tar.gz | 6.0 MB | Without provenance | Details for vtrim-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vtrim-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for vtrim-0.2.1-py3-none-any.whl |
Total release size: 12.0 MB
Release files / vtrim-0.2.1.tar.gz
| Download URL | vtrim-0.2.1.tar.gz |
|---|---|
| Size | 6.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
25557b88c2de40935b4a98ef134ca82412ae30bc7576887d736679152e31f19f
|
|
BLAKE2b-256 checksum How to use checksums |
ac3d11230defe265927e35f15e0de5885fd25c0600fc541476ad7e0b65569387
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.16
|
Release files / vtrim-0.2.1-py3-none-any.whl
| Download URL | vtrim-0.2.1-py3-none-any.whl |
|---|---|
| Size | 6.0 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5f3680c4770ec0f1d1fdff0c4cdf098006d4d98fa659d50cda1160ed68844d77
|
|
BLAKE2b-256 checksum How to use checksums |
4dc0ed784c5d848252b0d5fa89a62b086b16d138d2becb6b85634cc50245d089
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.16
|
Security for vtrim 0.2.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.