#!/bin/bash
# Generate the two AV1 segments consumed by poc.html.
#
# REQUIREMENT: both segments MUST have identical coded picture size so that
# `pic_size_ == decoder_->GetPicSize()` in
# V4L2StatelessVideoDecoderBackend::PumpDecodeTask() is true on the 10-bit
# kConfigChange.  AV1 seq_profile=0 (Main) covers both 8- and 10-bit, so the
# VideoCodecProfile reported to the backend is unchanged across the switch.
#
# Run this on any workstation with ffmpeg + libaom; copy the resulting *.webm
# next to poc.html before serving on the target ChromeOS device.
set -e

W=640
H=360
FRAMES=8

# 8-bit AV1 Main, yuv420p
ffmpeg -y -f lavfi -i "testsrc2=size=${W}x${H}:rate=30" -frames:v ${FRAMES} \
  -pix_fmt yuv420p -c:v libaom-av1 -crf 40 -cpu-used 8 -g 1 \
  -color_primaries bt709 -color_trc bt709 -colorspace bt709 \
  seg-8bit.webm

# 10-bit AV1 Main, yuv420p10le, SAME WxH
ffmpeg -y -f lavfi -i "testsrc2=size=${W}x${H}:rate=30" -frames:v ${FRAMES} \
  -pix_fmt yuv420p10le -c:v libaom-av1 -crf 40 -cpu-used 8 -g 1 \
  -color_primaries bt709 -color_trc bt709 -colorspace bt709 \
  seg-10bit.webm

# Optional: a single concatenated stream as a non-MSE fallback.  Re-encoding
# the concat is wrong (would normalise bit depth), so concat at the container
# level with -c copy.
printf "file 'seg-8bit.webm'\nfile 'seg-10bit.webm'\n" > _concat.txt
ffmpeg -y -f concat -safe 0 -i _concat.txt -c copy seg-concat.webm || true
rm -f _concat.txt

echo
echo "Generated:"
ls -l seg-8bit.webm seg-10bit.webm seg-concat.webm 2>/dev/null
echo
echo "Verify both report ${W}x${H}:"
ffprobe -v error -select_streams v:0 \
  -show_entries stream=width,height,pix_fmt,profile -of compact \
  seg-8bit.webm seg-10bit.webm
