Skip to main content

Video reduction tool

Project description

Video Encoder Utility

Overview

video_reducer scans a folder for supported videos (.mkv, .mp4, .wmv, .mwv) and re-encodes them with size-aware defaults. It keeps subtitles/metadata, flips containers when MP4 constraints are violated, and preserves a mirrored directory tree when you choose not to overwrite in place.

Key capabilities:

  • Automatic encoder selection with hardware-first preference (NVENC → QSV → AMF → x264) and explicit backend override flags.
  • Height presets (auto, 1080p, 720p, 480p, 360p) with bitrate scaling so smaller outputs also shrink file size.
  • Smart audio handling: copies compatible streams, forces stereo when sources are mono or pseudo-mono (e.g., WMV files with only one active channel), and warns about downmixing.
  • Hardware fallbacks: if a chosen hardware encoder fails to create a session, the tool transparently repeats the job with libx264 so the batch continues.

Prerequisites

  • Windows PowerShell 5.1 (default shell for the repo scripts).
  • Python 3.11+ with virtual environment support.
  • ffmpeg and ffprobe in PATH.
    • Hardware backends require vendor drivers and an ffmpeg build with NVENC/QSV/AMF enabled.

Installation

python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install --upgrade pip
pip install -e .

Usage

# Show CLI help
python -m video_reducer --help

# Reduce a folder, mirror outputs under ./output/<dir>, auto-select backend
python -m video_reducer --input D:\media --quality 720p

# Force Intel QSV, enable overwrite, run at debug verbosity
python -m video_reducer --input D:\media --encoder-backend qsv --overwrite --log-level debug

# Legacy wrapper remains available
python encode_videos.py --input D:\media

Key Flags

  • --input PATH: Directory scanned recursively for supported video extensions.
  • --encoder-backend BACKEND: auto (default), nvenc, x264, qsv, or amf.
  • --preferred-codec CODEC: Hint h264 or hevc; respected when the backend supports it.
  • --quality PRESET: Downscale preset (auto, 1080p, 720p, 480p, 360p).
  • --workers N: Concurrent encodes (default 1; hardware encoders generally behave best at 1).
  • --overwrite: Replace sources in place. When omitted, outputs land in ./output/<input-folder>.
  • --log-level LEVEL: info (default), debug, warning, etc.

Output Behavior

  • MP4 targets convert SubRip/ASS to mov_text automatically; incompatible streams trigger a fallback to MKV.
  • Attached artwork, metadata, and subtitle tracks are propagated.
  • When the output is larger than the input, a warning is emitted so you can review or delete the file.
  • Audio streams are copied when safe; otherwise they are re-encoded to AAC 192k stereo, duplicating the dominant channel if the source is effectively mono.

Encoder Backends

  • Auto: Queries ffmpeg encoders and picks the best available hardware backend (NVENC → QSV → AMF → x264).
  • NVENC/QSV/AMF: Uses vendor hardware. Hardware decode fallbacks are attempted before giving up.
  • x264: Software-only; always available.
  • If a hardware backend exhausts its attempts (e.g., Error creating a MFX session: -9 on QSV), the utility logs a warning and re-runs the encode with libx264 automatically.

Audio Handling

  • ffprobe insights drive copy-or-transcode decisions.
  • WMV inputs and other stereo tracks with severe channel imbalance trigger a sampling step; if only one channel has meaningful signal, the tool duplicates it so the result plays on both speakers.
  • Mono and surround sources are converted to stereo with informative log messages about the change.

Development

  • Run python -m pytest and flake8 before committing; coverage is enforced at 100%.
  • python -m video_reducer --help verifies CLI wiring after refactors.
  • VS Code launchers in .vscode/launch.json provide ready-to-run debug sessions.

Troubleshooting

  • Validate ffmpeg exposes the expected encoders: ffmpeg -hide_banner -encoders | Select-String nvenc.
  • Hardware backends may need up-to-date GPU/Media drivers; keep Windows and vendor packages current.
  • Delete partial outputs in output/ if you want to re-run without --overwrite.

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

jellycoder-0.1.0.tar.gz (63.7 kB view details)

Uploaded Source

Built Distribution

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

jellycoder-0.1.0-py3-none-any.whl (41.4 kB view details)

Uploaded Python 3

File details

Details for the file jellycoder-0.1.0.tar.gz.

File metadata

  • Download URL: jellycoder-0.1.0.tar.gz
  • Upload date:
  • Size: 63.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for jellycoder-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fc03365f9ae3275688b540b88a1763eb3ac1f02c810d7284fff8ada99ceb9fb1
MD5 c29c00528ad60784c92fe964f704c133
BLAKE2b-256 ed962bebc76686f6f1224faf810b10b66c899f66cac6ca4bd7d3541e7a897d40

See more details on using hashes here.

File details

Details for the file jellycoder-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: jellycoder-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 41.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for jellycoder-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fad9a8be86060f353021e3ffd964ea2d779471eae944810db4fb79d577aebd2d
MD5 092a44e72149bed94fc774943b1a3864
BLAKE2b-256 e5658bb3cb7b9ddae78c775341c9242354de96779b7aa2cad9c6b05f9ff89309

See more details on using hashes here.

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