diff options
author | Chocobozzz <me@florianbigard.com> | 2018-10-18 16:53:52 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-10-18 16:54:26 +0200 |
commit | 74cd011b6c089cac88a4b8aa76ad3be2ca4f1c15 (patch) | |
tree | 0fa74ef54f80cf5b2825f0b2d2d123e4c1aaa1dc /server/tests/utils/miscs/miscs.ts | |
parent | ccbbe2b8d4b18d48d132058776c22397250a4a87 (diff) | |
download | PeerTube-74cd011b6c089cac88a4b8aa76ad3be2ca4f1c15.tar.gz PeerTube-74cd011b6c089cac88a4b8aa76ad3be2ca4f1c15.tar.zst PeerTube-74cd011b6c089cac88a4b8aa76ad3be2ca4f1c15.zip |
Fix optimize old videos script
Diffstat (limited to 'server/tests/utils/miscs/miscs.ts')
-rw-r--r-- | server/tests/utils/miscs/miscs.ts | 31 |
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' | |||
4 | import { isAbsolute, join } from 'path' | 4 | import { isAbsolute, join } from 'path' |
5 | import * as request from 'supertest' | 5 | import * as request from 'supertest' |
6 | import * as WebTorrent from 'webtorrent' | 6 | import * as WebTorrent from 'webtorrent' |
7 | import { readFile } from 'fs-extra' | 7 | import { pathExists, readFile } from 'fs-extra' |
8 | import * as ffmpeg from 'fluent-ffmpeg' | ||
8 | 9 | ||
9 | const expect = chai.expect | 10 | const expect = chai.expect |
10 | let webtorrent = new WebTorrent() | 11 | let 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 | ||
65 | async 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 | ||
66 | export { | 92 | export { |
@@ -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 | } |