Files

26 lines
2.2 KiB
Python
Executable File

#!/usr/bin/env python3
"""Create 24-second previews solely from actual simulator screen-recording footage."""
from pathlib import Path
import json,subprocess,os
ROOT=Path(__file__).resolve().parents[1]
SCRATCH=Path(os.environ.get('TARNAX_SCRATCH_ROOT',str(Path.home()/'Developer/Scratch/Tarnax')))
SCENES=['01-home','02-library','03-details','04-files','05-settings','06-add']
metadata=[]
for device,size in [('iphone-6.9',(886,1920)),('ipad-13',(1200,1600))]:
w,h=size
work=SCRATCH/'appstore-video'/device
encoded=[]
for scene in SCENES:
src=work/(scene+'.mov');out=work/(scene+'-encoded.mp4')
vf=f'tpad=stop_mode=clone:stop_duration=4,scale={w}:{h}:force_original_aspect_ratio=decrease:force_divisible_by=2,pad={w}:{h}:(ow-iw)/2:(oh-ih)/2:color=black,fps=30,setsar=1,format=yuv420p'
cmd=['ffmpeg','-y','-v','error','-ss','0','-i',str(src),'-f','lavfi','-i','anullsrc=r=48000:cl=stereo','-t','4','-vf',vf,'-c:v','libx264','-preset','fast','-profile:v','high','-level:v','4.0','-b:v','10M','-maxrate','12M','-bufsize','20M','-pix_fmt','yuv420p','-color_primaries','bt709','-color_trc','bt709','-colorspace','bt709','-c:a','aac','-b:a','256k','-ar','48000','-ac','2','-movflags','+faststart',str(out)]
subprocess.run(cmd,check=True);encoded.append(out)
playlist=work/'concat.txt';playlist.write_text(''.join("file '"+str(p).replace("'","'\\''")+"'\n" for p in encoded))
dst=ROOT/f'previews/Tarnax-{device}-preview.mp4'
subprocess.run(['ffmpeg','-y','-v','error','-f','concat','-safe','0','-i',str(playlist),'-c','copy','-movflags','+faststart',str(dst)],check=True)
poster=ROOT/f'previews/Tarnax-{device}-poster.png'
subprocess.run(['ffmpeg','-y','-v','error','-ss','1','-i',str(dst),'-frames:v','1',str(poster)],check=True)
metadata.append({'file':str(dst.relative_to(ROOT)),'width':w,'height':h,'duration_seconds':24,'fps':30,'codec':'H.264 High Level 4.0','audio':'AAC stereo 48kHz, silent','poster_frame_seconds':1,'footage':'Actual app UI captured in a simulator with fictitious sample data; no marketing artwork inserted.'})
(ROOT/'previews/preview-info.json').write_text(json.dumps(metadata,indent=2)+'\n')
print('Created iPhone and iPad 24-second App Preview files.')