Skip to content

DaneManes/powershell-transcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

This is a sometimes convoluted PowerShell script for a distributed transcoding farm. It handles everything from hardware-specific acceleration (NVENC/QSV) to "surgical" aspect ratio correction and multi-stage integrity validation.

LOL yes - I asked Gemini to write my readme file.

FFmpeg Distributed Worker - Local Sandbox & Surgical Repair (v7.6)

A robust PowerShell-based distributed transcoding worker designed to process media libraries for maximum compatibility with players like Jellyfin, Plex, and Emby. This script is built for "Surgical Repair"—ensuring that aspect ratios, interlace settings, and bitstream integrity are handled with higher precision than standard batch converters.

## Key Features

  • Distributed Architecture: Multiple workers can point to a single recode_files.txt list. File-locking (claiming) prevents two workers from processing the same file.
  • Hybrid Hardware Support: Automatically detects and utilizes NVIDIA NVENC or Intel QSV hardware acceleration.
  • Intelligent Aspect Ratio Correction: Features a "Snap-to-Grid" table to fix non-standard DAR (Display Aspect Ratio) metadata common in DVD rips.
  • Surgical Interlace Detection: Uses the idet filter to statistically analyze frames and apply motion-adaptive deinterlacing (YADIF/VPP) only when necessary.
  • Local Sandboxing: All heavy lifting is done in a local C:\Temp directory to reduce network congestion and prevent file corruption on the NAS during the encode.
  • Strict Audit Protocol: Validates every encode for bitstream errors, NAL unit issues, and "ballooning" file sizes before replacing the original.

## Operational Workflow

### 1. The Source List (recode_files.txt)

The script operates on a "Queue" system.

  • Input: It reads a plain text file (defined in $InputList) containing the full UNC paths of videos to be processed.
  • The Claim: When a worker starts a file, it creates a _working.txt flag file next to the source. Other workers seeing this flag will skip that file.
  • The Swap: Once validated, the script performs a "Transactional Swap":
  1. The original .mp4 is renamed to .olx (Backup).
  2. The new file is moved into place.
  3. The _working.txt is changed to H264AAC.txt to mark completion.

### 2. The Sandbox & MOOV Atom

To ensure smooth streaming (Fast Start), the script performs a two-pass local process:

  1. Encode: The file is transcoded to a local fix_ file.
  2. Optimize: It runs a second pass with -movflags +faststart to move the MOOV atom to the front of the file, allowing Jellyfin users to start playback before the full file is buffered.

### 3. Logging & Monitoring

  • Central Log: Every worker reports its status (Startup, Claim, Analysis, Success/Failure) to a shared $CentralLog file.
  • Session Logs: Detailed FFmpeg output for every single file is saved to the \\NAS\Logging\Recoding directory. If a file fails, you can check the specific log to see if it was a bitstream error or a hardware crash.

## Defective File & Redo Handling

The script is designed to be "hands-off." If a file fails the Strict Audit (e.g., detected corruption, DTS sync issues, or encoder crashes), the following happens:

  • No Overwrite: The original source file remains untouched.

  • Quarantine: The failed encode is moved to a sub-folder named after the movie inside the $ParkingDir.

  • Redo Categorization: * Files that failed but are High Definition are flagged in the HD_Redo directory.

  • Standard Definition failures go to SD_Redo.

  • Error Flagging: An _error.txt file is created next to the source to prevent the script from infinitely retrying a file that has fundamental stream corruption.


## Configuration

Before running, update the variables in the param block of the script:

Variable Description
$InputList Path to your text file containing the list of movies to recode.
$CentralLog Shared log file where all workers report status.
$FFmpegPath Path to your ffmpeg.exe (preferably on a fast network share or local drive).
$UNCPaths Array of network paths the script should attempt to map/authenticate.
$Credentials The username/password used to access your NAS shares.

## Control Signals

You can control all active workers remotely by creating empty text files:

  • Pause: Create a file named pause.txt in the Processing folder. Workers will finish their current frame and wait.
  • Stop: Create a file named stop.txt. Workers will finish their current file and exit gracefully.

## Requirements

  • OS: Windows 10/11 or Windows Server.
  • PowerShell: 7.x mandatory
  • Hardware: NVIDIA GPU (GeForce 10-series+) or Intel CPU with QuickSync.
  • Environment: "Below Normal" process priority is automatically set to ensure the worker doesn't lag the host OS.

About

A distributed multi-GPU transcoding system based on Windows PowerShell

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages