#!/bin/bash
# Run with:
#. ./run_pinkdotvideo_fixed.py 20171110T011354-kitt_01

# Creates pink-dot videos for log with original and fixed calibration.
# Concatenates both videos

mkdir -p -- "/tmp/$1"
mkdir -p -- "/tmp/$1/org"
mkdir -p -- "/tmp/$1/opt"
mkdir -p -- "/mnt/flashblade/till/$1"
rm  "/tmp/$1/org/*.mp4"
rm  "/tmp/$1/opt/*.mp4"
rm "/tmp/*.mp4"

brun //calibration/one_shot:visualize_lidar_main -- --logtostderr --meta_id $1 --vehicle_config_input_file "/mnt/flashblade/till/camera_cal_evaluation_V1/$1.json"
mv /tmp/*.mp4 "/tmp/$1/opt/"

brun //calibration/one_shot:visualize_lidar_main -- --logtostderr --meta_id $1
mv /tmp/*.mp4 "/tmp/$1/org/"

for filename in /tmp/$1/org/*.mp4; do
  thisf=$(basename "$filename")
  thisfa="/tmp/$1/org/${thisf}"
  thisfb="/tmp/$1/opt/${thisf}"
  ffmpeg -y -i "${thisfa}" -i "${thisfb}"  -filter_complex "[0:v]pad=iw*2:ih[int];[int][1:v]overlay=W/2:0[vid]" -map [vid] -c:v libx264 -crf 23 -preset veryfast "/mnt/flashblade/till/$1/${thisf}"
done

