#!/usr/bin/env bash
presets=("medium" "fast" "faster" "veryfast" "superfast" "ultrafast")
lowlatency=("true" "false")
width=640
height=512
num_frames=500

echo "Running tests:"

for preset in "${presets[@]}"
do
  for latency in "${lowlatency[@]}"
  do
    cmd="bazel run -c opt //experimental/max/video:x264_test -- --width $width --height $height --num_frames $num_frames --preset $preset --real_images /tmp/real_images --low_latency=$latency &> /dev/null"
    fps=$($cmd)
    echo "Preset: $preset Latency: $latency - $fps"
  done
done

echo "Making images"

videos="/tmp/*.h264"
for vid in $videos
do
  name=$(echo $vid | awk '{split($0,a,"."); print a[1]}')
  dir="$name"
  mkdir -p $dir
  ffmpeg -i $vid $dir/image_%03d.png
  ffmpeg -i $vid $dir/out.mp4
done

frames=("002" "013" "050" "100" "233")
for frame in "${frames[@]}"
do
  images=$(printf "/tmp/**/image_%s.png" $frame)
  out=$(printf "/tmp/test_%s.png" $frame)
  convert $images +append $out
done
