VideoTools/scripts/git_converter/modules/hardware.sh
Jake P fa6ff5aba1 Turned GIT Converter Modular
📋 GIT Converter v2.7 - Feature Summary & Changes

🚀 Major New Features Added

🎬 Codec & Container Selection
- AV1 vs HEVC encoding - Choose between next-gen AV1 or mature HEVC
- MKV vs MP4 containers - Flexibility vs device compatibility
- User-controlled output format - Full control over final file type

⚙️ Advanced Quality Control
- Source Quality mode - Bypass quality changes unless required
- CRF options - 16 (near-lossless), 18 (recommended), 20 (balanced)
- Custom bitrate control - Exact bitrate specification for precise file sizes
- Encoder-specific optimization - Different parameters for AV1 vs HEVC

🎮 GPU/Encoder Selection
- Auto-detection - Intelligent hardware detection with benchmarking
- Manual selection - Choose specific GPU/encoder:
  - NVIDIA NVENC (HEVC/AV1)
  - AMD AMF (HEVC/AV1)
  - Intel Quick Sync (HEVC/AV1)
  - CPU encoding (SVT-AV1/x265)
  - Custom encoder selection
- Two-stage interface - Auto-detect first, then option to override

🎨 Enhanced Color Correction
- 8 specialized presets:
  - 2000s DVD Restore
  - 90s Quality Restore
  - VHS Quality Restore
  - Anime Preservation
  - Pink skin tone restoration (Topaz AI fix)
  - Warm/Cool color boosts
- Fixed filter parameters - Resolved unsharp filter matrix size issues

🔧 Technical Improvements

📦 Modular Architecture
- Separated concerns into focused modules:
  - hardware.sh - GPU detection & encoder selection
  - codec.sh - Codec & container options
  - quality.sh - Quality modes & bitrate control
  - filters.sh - Resolution, FPS, color correction
  - encode.sh - FFmpeg execution & monitoring

 Performance Optimizations
- Hardware benchmarking - Tests encoder speed before selection
- Timeout protection - Prevents hanging during encoder tests
- Better error reporting - Shows SUCCESS/FAILED/NOT AVAILABLE status
- Improved timing logic - Cross-platform compatible timing

🖥️ User Experience
- Two-stage workflow - Auto-detect → confirm/override
- Clear menu navigation - Numbered options with validation
- Real-time feedback - Shows what's being tested/selected
- Fixed input validation - Proper regex for multi-digit numbers

🐛 Bug Fixes
- Fixed unsharp filter - Corrected matrix size requirements (odd numbers only)
- Fixed hue parameter - Corrected eq filter syntax
- Fixed encoder detection - Improved hardware detection logic
- Fixed menu display - Resolved command substitution output capture issues

🎯 Key Benefits
- Full user control over encoding parameters
- Hardware optimization with automatic fallbacks
- Professional quality restoration options
- Modular design for easy maintenance
- Cross-platform compatibility (Windows/Linux)
2025-12-14 03:00:44 +00:00

82 lines
3.1 KiB
Bash

#!/bin/bash
# ===================================================================
# Hardware Detection Module - GIT Converter v2.7
# Optimized GPU and encoder detection
# ===================================================================
detect_hardware() {
echo "Detecting hardware and optimal encoder..." >&2
# Detect GPU type
gpu_type="none"
if command -v nvidia-smi >/dev/null 2>&1 && nvidia-smi >/dev/null 2>&1; then
gpu_type="nvidia"
echo " ✓ NVIDIA GPU detected" >&2
elif command -v lspci >/dev/null 2>&1 && lspci 2>/dev/null | grep -iq "amd\|radeon\|advanced micro devices"; then
gpu_type="amd"
echo " ✓ AMD GPU detected" >&2
elif command -v lspci >/dev/null 2>&1 && lspci 2>/dev/null | grep -iq "intel.*vga\|intel.*display"; then
gpu_type="intel"
echo " ✓ Intel GPU detected" >&2
else
echo " ⚠ No GPU detected, will use CPU encoding" >&2
fi
# Test encoder availability and speed
local best_encoder=""
local best_time=999999
# Test candidates based on GPU type
local candidates=()
case $gpu_type in
nvidia) candidates=("hevc_nvenc" "av1_nvenc" "libsvtav1" "libx265") ;;
amd) candidates=("hevc_amf" "av1_amf" "libsvtav1" "libx265") ;;
intel) candidates=("hevc_qsv" "av1_qsv" "libsvtav1" "libx265") ;;
*) candidates=("libsvtav1" "libx265") ;;
esac
# Quick benchmark each encoder
for enc in "${candidates[@]}"; do
if ffmpeg -hide_banner -loglevel error -encoders | grep -q "$enc"; then
echo " Testing $enc..." >&2
start_time=$(date +%s.%N)
if ffmpeg -hide_banner -loglevel error -y -f lavfi -i "testsrc=duration=2:size=320x240:rate=1" \
-c:v "$enc" -f null - >/dev/null 2>&1; then
end_time=$(date +%s.%N)
test_time=$(echo "$end_time - $start_time" | bc -l 2>/dev/null || echo "1")
echo " $enc: ${test_time}s" >&2
if (( $(echo "$test_time < $best_time" | bc -l 2>/dev/null || echo "0") )); then
best_time=$test_time
best_encoder=$enc
fi
fi
fi
done
if [[ -n "$best_encoder" ]]; then
echo " ✓ Selected: $best_encoder (fastest encoder)" >&2
echo "" >&2
echo "Hardware Detection Summary:" >&2
echo " GPU Type: $gpu_type" >&2
echo " Available Encoders Tested: ${candidates[*]}" >&2
echo " Optimal Encoder: $best_encoder" >&2
echo " Benchmark Time: ${best_time}s" >&2
echo "" >&2
echo "Press space to continue..." >&2
read -n 1 -s
echo "$best_encoder"
return 0
else
echo " ⚠ No working encoder found, defaulting to libx265" >&2
echo "" >&2
echo "Hardware Detection Summary:" >&2
echo " GPU Type: $gpu_type" >&2
echo " Available Encoders Tested: ${candidates[*]}" >&2
echo " Fallback Encoder: libx265" >&2
echo "" >&2
echo "Press space to continue..." >&2
read -n 1 -s
echo "libx265"
return 0
fi
}