forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

streamsink-r1-run_film_fifo.sh52 lines, 2.7 KiBHistoryRawDownload
1#!/bin/bash
2# lane-streamsink r1: same census as run_film.sh, but our decoder streams its
3# frames into a FIFO (ec_av1::stream::decode_stream_with, one frame written the
4# moment it completes) and cmp2.py reads one frame from that FIFO and one from
5# ffmpeg's stdout at a time. Neither side ever holds more than a frame, so the
6# segment length no longer bounds memory -- peak RSS of the decoder is ~0.44 GB
7# on a 4K 10-bit window regardless of how long the window is.
8# usage: run_film_fifo.sh <name> <film> <width> <height> <seg_seconds> [probe]
9set -u
10S="$(cd "$(dirname "$0")" && pwd)"
11NAME="$1"; FILM="$2"; W="$3"; H="$4"; SEG="$5"
12PROBE="${6:-$HOME/.cache/cargo-target-streamsink/release/examples/decode_probe}"
13T=$HOME/.cache/fullfilm-fifo/$NAME
14rm -rf "$T"; mkdir -p "$T"
15STATE=$T/state.json
16DUR=$(ffprobe -v error -show_entries format=duration -of default=nw=1:nk=1 "$FILM" | cut -d. -f1)
17echo "START name=$NAME res=${W}x${H} depth=10 codec=av1 duration_s=$DUR seg_s=$SEG mode=fifo"
18T0=$(date +%s)
19s=0
20while [ "$s" -lt "$DUR" ]; do
21 seg=$T/seg.obu; fifo=$T/ours.fifo
22 rm -f "$seg" "$fifo"
23 ffmpeg -nostdin -loglevel error -ss "$s" -t "$SEG" -i "$FILM" -map 0:v:0 -c:v copy -an -f obu "$seg" -y 2>/dev/null
24 if [ ! -s "$seg" ]; then echo "t=${s}s NO-SEGMENT"; s=$((s+SEG)); continue; fi
25 mkfifo "$fifo"
26 base=$(python3 -c 'import json,sys,os
27p=sys.argv[1]
28print(json.load(open(p))["compared"] if os.path.exists(p) else 0)' "$STATE")
29 EC_PROBE_OUT16="$fifo" timeout 7200 "$PROBE" "$seg" > "$T/probe.log" 2>&1 &
30 probe=$!
31 line=$(ffmpeg -nostdin -loglevel error -i "$seg" -pix_fmt yuv420p10le -f rawvideo - 2>/dev/null \
32 | python3 "$S/cmp2.py" "$fifo" "$W" "$H" "$STATE" "$base")
33 wait $probe; rc=$?
34 r=$(grep -E '^REFUSED|^OK|panick|rror' "$T/probe.log" | head -1)
35 [ $rc -ge 128 ] && r="KILLED(rc=$rc)"
36 [ -z "$r" ] && r="NO-MATCH-LINE(rc=$rc)"
37 now=$(date +%s); el=$((now-T0)); [ "$el" -lt 1 ] && el=1
38 tot=$(python3 -c 'import json,sys,os
39p=sys.argv[1]
40print(json.load(open(p))["compared"] if os.path.exists(p) else 0)' "$STATE")
41 fpm=$(python3 -c "print(round($tot*60.0/$el,2))")
42 printf 't=%ss\t%s\t%b\telapsed_s=%s\tfpm=%s\n' "$s" "$r" "$line" "$el" "$fpm"
43 rm -f "$seg" "$fifo"
44 s=$((s+SEG))
45done
46now=$(date +%s); el=$((now-T0)); [ "$el" -lt 1 ] && el=1
47python3 -c '
48import json,sys
49st=json.load(open(sys.argv[1])); el=int(sys.argv[2]); name=sys.argv[3]
50print("FULLFILM name=%s compared=%d differing=%d first_bad=%s first_bad_bytes=%d max_bytes=%d segments=%d elapsed_s=%d fpm=%.2f"
51 % (name, st["compared"], st["differing"], st["first_bad"] if st["first_bad"] is not None else "-",
52 st["first_bad_bytes"], st["max_bytes"], st["segments"], el, st["compared"]*60.0/el))' "$STATE" "$el" "$NAME"