#!/bin/bash
# Gate 24: run each published command on the test file and on edge inputs; log command, exit code, edge.
# Usage: bash cmds.sh   (run from the folder holding out/ and edge-7s-4k30.mp4)
LOG=commands.log; : > $LOG
# edge clip: 7 s of 4K30 H.264 at the same 23000k draft target as p3, made here so the edge input is reproducible
ffmpeg -v error -y -ss 60 -t 7 -i in/tos-part.webm -vf "scale=-2:2160,crop=3840:2160,fps=30,format=yuv420p" -c:v libx264 -preset veryfast -b:v 23000k -c:a aac -b:a 128k -movflags +faststart edge-7s-4k30.mp4
ffmpeg -v error -y -i out/p1-1080p30-h264.mp4 -map 0:v -c copy -f h264 edge-raw.h264
CMD='ffprobe -v error -show_entries format=duration,size -of csv=p=0 FILE | awk -F, '"'"'{printf "%.1f MB per minute, %.2f GB per hour\n", $2/$1*60/1e6, $2/$1*3600/1e9}'"'"
run() { # label file
  echo "published: ${CMD//FILE/clip.mp4}" >> $LOG
  c=${CMD//FILE/$2}; out=$(bash -c "set -o pipefail; $c" 2>&1); ec=$?
  echo "run on $2: $out" >> $LOG; echo "exit=$ec" >> $LOG; echo "edge: $1" >> $LOG; echo >> $LOG
}
run "test file, 60 s 1080p30" out/p1-1080p30-h264.mp4
run "test file, 60 s 4K60" out/p4-4k60-h264.mp4
run "7 s 4K30 clip, short duration" edge-7s-4k30.mp4
run "raw .h264 stream, no duration in the container" edge-raw.h264
run "file that does not exist" nofile.mp4
