#!/usr/bin/env bash

F="${1:?need arg1 to be set to input .mkv}"
OUT="${1%.mkv}.webm"
LOGBASE="${OUT}.passlog"

# Pass 1: video only, stats only
ffmpeg -y \
  -i "$F" \
  -map 0:v:0 \
  -c:v libsvtav1 -preset 5 -crf 30 -g 240 -pix_fmt yuv420p \
  -an -pass 1 -passlogfile "$LOGBASE" -f webm /dev/null

# Pass 2: video + copy Opus audio
ffmpeg \
  -i "$F" \
  -map 0:v:0 -map 0:a:0 \
  -c:v libsvtav1 -preset 5 -crf 30 -g 240 -pix_fmt yuv420p \
  -c:a copy \
  -pass 2 -passlogfile "$LOGBASE" \
  "$OUT"
