diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-13 09:43:59 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:18 +0200 |
commit | 6c5065a011b099618681a37bd77eaa7bd3db752e (patch) | |
tree | 352252a00b25013c4b1902f6bcd9668aba295c7b /shared/extra-utils/miscs/generate.ts | |
parent | 0d8ecb7592577f54012413a2b5a9b159cfc90399 (diff) | |
download | PeerTube-6c5065a011b099618681a37bd77eaa7bd3db752e.tar.gz PeerTube-6c5065a011b099618681a37bd77eaa7bd3db752e.tar.zst PeerTube-6c5065a011b099618681a37bd77eaa7bd3db752e.zip |
Introduce server commands
Diffstat (limited to 'shared/extra-utils/miscs/generate.ts')
-rw-r--r-- | shared/extra-utils/miscs/generate.ts | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/shared/extra-utils/miscs/generate.ts b/shared/extra-utils/miscs/generate.ts new file mode 100644 index 000000000..4e70ab853 --- /dev/null +++ b/shared/extra-utils/miscs/generate.ts | |||
@@ -0,0 +1,61 @@ | |||
1 | import { ensureDir, pathExists } from 'fs-extra' | ||
2 | import { dirname } from 'path' | ||
3 | import { buildAbsoluteFixturePath } from './tests' | ||
4 | import * as ffmpeg from 'fluent-ffmpeg' | ||
5 | |||
6 | async function generateHighBitrateVideo () { | ||
7 | const tempFixturePath = buildAbsoluteFixturePath('video_high_bitrate_1080p.mp4', true) | ||
8 | |||
9 | await ensureDir(dirname(tempFixturePath)) | ||
10 | |||
11 | const exists = await pathExists(tempFixturePath) | ||
12 | if (!exists) { | ||
13 | console.log('Generating high bitrate video.') | ||
14 | |||
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) => { | ||
20 | ffmpeg() | ||
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) | ||
25 | .on('error', rej) | ||
26 | .on('end', () => res(tempFixturePath)) | ||
27 | .run() | ||
28 | }) | ||
29 | } | ||
30 | |||
31 | return tempFixturePath | ||
32 | } | ||
33 | |||
34 | async function generateVideoWithFramerate (fps = 60) { | ||
35 | const tempFixturePath = buildAbsoluteFixturePath(`video_${fps}fps.mp4`, true) | ||
36 | |||
37 | await ensureDir(dirname(tempFixturePath)) | ||
38 | |||
39 | const exists = await pathExists(tempFixturePath) | ||
40 | if (!exists) { | ||
41 | console.log('Generating video with framerate %d.', fps) | ||
42 | |||
43 | return new Promise<string>((res, rej) => { | ||
44 | ffmpeg() | ||
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) | ||
49 | .on('error', rej) | ||
50 | .on('end', () => res(tempFixturePath)) | ||
51 | .run() | ||
52 | }) | ||
53 | } | ||
54 | |||
55 | return tempFixturePath | ||
56 | } | ||
57 | |||
58 | export { | ||
59 | generateHighBitrateVideo, | ||
60 | generateVideoWithFramerate | ||
61 | } | ||