Files
gwutilz/test_encoding.sh
2026-03-23 15:48:34 -07:00

240 lines
9.5 KiB
Bash
Executable File

#!/bin/bash
# GWEncoder v3.0 Comprehensive Testing Script
# Tests all encoding modes with all codec variants (AV1, H.264, NVENC HEVC)
set -e
echo "🧪 GWEncoder v3.0 - Comprehensive Encoding Test"
echo "================================================"
echo ""
# Check if testvid.webm exists
if [ ! -f "testvid.webm" ]; then
echo "❌ testvid.webm not found in current directory"
exit 1
fi
# Get source file info
echo "📊 SOURCE FILE INFORMATION"
echo "=========================="
SOURCE_SIZE=$(stat -c%s "testvid.webm")
SOURCE_SIZE_MB=$(echo "scale=2; $SOURCE_SIZE / 1024 / 1024" | bc)
SOURCE_DURATION=$(ffprobe -v quiet -select_streams v:0 -show_entries format=duration -of csv=p=0 testvid.webm)
SOURCE_RESOLUTION=$(ffprobe -v quiet -select_streams v:0 -show_entries stream=width,height -of csv=p=0 testvid.webm)
echo "File: testvid.webm"
GENL_SIZE_MB=$(echo "scale=2; $SOURCE_SIZE / 1024 / 1024" | bc)
echo "Size: $SOURCE_SIZE_MB MB"
echo "Duration: $SOURCE_DURATION seconds"
echo "Resolution: $SOURCE_RESOLUTION"
echo ""
# Create results file
RESULTS_FILE="encoding_test_results.txt"
echo "GWEncoder v3.0 - Encoding Test Results" > $RESULTS_FILE
echo "Generated: $(date)" >> $RESULTS_FILE
echo "Source: testvid.webm ($SOURCE_SIZE_MB MB, $SOURCE_DURATION s, $SOURCE_RESOLUTION)" >> $RESULTS_FILE
echo "" >> $RESULTS_FILE
echo "Mode,Codec,CRF,Preset,Container,Audio Bitrate,Encoding Time,Output Size (MB),Size Reduction (%),Compression Ratio" >> $RESULTS_FILE
# Function to run encoding test
run_test() {
local mode=$1
local mode_name=$2
local codec_flag=$3
local codec_name=$4
echo "🚀 Testing $mode_name mode ($codec_name)..."
echo "Mode: $mode_name ($codec_name)" >> $RESULTS_FILE
# Clean up any previous outputs
rm -f *-*-*-GWELL.*
# Record start time
start_time=$(date +%s)
# Run encoding with codec flag
if ./gwencoder --$mode $codec_flag; then
# Record end time
end_time=$(date +%s)
encoding_time=$((end_time - start_time))
# Find the output file (look for any GWELL file)
output_file=$(ls *-*-*-GWELL.* 2>/dev/null | head -1)
if [ -f "$output_file" ]; then
output_size=$(stat -c%s "$output_file")
output_size_mb=$(echo "scale=2; $output_size / 1024 / 1024" | bc)
size_reduction=$(echo "scale=2; (($SOURCE_SIZE - $output_size) * 100) / $SOURCE_SIZE" | bc)
compression_ratio=$(echo "scale=2; $SOURCE_SIZE / $output_size" | bc)
echo "$mode_name ($codec_name) completed in ${encoding_time}s"
echo " Output: $output_file"
echo " Size: $output_size_mb MB"
echo " Reduction: ${size_reduction}%"
echo " Compression: ${compression_ratio}:1"
echo ""
# Extract settings based on mode and codec
case $mode in
"fast")
case $codec_flag in
"")
echo "fast,AV1,28,10,mkv,64,$encoding_time,$output_size_mb,$size_reduction,$compression_ratio" >> $RESULTS_FILE
;;
"--x264")
echo "fast,H264,28,10,mkv,64,$encoding_time,$output_size_mb,$size_reduction,$compression_ratio" >> $RESULTS_FILE
;;
"--nvhevc")
echo "fast,NVHEVC,26,fast,mkv,64,$encoding_time,$output_size_mb,$size_reduction,$compression_ratio" >> $RESULTS_FILE
;;
esac
;;
"web")
case $codec_flag in
"")
echo "web,AV1,35,10,webm,64,$encoding_time,$output_size_mb,$size_reduction,$compression_ratio" >> $RESULTS_FILE
;;
"--x264")
echo "web,H264,35,10,mkv,64,$encoding_time,$output_size_mb,$size_reduction,$compression_ratio" >> $RESULTS_FILE
;;
"--nvhevc")
echo "web,NVHEVC,28,medium,mp4,64,$encoding_time,$output_size_mb,$size_reduction,$compression_ratio" >> $RESULTS_FILE
;;
esac
;;
"tiny")
case $codec_flag in
"")
echo "tiny,AV1,42,8,mp4,48,$encoding_time,$output_size_mb,$size_reduction,$compression_ratio" >> $RESULTS_FILE
;;
"--x264")
echo "tiny,H264,42,fast,mp4,48,$encoding_time,$output_size_mb,$size_reduction,$compression_ratio" >> $RESULTS_FILE
;;
"--nvhevc")
echo "tiny,NVHEVC,30,fast,mp4,48,$encoding_time,$output_size_mb,$size_reduction,$compression_ratio" >> $RESULTS_FILE
;;
esac
;;
"hq")
case $codec_flag in
"")
echo "hq,AV1,22,6,mkv,96,$encoding_time,$output_size_mb,$size_reduction,$compression_ratio" >> $RESULTS_FILE
;;
"--x264")
echo "hq,H264,22,medium,mkv,96,$encoding_time,$output_size_mb,$size_reduction,$compression_ratio" >> $RESULTS_FILE
;;
"--nvhevc")
echo "hq,NVHEVC,22,medium,mkv,96,$encoding_time,$output_size_mb,$size_reduction,$compression_ratio" >> $RESULTS_FILE
;;
esac
;;
"slow")
case $codec_flag in
"")
echo "slow,AV1,18,4,mkv,128,$encoding_time,$output_size_mb,$size_reduction,$compression_ratio" >> $RESULTS_FILE
;;
"--x264")
echo "slow,H264,18,slow,mkv,128,$encoding_time,$output_size_mb,$size_reduction,$compression_ratio" >> $RESULTS_FILE
;;
"--nvhevc")
echo "slow,NVHEVC,18,slow,mkv,128,$encoding_time,$output_size_mb,$size_reduction,$compression_ratio" >> $RESULTS_FILE
;;
esac
;;
esac
else
echo "❌ No output file found for $mode_name ($codec_name)"
echo "ERROR: No output file generated" >> $RESULTS_FILE
fi
else
echo "$mode_name ($codec_name) encoding failed"
echo "ERROR: Encoding failed" >> $RESULTS_FILE
fi
echo "" >> $RESULTS_FILE
echo "---" >> $RESULTS_FILE
echo ""
}
# Check if gwencoder exists
if [ ! -f "./gwencoder" ]; then
echo "🔨 Building gwencoder..."
if [ -f "./build.sh" ]; then
./build.sh
else
echo "❌ Build script not found. Please build manually."
exit 1
fi
fi
echo "📋 TESTING ALL ENCODING MODES WITH ALL CODECS"
echo "============================================="
echo ""
# Test all modes with all codec variants
echo "🎬 Testing Fast mode..."
run_test "fast" "Fast" "" "AV1"
run_test "fast" "Fast" "--x264" "H.264"
run_test "fast" "Fast" "--nvhevc" "NVENC HEVC"
echo "🌐 Testing Web mode..."
run_test "web" "Web" "" "AV1"
run_test "web" "Web" "--x264" "H.264"
run_test "web" "Web" "--nvhevc" "NVENC HEVC"
echo "📦 Testing Tiny mode..."
run_test "tiny" "Tiny" "" "AV1"
run_test "tiny" "Tiny" "--x264" "H.264"
run_test "tiny" "Tiny" "--nvhevc" "NVENC HEVC"
echo "🎯 Testing HQ mode..."
run_test "hq" "HQ" "" "AV1"
run_test "hq" "HQ" "--x264" "H.264"
run_test "hq" "HQ" "--nvhevc" "NVENC HEVC"
echo "🐌 Testing Slow mode..."
run_test "slow" "Slow" "" "AV1"
run_test "slow" "Slow" "--x264" "H.264"
run_test "slow" "Slow" "--nvhevc" "NVENC HEVC"
echo "📊 FINAL RESULTS SUMMARY"
echo "========================"
echo ""
# Display results table
echo "Mode | Codec | CRF | Preset | Container | Audio | Time(s) | Size(MB) | Reduction | Compression"
echo "----------------|----------|-----|--------|-----------|-------|---------|----------|-----------|------------"
# Parse results and display
tail -n +6 $RESULTS_FILE | grep -v "^$" | grep -v "^---$" | grep -v "^ERROR" | while IFS=',' read -r mode codec crf preset container audio time size reduction compression; do
printf "%-15s | %-8s | %-3s | %-6s | %-9s | %-5s | %-7s | %-8s | %-9s | %-11s\n" "$mode" "$codec" "$crf" "$preset" "$container" "$audio" "$time" "$size" "$reduction%" "${compression}:1"
done
echo ""
echo "📁 Results saved to: $RESULTS_FILE"
echo ""
# Show file sizes
echo "📁 OUTPUT FILES:"
echo "================"
ls -lh *-*-*-GWELL.* 2>/dev/null | awk '{print $5, $9}' | while read size file; do
echo "$size - $file"
done
echo ""
echo "🎯 NEW ENCODING MODES:"
echo "======================"
echo ""
echo "Updated encoding modes with new defaults:"
echo "• --fast → Daily driver, quick turnaround (CRF 28, MKV, Opus 64kbps)"
echo "• --web → Streaming, Discord, web upload (CRF 35, WEBM, Opus 64kbps)"
echo "• --tiny → Maximum compression (CRF 42, MP4, Opus 48kbps)"
echo "• --hq → High quality archival (CRF 22, MKV, Opus 96kbps)"
echo "• --slow → Best possible quality (CRF 18, MKV, Opus 128kbps)"
echo ""
echo "All modes support AV1 (default), H.264/x264, and NVIDIA NVENC HEVC codecs!"
echo ""
echo "✅ Testing complete!"