shots video: dry run, clips under half a second skipped instead of the remainder
This commit is contained in:
parent
37a32033c1
commit
97d82e99c5
1 changed files with 14 additions and 6 deletions
|
|
@ -1,5 +1,5 @@
|
|||
// App preview (App Store) and promo video (Play, via YouTube) from gameplay clips, with ffmpeg.
|
||||
// storebound shots video [--lang en,tr] [--target iphone,ipad,youtube] [--seconds 25] [--no-captions]
|
||||
// storebound shots video [--lang en,tr] [--target iphone,ipad,youtube] [--seconds 25] [--no-captions] [--dry]
|
||||
// Clips: <shots.video.clips>/<lang>/*.mp4|mov|webm (or <clips>/*.* shared by every language), joined in name order.
|
||||
// Record them with `storebound shots record` (simulator, emulator or web build) or bring your own.
|
||||
// Out: <renders>/<lang>/preview/<target>/01.mp4 + 01-poster.png. Every file is checked afterwards (`shots check` rules):
|
||||
|
|
@ -32,15 +32,16 @@ export function clipFiles(clipsDir: string, lang: string, list: (d: string) => s
|
|||
|
||||
export interface ClipPlan { file: string; dur: number; start: number }
|
||||
|
||||
/** Clips in order until `seconds` is filled (the last one is cut). Total below 15 s is an error (App Store minimum). */
|
||||
/** Clips in order until `seconds` is filled (the last one is cut; clips under half a second are skipped). Total below
|
||||
* 15 s is an error (App Store minimum). */
|
||||
export function planClips(clips: { file: string; dur: number }[], seconds: number): { plan: ClipPlan[]; total: number } {
|
||||
const want = Math.min(PREVIEW_RULES.maxSec, Math.max(PREVIEW_RULES.minSec, seconds));
|
||||
const plan: ClipPlan[] = [];
|
||||
let t = 0;
|
||||
for (const c of clips) {
|
||||
if (t >= want - 0.05) break;
|
||||
if (c.dur < 0.5) continue;
|
||||
const d = Math.min(c.dur, want - t);
|
||||
if (d < 0.5) continue;
|
||||
plan.push({ file: c.file, dur: +d.toFixed(3), start: +t.toFixed(3) });
|
||||
t += d;
|
||||
}
|
||||
|
|
@ -132,12 +133,13 @@ export async function run(ctx: Ctx): Promise<void> {
|
|||
const seconds = a.num('seconds', vc.seconds ?? 25);
|
||||
const clipsDir = resolve(vc.clips ?? 'store/video/clips');
|
||||
const outDir = resolve(config.renders ?? shots.out);
|
||||
const captions = vc.captions !== false && !a.has('no-captions');
|
||||
const dry = a.has('dry');
|
||||
const captions = vc.captions !== false && !a.has('no-captions') && !dry;
|
||||
const copy = JSON.parse(readFileSync(resolve(shots.copy), 'utf8')) as CopyFile;
|
||||
const sceneIds = vc.captionScenes ?? shots.scenes.map(s => s.id);
|
||||
const rtl = new Map(config.languages.map(l => [l.id, !!l.rtl] as const));
|
||||
const tmp = join(root, '.storebound', 'tmp', 'captions');
|
||||
mkdirSync(tmp, { recursive: true });
|
||||
if (!dry) mkdirSync(tmp, { recursive: true });
|
||||
|
||||
// caption PNGs come from a local page (fonts from `shots fonts`), like the screenshots
|
||||
let server: ReturnType<typeof Bun.serve> | null = null, browser: { close(): Promise<void>; newContext(o: unknown): Promise<{ newPage(): Promise<unknown> }> } | null = null;
|
||||
|
|
@ -174,6 +176,12 @@ export async function run(ctx: Ctx): Promise<void> {
|
|||
if (!files.length) { warn('shots', `${lang}: no clips in ${clipsDir}/${lang} or ${clipsDir} (storebound shots record)`); continue; }
|
||||
const { plan, total } = planClips(files.map(file => ({ file, dur: duration(file) })), seconds);
|
||||
const texts = captions ? captionsFor(copy[lang], sceneIds, plan.length) : [];
|
||||
if (dry) {
|
||||
for (const c of plan) log('shots', `${lang}: ${c.start.toFixed(1)}-${(c.start + c.dur).toFixed(1)} s ${c.file.slice(clipsDir.length + 1)}`);
|
||||
for (const key of targets) log('shots', `${lang}/${key}: would write ${join(renderDir(outDir, lang), 'preview', key, '01.mp4')} (${VIDEO_TARGETS[key]!.w}x${VIDEO_TARGETS[key]!.h}, ${total.toFixed(1)} s${vc.captions !== false && !a.has('no-captions') ? ', captions' : ''})`);
|
||||
made += targets.length;
|
||||
continue;
|
||||
}
|
||||
for (const key of targets) {
|
||||
const t = VIDEO_TARGETS[key]!;
|
||||
const dir = join(renderDir(outDir, lang), 'preview', key);
|
||||
|
|
@ -208,5 +216,5 @@ export async function run(ctx: Ctx): Promise<void> {
|
|||
rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
if (bad) throw new Error(`${bad} videos fail the store checks`);
|
||||
done('shots', `video done: ${made} files`);
|
||||
done('shots', dry ? `video planned (dry run): ${made} files` : `video done: ${made} files`);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue