forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

gen-subtitle-fixtures.sh65 lines, 2.6 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# gen-subtitle-fixtures.sh — extract real subtitle streams out of the library.
3#
4# READ-ONLY on the library; writes only under fixtures/ (gitignored). Picks the
5# first manifest file carrying each subtitle codec and copies that stream out
6# without re-encoding, so what the tests parse is exactly the bytes a disc rip
7# holds. The synthetic .srt/.vtt/.ass cases live inside the crates' own unit
8# tests; what cannot be written by hand is a real PGS display set.
9#
10# Usage: scripts/gen-subtitle-fixtures.sh
11# Env: EC_FIXTURES=<dir> (default <repo>/fixtures)
12# EC_PGS_SECONDS=<n> (default 900 — a whole film's worth is 30 MB)
13# In: fixtures/real-library-manifest.tsv (scripts/scan-real-library.sh)
14# Out: fixtures/subs/{pgs-1080p.sup,real.ass,real.srt}
15
16set -uo pipefail
17
18ROOT=$(cd -- "$(dirname -- "$0")/.." && pwd)
19FIXTURES=${EC_FIXTURES:-$ROOT/fixtures}
20MANIFEST=$FIXTURES/real-library-manifest.tsv
21OUT=$FIXTURES/subs
22SECONDS_LIMIT=${EC_PGS_SECONDS:-900}
23
24command -v ffmpeg >/dev/null || { echo "gen-subtitle-fixtures: ffmpeg not found" >&2; exit 2; }
25[ -r "$MANIFEST" ] || { echo "gen-subtitle-fixtures: run scripts/scan-real-library.sh first" >&2; exit 2; }
26
27mkdir -p -- "$OUT"
28
29# first_with <codec_name> — path of the first manifest file holding such a
30# subtitle stream, empty when the library has none.
31first_with() {
32 local codec=$1 path
33 while IFS=$'\t' read -r path _; do
34 [ -r "$path" ] || continue
35 if ffprobe -v error -select_streams s -show_entries stream=codec_name -of csv=p=0 -- "$path" 2>/dev/null |
36 grep -qx "$codec"; then
37 printf '%s\n' "$path"
38 return 0
39 fi
40 done < <(tail -n +2 -- "$MANIFEST")
41 return 1
42}
43
44# extract <codec_name> <output> [ffmpeg args...]
45extract() {
46 local codec=$1 out=$2; shift 2
47 local src
48 if ! src=$(first_with "$codec"); then
49 echo "gen-subtitle-fixtures: no $codec stream in the library — skipping $(basename "$out")" >&2
50 return 0
51 fi
52 # -map by codec so a dual-subtitle file gives the stream we asked for.
53 local index
54 index=$(ffprobe -v error -select_streams s -show_entries stream=index,codec_name -of csv=p=0 -- "$src" |
55 awk -F, -v c="$codec" '$2 == c {print $1; exit}')
56 if ffmpeg -v error -y "$@" -i "$src" -map "0:$index" -c copy -- "$out"; then
57 printf '%s\t%s\n' "$(basename "$out")" "$src"
58 else
59 echo "gen-subtitle-fixtures: ffmpeg failed on $src" >&2
60 fi
61}
62
63extract hdmv_pgs_subtitle "$OUT/pgs-1080p.sup" -t "$SECONDS_LIMIT"
64extract ass "$OUT/real.ass"
65extract subrip "$OUT/real.srt"