forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB0b7aabeTahinli2 months ago3732 commits

pgs-white-level.sh38 lines, 1.4 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# What a player draws a PGS subtitle's white as, measured rather than reasoned:
3# ffmpeg burns fixtures/subs/pgs-1080p.sup over black and the brightest red
4# channel in the first painted frame is printed. It is 235 -- the palette's own
5# Y', not an expansion of the 16..235 video range to 255 -- which is what
6# `ec_pgs::rgba` matches.
7#
8# scripts/pgs-white-level.sh [file.sup]
9set -euo pipefail
10
11sup="${1:-$(dirname "$0")/../fixtures/subs/pgs-1080p.sup}"
12[ -r "$sup" ] || { echo "no such .sup: $sup (fixtures are gitignored)" >&2; exit 1; }
13
14size=$(ffprobe -v error -select_streams s:0 -show_entries stream=width,height \
15 -of csv=p=0:s=x "$sup")
16raw=$(mktemp -t pgs-white.XXXXXX)
17trap 'rm -f "$raw"' EXIT
18
19ffmpeg -v error -f lavfi -i "color=c=black:s=$size:r=1:d=60,format=rgba" -i "$sup" \
20 -filter_complex "[0:v][1:s]overlay=format=rgb" -frames:v 60 \
21 -pix_fmt rgba -f rawvideo -y "$raw"
22
23python3 - "$raw" "$size" <<'PY'
24import sys
25data = open(sys.argv[1], 'rb').read()
26w, h = (int(v) for v in sys.argv[2].split('x'))
27frame = w * h * 4
28for i in range(len(data) // frame):
29 reds = data[i * frame:(i + 1) * frame:4]
30 peak = max(reds)
31 if peak:
32 print(f"frame {i}: brightest red {peak}, "
33 f"{sum(1 for v in reds if v)} pixels drawn on")
34 break
35else:
36 print("nothing painted in any frame", file=sys.stderr)
37 sys.exit(1)
38PY