#!/bin/bash
# Phone-video storage per minute: encode five 60 s profiles from a CC BY 3.0 clip, then measure bytes per minute.
# Usage: bash test-run.sh <workdir with in/tos-part.webm>   (ffmpeg 6.1.1, libx264/libx265, run on the VPS)
set -e
W=${1:-$HOME/rt/phone-video-storage-per-minute}; IN=$W/in/tos-part.webm; OUT=$W/out; mkdir -p $OUT
SS=60; T=60
enc() { # name width height fps codec kbps
  local n=$1 w=$2 h=$3 f=$4 c=$5 k=$6
  local vf="scale=-2:${h},crop=${w}:${h},fps=${f},format=yuv420p"
  local extra=""; [ "$c" = libx265 ] && extra="-tag:v hvc1 -x265-params log-level=error"
  ffmpeg -v error -y -ss $SS -t $T -i $IN -vf "$vf" -c:v $c -preset veryfast -b:v ${k}k $extra -c:a aac -b:a 128k -movflags +faststart $OUT/$n.mp4
}
enc p1-1080p30-h264 1920 1080 30 libx264 10000
enc p2-1080p60-h264 1920 1080 60 libx264 15000
enc p3-4k30-h264 3840 2160 30 libx264 23000
enc p4-4k60-h264 3840 2160 60 libx264 40000
enc p5-4k30-hevc 3840 2160 30 libx265 23000
# same CRF, two different 60 s stretches of the film (only the content differs)
for s in 60 150; do
  ffmpeg -v error -y -ss $s -t $T -i $IN -vf "scale=-2:1080,crop=1920:1080,fps=30,format=yuv420p" -c:v libx264 -preset veryfast -crf 23 -c:a aac -b:a 128k -movflags +faststart $OUT/crf23-at-${s}s.mp4
done
ls -l $OUT
