Files
gwutilz/gwencoder/scripts/phase5_test.sh
2026-03-23 15:48:34 -07:00

214 lines
8.4 KiB
Bash
Executable File

#!/bin/bash
# Phase 5 Comprehensive Testing Script
# Tests various flag combinations and logs results
TEST_FILE="testvid.webm"
OUTPUT_DIR="phase5_test_outputs"
LOG_FILE="phase5_test_results.log"
RESULTS_TABLE="PHASE5_TEST_RESULTS.md"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Create output directory
mkdir -p "$OUTPUT_DIR"
# Check if test file exists
if [ ! -f "$TEST_FILE" ]; then
echo -e "${RED}❌ Test file not found: $TEST_FILE${NC}"
exit 1
fi
# Get original file size
ORIGINAL_SIZE=$(du -b "$TEST_FILE" 2>/dev/null | cut -f1)
ORIGINAL_SIZE_MB=$(echo "scale=2; $ORIGINAL_SIZE / 1024 / 1024" | bc)
echo -e "${BLUE}══════════════════════════════════════════════════════════════${NC}"
echo -e "${BLUE}GWENCODER PHASE 5 COMPREHENSIVE TESTING${NC}"
echo -e "${BLUE}══════════════════════════════════════════════════════════════${NC}"
echo ""
echo -e "Test file: ${GREEN}$TEST_FILE${NC} (${ORIGINAL_SIZE_MB} MB)"
echo -e "Output directory: ${GREEN}$OUTPUT_DIR${NC}"
echo -e "Log file: ${GREEN}$LOG_FILE${NC}"
echo -e "Results table: ${GREEN}$RESULTS_TABLE${NC}"
echo ""
# Function to get file size in MB
get_file_size_mb() {
local file=$1
if [ -f "$file" ]; then
local size=$(du -b "$file" 2>/dev/null | cut -f1)
echo "scale=2; $size / 1024 / 1024" | bc
else
echo "0"
fi
}
# Function to calculate compression ratio
get_compression_ratio() {
local original=$1
local output=$2
local orig_mb=$(echo "scale=2; $original / 1024 / 1024" | bc)
local out_mb=$(get_file_size_mb "$output")
if [ "$out_mb" != "0" ] && [ "$orig_mb" != "0" ]; then
echo "scale=1; ($orig_mb - $out_mb) / $orig_mb * 100" | bc
else
echo "0"
fi
}
# Function to calculate encoding speed (fps if available, or just time)
get_encoding_speed() {
local log_file=$1
# Try to extract fps from FFmpeg output
local fps=$(grep -oP 'fps=\K[0-9.]+' "$log_file" 2>/dev/null | tail -1)
if [ -n "$fps" ]; then
echo "${fps} fps"
else
echo "N/A"
fi
}
# Function to run test and log results
run_test() {
local test_num=$1
local test_name=$2
local mode=$3
local flags=$4
local description=$5
echo ""
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE}TEST $test_num: $test_name${NC}"
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "Mode: ${GREEN}$mode${NC}"
echo -e "Flags: ${GREEN}$flags${NC}"
echo -e "Description: $description"
echo ""
# Clean up old output files
find . -maxdepth 1 -name "*GWELL.*" -type f -delete 2>/dev/null
start_time=$(date +%s.%N)
# Build command
cmd="./gwencoder $mode $flags"
echo -e "${BLUE}Running: ${NC}$cmd"
echo ""
# Run encoding and capture output
output_log="$OUTPUT_DIR/test${test_num}_${test_name}.log"
$cmd 2>&1 | tee "$output_log"
end_time=$(date +%s.%N)
duration=$(echo "$end_time - $start_time" | bc)
duration_rounded=$(printf "%.1f" "$duration")
# Find output file
output_file=$(find . -maxdepth 1 -name "*GWELL.*" -type f -newer "$TEST_FILE" 2>/dev/null | head -1)
if [ -n "$output_file" ]; then
file_size_mb=$(get_file_size_mb "$output_file")
compression=$(get_compression_ratio "$ORIGINAL_SIZE" "$output_file")
speed=$(get_encoding_speed "$output_log")
# Move output file to test directory
mv "$output_file" "$OUTPUT_DIR/" 2>/dev/null
output_file="$OUTPUT_DIR/$(basename "$output_file")"
echo ""
echo -e "${GREEN}✅ Test completed${NC}"
echo -e " Duration: ${GREEN}${duration_rounded}s${NC}"
echo -e " File size: ${GREEN}${file_size_mb} MB${NC}"
echo -e " Compression: ${GREEN}${compression}%${NC}"
echo -e " Speed: ${GREEN}$speed${NC}"
echo -e " Output: ${GREEN}$output_file${NC}"
# Log to CSV
echo "$test_num|$test_name|$mode|$flags|$duration_rounded|$file_size_mb|$compression|$speed|✅|$output_file" >> "$LOG_FILE"
else
echo ""
echo -e "${RED}❌ Test failed - no output file found${NC}"
echo "$test_num|$test_name|$mode|$flags|N/A|N/A|N/A|N/A|❌|N/A" >> "$LOG_FILE"
fi
}
# Initialize log file
echo "Test#|Test Name|Mode|Flags|Duration (s)|Size (MB)|Compression %|Speed|Status|Output File" > "$LOG_FILE"
# Test 1: Default settings (Fast mode)
run_test "1" "Default Fast" "--fast" "" "Default settings: AV1 preset 10, CRF 28, stream reordering enabled"
# Test 2: Fast with AV1 advanced options
run_test "2" "Fast AV1 Advanced" "--fast" "--av1-preset 8 --av1-crf 30" "Fast mode with custom preset and CRF"
# Test 3: Fast with audio options
run_test "3" "Fast Audio Options" "--fast" "--audio-quality balanced --audio-stereo" "Fast mode with balanced audio quality and stereo downmix"
# Test 4: Web mode (different container)
run_test "4" "Web Mode" "--web" "" "Web mode: WEBM container, CRF 35, optimized for streaming"
# Test 5: Web with maxrate cap
run_test "5" "Web Maxrate" "--web" "--av1-maxrate 5000" "Web mode with 5Mbps maxrate cap"
# Test 6: Tiny mode (maximum compression)
run_test "6" "Tiny Mode" "--tiny" "" "Tiny mode: MP4 container, CRF 42, maximum compression"
# Test 7: HQ mode (high quality)
run_test "7" "HQ Mode" "--hq" "" "HQ mode: MKV container, CRF 22, high quality preset"
# Test 8: Fast with subtitle extraction
run_test "8" "Fast Extract Subs" "--fast" "--extract-subs" "Fast mode with subtitle extraction"
# Test 9: Fast with force transcode
run_test "9" "Fast Force Transcode" "--fast" "--force-transcode" "Fast mode with force transcode enabled"
# Test 10: Fast with all audio options
run_test "10" "Fast Full Audio" "--fast" "--audio-quality high --audio-create-downmix" "Fast mode with high quality audio and downmix creation"
# Generate results table
echo "# Phase 5 Test Results" > "$RESULTS_TABLE"
echo "" >> "$RESULTS_TABLE"
echo "## Test Overview" >> "$RESULTS_TABLE"
echo "" >> "$RESULTS_TABLE"
echo "**Test File**: \`$TEST_FILE\` (${ORIGINAL_SIZE_MB} MB)" >> "$RESULTS_TABLE"
echo "**Test Date**: $(date)" >> "$RESULTS_TABLE"
echo "" >> "$RESULTS_TABLE"
echo "## Results Table" >> "$RESULTS_TABLE"
echo "" >> "$RESULTS_TABLE"
echo "| Test# | Test Name | Mode | Flags | Duration (s) | Size (MB) | Compression % | Speed | Status |" >> "$RESULTS_TABLE"
echo "|-------|-----------|------|-------|--------------|-----------|---------------|-------|--------|" >> "$RESULTS_TABLE"
# Add results to table (skip header)
tail -n +2 "$LOG_FILE" | while IFS='|' read -r num name mode flags duration size compression speed status output; do
echo "| $num | $name | $mode | \`$flags\` | $duration | $size | $compression | $speed | $status |" >> "$RESULTS_TABLE"
done
echo "" >> "$RESULTS_TABLE"
echo "## Summary" >> "$RESULTS_TABLE"
echo "" >> "$RESULTS_TABLE"
echo "Total tests: $(tail -n +2 "$LOG_FILE" | wc -l)" >> "$RESULTS_TABLE"
echo "Successful: $(grep -c "✅" "$LOG_FILE")" >> "$RESULTS_TABLE"
echo "Failed: $(grep -c "❌" "$LOG_FILE")" >> "$RESULTS_TABLE"
# Print summary
echo ""
echo -e "${BLUE}══════════════════════════════════════════════════════════════${NC}"
echo -e "${BLUE}TEST SUMMARY${NC}"
echo -e "${BLUE}══════════════════════════════════════════════════════════════${NC}"
echo ""
echo -e "Total tests: ${GREEN}$(tail -n +2 "$LOG_FILE" | wc -l)${NC}"
echo -e "Successful: ${GREEN}$(grep -c "✅" "$LOG_FILE")${NC}"
echo -e "Failed: ${RED}$(grep -c "❌" "$LOG_FILE")${NC}"
echo ""
echo -e "Full results logged to: ${GREEN}$LOG_FILE${NC}"
echo -e "Results table: ${GREEN}$RESULTS_TABLE${NC}"
echo -e "Individual test outputs in: ${GREEN}$OUTPUT_DIR/${NC}"
echo ""