File size: 1,461 Bytes
a359f6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import fs from 'node:fs/promises';
import path from 'node:path';
import {bundle} from '@remotion/bundler';
import {selectComposition, renderMedia, renderStill} from '@remotion/renderer';

const hands = process.argv.slice(2).filter((a) => !a.startsWith('--'));
const want = hands.length ? hands : ['rock', 'scissors', 'paper'];
const coverFrame = 6;
const serveUrl = await bundle({entryPoint: path.resolve('src/index.tsx'), publicDir: path.resolve('public')});
for (const hand of want) {
  const out = path.resolve('out', hand);
  await fs.mkdir(out, {recursive: true});
  const composition = await selectComposition({serveUrl, id: `tod-${hand}`});
  const common = {composition, serveUrl};
  await renderMedia({...common, codec: 'h264', pixelFormat: 'yuv420p', crf: 17, audioCodec: 'aac', outputLocation: path.join(out, 'motion.mp4'), concurrency: 2});
  await renderStill({...common, frame: coverFrame, imageFormat: 'jpeg', jpegQuality: 96, output: path.join(out, 'cover.jpg')});
  for (const frame of [0, 16, 24, 34, 44, 50, 56, 70, 89]) await renderStill({...common, frame, imageFormat: 'jpeg', jpegQuality: 80, output: path.join(out, `frame-${frame}.jpg`)});
  await fs.writeFile(path.join(out, 'render.json'), JSON.stringify({hand, fps: composition.fps, durationInFrames: composition.durationInFrames, width: composition.width, height: composition.height, coverFrame, coverTime: coverFrame / composition.fps}, null, 2));
  console.log('rendered', hand);
}