1 import { ensureDir, pathExists } from 'fs-extra'
2 import { dirname } from 'path'
3 import { buildAbsoluteFixturePath } from './tests'
4 import * as ffmpeg from 'fluent-ffmpeg'
6 async function generateHighBitrateVideo () {
7 const tempFixturePath = buildAbsoluteFixturePath('video_high_bitrate_1080p.mp4', true)
9 await ensureDir(dirname(tempFixturePath))
11 const exists = await pathExists(tempFixturePath)
13 console.log('Generating high bitrate video.')
15 // Generate a random, high bitrate video on the fly, so we don't have to include
16 // a large file in the repo. The video needs to have a certain minimum length so
17 // that FFmpeg properly applies bitrate limits.
18 // https://stackoverflow.com/a/15795112
19 return new Promise<string>((res, rej) => {
21 .outputOptions([ '-f rawvideo', '-video_size 1920x1080', '-i /dev/urandom' ])
22 .outputOptions([ '-ac 2', '-f s16le', '-i /dev/urandom', '-t 10' ])
23 .outputOptions([ '-maxrate 10M', '-bufsize 10M' ])
24 .output(tempFixturePath)
26 .on('end', () => res(tempFixturePath))
31 return tempFixturePath
34 async function generateVideoWithFramerate (fps = 60) {
35 const tempFixturePath = buildAbsoluteFixturePath(`video_${fps}fps.mp4`, true)
37 await ensureDir(dirname(tempFixturePath))
39 const exists = await pathExists(tempFixturePath)
41 console.log('Generating video with framerate %d.', fps)
43 return new Promise<string>((res, rej) => {
45 .outputOptions([ '-f rawvideo', '-video_size 1280x720', '-i /dev/urandom' ])
46 .outputOptions([ '-ac 2', '-f s16le', '-i /dev/urandom', '-t 10' ])
47 .outputOptions([ `-r ${fps}` ])
48 .output(tempFixturePath)
50 .on('end', () => res(tempFixturePath))
55 return tempFixturePath
59 generateHighBitrateVideo,
60 generateVideoWithFramerate