#!/bin/bash
# SSIM of each file against the original src.mp4 (ffmpeg 6.1.1 ssim filter, "All" value). Needs test-run.sh outputs rebuilt here; the tool file comes from tool.cjs.
# Varied: the file compared. Held equal: reference (src.mp4, 1920x1080, 60 fps, 180 frames), the ssim filter, preset medium for the CRF files. Size only is not quality; this adds one picture-fidelity figure.
cd "$(dirname "$0")"
W=$(mktemp -d); trap "rm -rf $W" EXIT
ss(){ ffmpeg -v info -i "$1" -i src.mp4 -lavfi "[0:v]setpts=PTS-STARTPTS[a];[1:v]setpts=PTS-STARTPTS[b];[a][b]ssim" -f null - 2>&1 | grep -o "All:[0-9.]*" | tail -1; }
echo "SSIM lean-hevc.mp4 (the input) $(ss lean-hevc.mp4)"
for c in 18 23 28 34; do ffmpeg -v error -y -i lean-hevc.mp4 -c:v libx264 -preset medium -crf $c -an $W/c$c.mp4; echo "SSIM x264 crf=$c medium bytes=$(stat -c %s $W/c$c.mp4) $(ss $W/c$c.mp4)"; done
T=${1:-$HOME/rt/compression-made-file-bigger/out/lean-hevc-127001-1080p.mp4}
[ -f "$T" ] && echo "SSIM Koldflux tool 1080p bytes=$(stat -c %s $T) $(ss $T)"
echo "SSIM-DONE"
