This repository is a fork of soCzech/TransNetV2 that introduces several enhancements:
- OpenCV CUDA Integration: Accelerated frame extraction leveraging NVIDIA CUDA.
- PyTorch Backend: Native PyTorch model loading and inference for easier integration and extension.
- Logging: Structured logging via Python
logging
module for better observability. - Progress Bar: Real-time progress feedback using
tqdm
during frame extraction and scene detection.
- Fast Frame Extraction: Utilizes OpenCV with CUDA support, if available, falling back to CPU otherwise.
- PyTorch Model: Loads TransNetV2 weights via PyTorch, supports GPU/CPU inference.
- Scene Boundary Detection: Produces accurate shot boundary detection with configurable thresholds.
- Logging & Monitoring: INFO-level logs for key steps and errors.
- Progress Feedback:
tqdm
progress bars for both frame extraction and scene prediction.
-
Clone this repository:
git clone https://github.com/yourusername/TransNetV2.git
-
Install dependencies (tested on Python 3.12):
pip install -r requirements.txt
-
Install PyTorch:
-
Build and Install OpenCV CUDA
https://machinelearningprojects.net/build-opencv-with-cuda-and-cudnn/
-
Install package:
python setup.py install
from transnetv2pt import predict_video
# Detect scenes in a video file
target = "path/to/video.mp4"
scenes = predict_video(str(target), device='cuda', show_progressbar=True)
print(scenes)
from pathlib import Path
from transnetv2pt import predict_video
import cv2
video_path = Path("video.mkv")
scenes = predict_video(str(video_path), show_progressbar=True)
cap = cv2.VideoCapture(str(video_path))
for i, (start, end) in enumerate(scenes):
cap.set(cv2.CAP_PROP_POS_FRAMES, start)
ret, frame = cap.read()
if ret:
cv2.imwrite(f"scene_{i}_start.png", frame)
cap.release()
- CUDA Support: Automatic detection via
cv2.cuda.getCudaEnabledDeviceCount()
. - Device Selection: Pass
device='cpu'
ordevice='cuda'
topredict_video()
. - Progress Bars: Enable via
show_progressbar=True
in both frame extraction and scene detection.
Contributions are welcome! Please open issues and submit pull requests for bug fixes and enhancements.
This project inherits the MIT License from the original TransNetV2 repository. See LICENSE
for details.