aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/miscs
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/utils/miscs')
-rw-r--r--server/tests/utils/miscs/miscs.ts31
1 files changed, 29 insertions, 2 deletions
diff --git a/server/tests/utils/miscs/miscs.ts b/server/tests/utils/miscs/miscs.ts
index d20fa96b8..589daa420 100644
--- a/server/tests/utils/miscs/miscs.ts
+++ b/server/tests/utils/miscs/miscs.ts
@@ -4,7 +4,8 @@ import * as chai from 'chai'
4import { isAbsolute, join } from 'path' 4import { isAbsolute, join } from 'path'
5import * as request from 'supertest' 5import * as request from 'supertest'
6import * as WebTorrent from 'webtorrent' 6import * as WebTorrent from 'webtorrent'
7import { readFile } from 'fs-extra' 7import { pathExists, readFile } from 'fs-extra'
8import * as ffmpeg from 'fluent-ffmpeg'
8 9
9const expect = chai.expect 10const expect = chai.expect
10let webtorrent = new WebTorrent() 11let webtorrent = new WebTorrent()
@@ -61,6 +62,31 @@ function buildAbsoluteFixturePath (path: string, customTravisPath = false) {
61 return join(__dirname, '..', '..', 'fixtures', path) 62 return join(__dirname, '..', '..', 'fixtures', path)
62} 63}
63 64
65async function generateHighBitrateVideo () {
66 const tempFixturePath = buildAbsoluteFixturePath('video_high_bitrate_1080p.mp4', true)
67
68 const exists = await pathExists(tempFixturePath)
69 if (!exists) {
70
71 // Generate a random, high bitrate video on the fly, so we don't have to include
72 // a large file in the repo. The video needs to have a certain minimum length so
73 // that FFmpeg properly applies bitrate limits.
74 // https://stackoverflow.com/a/15795112
75 return new Promise<string>(async (res, rej) => {
76 ffmpeg()
77 .outputOptions([ '-f rawvideo', '-video_size 1920x1080', '-i /dev/urandom' ])
78 .outputOptions([ '-ac 2', '-f s16le', '-i /dev/urandom', '-t 10' ])
79 .outputOptions([ '-maxrate 10M', '-bufsize 10M' ])
80 .output(tempFixturePath)
81 .on('error', rej)
82 .on('end', () => res(tempFixturePath))
83 .run()
84 })
85 }
86
87 return tempFixturePath
88}
89
64// --------------------------------------------------------------------------- 90// ---------------------------------------------------------------------------
65 91
66export { 92export {
@@ -70,5 +96,6 @@ export {
70 immutableAssign, 96 immutableAssign,
71 testImage, 97 testImage,
72 buildAbsoluteFixturePath, 98 buildAbsoluteFixturePath,
73 root 99 root,
100 generateHighBitrateVideo
74} 101}