Skip to main content

GPU-accelerated short video generator using NVIDIA VPF and PyTorch.

Project description

Shorts Maker (GPU Optimized)

Shorts Maker generates vertical video clips from longer gameplay footage. This Python library and CLI tool detects scenes, computes audio and video action profiles (sound intensity + visual motion), and combines them to rank scenes by overall intensity. It then crops to the desired aspect ratio and renders ready‑to‑upload shorts.

This version has been heavily optimized for NVIDIA GPUs using CUDA.

For the original CPU-only version, please visit Shorts Maker.

Tests Linting codecov License: MIT Python Docker PyTorch CUDA

Read the Full Documentation 📚

Features

  • GPU-Accelerated Processing:
    • Hardware Decoding & Resizing: Native NVIDIA Video Processing Framework (VPF) integration via PyNvCodec. Decodes, resizes, and converts color spaces directly on NVDEC.
    • Scene Detection: Custom implementation using VPF and OpenCV.
    • Audio Analysis: Uses torchaudio on GPU for fast RMS and spectral flux calculation.
    • Video Analysis: Zero-copy GPU memory streaming for stable motion estimation (replaces heavy frame indices).
    • Image Processing: Native PyTorch operators used for heavy operations like blurring backgrounds (separable convolutions).
    • Rendering: Custom PyTorch+NVENC engine for high-performance rendering (MoviePy removed from render path).
  • Audio + video action scoring:
    • Combined ranking with tunable weights (defaults: audio 0.6, video 0.4).
  • Scenes ranked by combined action score rather than duration.
  • Smart Scene Cutting:
    • Preferentially selects complete scenes if they fit within the time limit.
    • Scene Padding: Adds a 1.5-second buffer to the end of scenes to capture exit animations and fades.
    • Smart Trimming: For long scenes, searches for "quiet" moments (low audio/motion) to cut, avoiding abrupt endings.
  • Smart cropping with optional blurred background for non‑vertical footage.
  • Retry logic during rendering to avoid spurious failures.
  • Configuration via .env environment variables.

Requirements

  • NVIDIA GPU with CUDA support.
  • NVIDIA Drivers (compatible with CUDA 13.0+ recommended).
  • Python 3.12+
  • FFmpeg (used for audio extraction and NVENC encoding).
  • System libraries: libgl1, libglib2.0-0 (often needed for vision libraries).

Python dependencies (see pyproject.toml):

  • torch, torchaudio (with CUDA support)
  • PyNvCodec, PytorchNvCodec (Video Processing Framework)

Installation

Manual Setup (Linux with CUDA)

Ensure you have the NVIDIA drivers and CUDA toolkit installed.

git clone https://github.com/artryazanov/shorts-maker-gpu.git
cd shorts-maker-gpu
python3 -m venv venv
source venv/bin/activate

# Install the library and its dependencies
pip install -e .

If you encounter issues with PyTorch not finding the GPU, refer to its installation guide for your specific CUDA version.

Usage

  1. Place source videos inside the gameplay/ directory.
  2. Run the CLI tool:
shorts-maker process

You can optionally customize the input and output directories and scene limits:

shorts-maker process --input-dir my_videos/ --output-dir my_shorts/ --scene-limit 3
  1. Generated clips are written to the generated/ directory.

During processing, the log shows an action score for each combined scene and the final list sorted by that score. The top scenes (by action intensity) are rendered first using NVENC.

Docker (Recommended)

The easiest way to run this application is using Docker with the NVIDIA Container Toolkit.

Prerequisite: NVIDIA Container Toolkit must be installed on the host.

Build and run:

docker build -t shorts-maker .

# Run with GPU access
docker run --rm \
    --gpus all \
    -v $(pwd)/gameplay:/app/gameplay \
    -v $(pwd)/generated:/app/generated \
    --env-file .env \
    shorts-maker

Note the --gpus all flag, which is essential for the application to access hardware acceleration.

Configuration

Copy .env.example to .env and adjust values as needed.

Supported variables (defaults shown):

  • TARGET_RATIO_W=9 — Width part of the target aspect ratio (e.g., 9 for 9:16).
  • TARGET_RATIO_H=16 — Height part of the target aspect ratio (e.g., 16 for 9:16).
  • SCENE_LIMIT=4 — Maximum number of top scenes rendered per source video.
  • X_CENTER=0.5 — Horizontal crop center in range [0.0, 1.0].
  • Y_CENTER=0.5 — Vertical crop center in range [0.0, 1.0].
  • MAX_ERROR_DEPTH=3 — Maximum retry depth if rendering fails.
  • MIN_SHORT_LENGTH=15 — Minimum short length in seconds.
  • MAX_SHORT_LENGTH=179 — Maximum short length in seconds.
  • MAX_COMBINED_SCENE_LENGTH=300 — Maximum combined length (in seconds).

Development

Linting

This project uses ruff for fast linting.

pip install ruff
ruff check .

Running Tests

Unit tests live in the tests/ folder. Run them with:

pytest -q

Note: The tests are designed to mock GPU availability if it is missing, so they can run in standard CI environments.

Troubleshooting

  • "Torch not installed" / "CUDA not available": Ensure you are running inside the Docker container with --gpus all or have the correct CUDA toolkit installed locally.
  • NVENC Error: If h264_nvenc fails, the script attempts to fall back to software encoding (libx264). Check if your GPU supports NVENC and if the drivers are up to date.

License

This project is released under the MIT License.

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

shorts_maker_gpu-0.1.1.tar.gz (37.4 kB view details)

Uploaded Source

Built Distribution

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

shorts_maker_gpu-0.1.1-py3-none-any.whl (29.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for shorts_maker_gpu-0.1.1.tar.gz
Algorithm Hash digest
SHA256 37f1fc530c5474f72e1eab57a40fe23fd666b4dcc7913c9dc7e6a375750a5af5
MD5 75c78a04174a627ecd5b24a71292f3e1
BLAKE2b-256 cc9b0c4e0a5971d3764fe7ac3457f891685296db8c267782e7f064a05de6650c

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on artryazanov/shorts-maker-gpu

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

File details

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

File metadata

File hashes

Hashes for shorts_maker_gpu-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a4c16189c53428daaa1f229c7959cb3ca9f27b1d21bb1ef7b1b464703cc17480
MD5 d1a6f802007f2fe1f23256f8fb4e92da
BLAKE2b-256 9112e1e918e98a9f0da177f8637efbc44a560e3b047cefd73767e2bcf133efd8

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on artryazanov/shorts-maker-gpu

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