36 lines
1.8 KiB
Python
36 lines
1.8 KiB
Python
"""Check rendered media, matching captions, and frozen benchmark provenance."""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import av
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--quality', default='final', choices=['preview', 'final'])
|
|
parser.add_argument('--scene', default='SlimeFilm')
|
|
args = parser.parse_args()
|
|
name = f'{args.scene}-{args.quality}'
|
|
report = json.loads((HERE / f'output/{name}.render.json').read_text())
|
|
timeline = json.loads((HERE / f'output/{name}.timeline.json').read_text())
|
|
for source, digest in report['source_sha256'].items():
|
|
assert hashlib.sha256((HERE/source).read_bytes()).hexdigest() == digest, f'changed after render: {source}'
|
|
data = json.loads((HERE/'data/benchmarks.json').read_text())
|
|
for record in (data,):
|
|
path = HERE/record['source']
|
|
assert hashlib.sha256(path.read_bytes()).hexdigest() == record['source_sha256'], f'benchmark source changed: {path}'
|
|
for cue in timeline['cues']:
|
|
assert 0 <= cue['start'] < cue['end'] <= timeline['duration']+.1
|
|
for a,b in zip(timeline['cues'],timeline['cues'][1:]):
|
|
assert a['end'] <= b['start']+.01, 'overlapping captions'
|
|
assert len(timeline['cues']) == report['caption_count']
|
|
with av.open(str(HERE/'output'/report['file'])) as container:
|
|
stream = container.streams.video[0]
|
|
expected = (854,480) if args.quality == 'preview' else (1920,1080)
|
|
assert (stream.width,stream.height) == expected
|
|
duration = float(stream.duration*stream.time_base)
|
|
assert abs(duration-timeline['duration']) < .15, 'video and caption timelines differ'
|
|
frames = sum(1 for _ in container.decode(stream))
|
|
assert frames > 0
|
|
print(f'OK: {report["file"]}; {frames} decoded frames; {len(timeline["cues"])} captions; source hashes match')
|