VideoTools/scripts/git_converter/modules/quality.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

157 lines
6.4 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# ===================================================================
# Optimized Quality Settings Module - GIT Converter v2.7
# Encoder-specific optimal parameters for maximum speed
# ===================================================================
get_quality_settings() {
local encoder="$1"
clear
cat << "EOF"
╔═══════════════════════════════════════════════════════════════════╗
║ Choose Quality Mode ║
╚═══════════════════════════════════════════════════════════════╝
1) Near-Lossless (CRF 16) - Maximum quality
2) High Quality (CRF 18) - Recommended
3) Good Quality (CRF 20) - Balanced
4) Custom bitrate
EOF
echo
while true; do
read -p " Enter 14 → " b
if [[ -n "$b" && "$b" =~ ^[1-4]$ ]]; then
break
else
echo " Invalid input. Please enter a number between 1 and 4."
fi
done
# Encoder-specific optimal settings
case $encoder in
*nvenc*)
quality_params="-crf ${b:16:18:20:22} -preset fast -tune ll"
quality_name="NVENC CRF ${b:16:18:20:22}"
;;
*amf*)
quality_params="-crf ${b:16:18:20:22} -quality 23 -rc 1"
quality_name="AMF CRF ${b:16:18:20:22}"
;;
*qsv*)
quality_params="-crf ${b:16:18:20:22} -preset fast -global_quality 23"
quality_name="QSV CRF ${b:16:18:20:22}"
;;
libsvtav1)
quality_params="-crf ${b:16:18:20:22} -preset 8 -tile-rows 2 -tile-columns 2"
quality_name="SVT-AV1 CRF ${b:16:18:20:22}"
;;
libx265)
quality_params="-crf ${b:16:18:20:22} -preset fast -tune fastdecode"
quality_name="x265 CRF ${b:16:18:20:22}"
;;
*)
quality_params="-crf ${b:16:18:20:22}"
quality_name="CRF ${b:16:18:20:22}"
;;
esac
# Handle custom bitrate with exact control and override option
if [[ "$b" == "4" ]]; then
echo
echo "Choose custom bitrate mode:"
echo " 1) Target bitrate (exact match)"
echo " 2) Target bitrate with optimal adjustment"
echo
while true; do
read -p " Enter 12 → " bitrate_mode
if [[ -n "$bitrate_mode" && "$bitrate_mode" =~ ^[1-2]$ ]]; then
break
else
echo " Invalid input. Please enter 1 or 2."
fi
done
if [[ "$bitrate_mode" == "1" ]]; then
echo
echo "Enter target bitrate (e.g., 3200k, 5000k, 8000k):"
read -p "→ " custom_bitrate
# Clean input - remove control characters and spaces
custom_bitrate=$(echo "$custom_bitrate" | tr -cd '[:alnum:]k')
# Validate exact bitrate format
if [[ -n "$custom_bitrate" && "$custom_bitrate" =~ ^[0-9]+k$ ]]; then
quality_params="-b:v $custom_bitrate"
quality_name="Exact $custom_bitrate"
else
echo " Invalid bitrate format. Use format like 3200k, 5000k"
quality_params="-crf 18"
quality_name="HEVC CRF 18"
fi
else
echo
echo "Enter target bitrate (e.g., 3200k, 5000k, 8000k):"
read -p "→ " custom_bitrate
# Clean input - remove control characters and spaces
custom_bitrate=$(echo "$custom_bitrate" | tr -cd '[:alnum:]k')
# Validate and adjust bitrate to nearest standard tier for optimal compression
if [[ -n "$custom_bitrate" && "$custom_bitrate" =~ ^[0-9]+k$ ]]; then
# Extract numeric value and round to nearest standard bitrate
target_kbps=$(echo "$custom_bitrate" | sed 's/k//')
# Standard bitrate tiers with optimal compression
case $target_kbps in
[0-1499]) adjusted_bitrate="1500k" ;;
[1500-2499]) adjusted_bitrate="2000k" ;;
[2500-3499]) adjusted_bitrate="2500k" ;;
[3500-4499]) adjusted_bitrate="3000k" ;;
[4500-5499]) adjusted_bitrate="3500k" ;;
[5500-6499]) adjusted_bitrate="4000k" ;;
[6500-7499]) adjusted_bitrate="4500k" ;;
[7500-8499]) adjusted_bitrate="5000k" ;;
[8500-9499]) adjusted_bitrate="5500k" ;;
[9500-11499]) adjusted_bitrate="6000k" ;;
[11500-13499]) adjusted_bitrate="7000k" ;;
[13500-15499]) adjusted_bitrate="8000k" ;;
*) adjusted_bitrate="9000k" ;;
esac
echo " Target: $target_kbps kbps → Adjusted to: $adjusted_bitrate"
case $encoder in
*nvenc*)
quality_params="-b:v $adjusted_bitrate -preset fast -tune ll"
quality_name="Custom NVENC $adjusted_bitrate"
;;
*amf*)
quality_params="-b:v $adjusted_bitrate -quality 23 -rc 1"
quality_name="Custom AMF $adjusted_bitrate"
;;
*qsv*)
quality_params="-b:v $adjusted_bitrate -preset fast -global_quality 23"
quality_name="Custom QSV $adjusted_bitrate"
;;
libsvtav1)
quality_params="-b:v $adjusted_bitrate -preset 8 -tile-rows 2 -tile-columns 2"
quality_name="Custom SVT-AV1 $adjusted_bitrate"
;;
libx265)
quality_params="-b:v $adjusted_bitrate -preset fast -tune fastdecode"
quality_name="Custom x265 $adjusted_bitrate"
;;
*)
quality_params="-b:v $adjusted_bitrate"
quality_name="Custom $adjusted_bitrate"
;;
esac
else
quality_params="-crf 18"
quality_name="HEVC CRF 18"
fi
fi
}