diff options
author | Felix Ableitner <me@nutomic.com> | 2018-10-08 09:26:04 -0500 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-10-08 16:26:04 +0200 |
commit | edb4ffc7e0b13659d7c73b120f2c87b27e4c26a1 (patch) | |
tree | fb9df6826eaeb23ab3bcac7fe21773978c68d27c /server/tests | |
parent | 2cae5f13076a31aa95774679aed1f13c3bd5f8ce (diff) | |
download | PeerTube-edb4ffc7e0b13659d7c73b120f2c87b27e4c26a1.tar.gz PeerTube-edb4ffc7e0b13659d7c73b120f2c87b27e4c26a1.tar.zst PeerTube-edb4ffc7e0b13659d7c73b120f2c87b27e4c26a1.zip |
Set bitrate limits for transcoding (fixes #638) (#1135)
* Set bitrate limits for transcoding (fixes #638)
* added optimization script and test, changed stuff
* fix test, improve docs
* re-add optimize-old-videos script
* added documentation
* Don't optimize videos without valid UUID, or redundancy videos
* move getUUIDFromFilename
* fix tests?
* update torrent and file size, some more fixes/improvements
* use higher bitrate for high fps video, adjust bitrates
* add test video
* don't throw error if resolution is undefined
* generate test fixture on the fly
* use random noise video for bitrate test, add promise
* shorten test video to avoid timeout
* use existing function to optimize video
* various fixes
* increase test timeout
* limit test fixture size, add link
* test fixes
* add await
* more test fixes, add -b:v parameter
* replace ffmpeg wiki link
* fix ffmpeg params
* fix unit test
* add test fixture to .gitgnore
* add video transcoding fps model
* add missing file
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/videos/video-transcoder.ts | 62 |
1 files changed, 58 insertions, 4 deletions
diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index 0f83d4d57..ec554ed19 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts | |||
@@ -4,8 +4,8 @@ import * as chai from 'chai' | |||
4 | import 'mocha' | 4 | import 'mocha' |
5 | import { omit } from 'lodash' | 5 | import { omit } from 'lodash' |
6 | import * as ffmpeg from 'fluent-ffmpeg' | 6 | import * as ffmpeg from 'fluent-ffmpeg' |
7 | import { VideoDetails, VideoState } from '../../../../shared/models/videos' | 7 | import { VideoDetails, VideoState, getMaxBitrate, VideoResolution } from '../../../../shared/models/videos' |
8 | import { getVideoFileFPS, audio } from '../../../helpers/ffmpeg-utils' | 8 | import { getVideoFileFPS, audio, getVideoFileBitrate, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' |
9 | import { | 9 | import { |
10 | buildAbsoluteFixturePath, | 10 | buildAbsoluteFixturePath, |
11 | doubleFollow, | 11 | doubleFollow, |
@@ -20,8 +20,10 @@ import { | |||
20 | uploadVideo, | 20 | uploadVideo, |
21 | webtorrentAdd | 21 | webtorrentAdd |
22 | } from '../../utils' | 22 | } from '../../utils' |
23 | import { join } from 'path' | 23 | import { join, basename } from 'path' |
24 | import { waitJobs } from '../../utils/server/jobs' | 24 | import { waitJobs } from '../../utils/server/jobs' |
25 | import { remove } from 'fs-extra' | ||
26 | import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' | ||
25 | 27 | ||
26 | const expect = chai.expect | 28 | const expect = chai.expect |
27 | 29 | ||
@@ -228,7 +230,7 @@ describe('Test video transcoding', function () { | |||
228 | } | 230 | } |
229 | }) | 231 | }) |
230 | 232 | ||
231 | it('Should wait transcoding before publishing the video', async function () { | 233 | it('Should wait for transcoding before publishing the video', async function () { |
232 | this.timeout(80000) | 234 | this.timeout(80000) |
233 | 235 | ||
234 | { | 236 | { |
@@ -281,7 +283,59 @@ describe('Test video transcoding', function () { | |||
281 | } | 283 | } |
282 | }) | 284 | }) |
283 | 285 | ||
286 | const tempFixturePath = buildAbsoluteFixturePath('video_high_bitrate_1080p.mp4') | ||
287 | it('Should respect maximum bitrate values', async function () { | ||
288 | this.timeout(160000) | ||
289 | |||
290 | { | ||
291 | // Generate a random, high bitrate video on the fly, so we don't have to include | ||
292 | // a large file in the repo. The video needs to have a certain minimum length so | ||
293 | // that FFmpeg properly applies bitrate limits. | ||
294 | // https://stackoverflow.com/a/15795112 | ||
295 | await new Promise<void>(async (res, rej) => { | ||
296 | ffmpeg() | ||
297 | .outputOptions(['-f rawvideo', '-video_size 1920x1080', '-i /dev/urandom']) | ||
298 | .outputOptions(['-ac 2', '-f s16le', '-i /dev/urandom', '-t 10']) | ||
299 | .outputOptions(['-maxrate 10M', '-bufsize 10M']) | ||
300 | .output(tempFixturePath) | ||
301 | .on('error', rej) | ||
302 | .on('end', res) | ||
303 | .run() | ||
304 | }) | ||
305 | |||
306 | const bitrate = await getVideoFileBitrate(tempFixturePath) | ||
307 | expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 60, VIDEO_TRANSCODING_FPS)) | ||
308 | |||
309 | const videoAttributes = { | ||
310 | name: 'high bitrate video', | ||
311 | description: 'high bitrate video', | ||
312 | fixture: basename(tempFixturePath) | ||
313 | } | ||
314 | |||
315 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | ||
316 | |||
317 | await waitJobs(servers) | ||
318 | |||
319 | for (const server of servers) { | ||
320 | const res = await getVideosList(server.url) | ||
321 | |||
322 | const video = res.body.data.find(v => v.name === videoAttributes.name) | ||
323 | |||
324 | for (const resolution of ['240', '360', '480', '720', '1080']) { | ||
325 | const path = join(root(), 'test2', 'videos', video.uuid + '-' + resolution + '.mp4') | ||
326 | const bitrate = await getVideoFileBitrate(path) | ||
327 | const fps = await getVideoFileFPS(path) | ||
328 | const resolution2 = await getVideoFileResolution(path) | ||
329 | |||
330 | expect(resolution2.videoFileResolution.toString()).to.equal(resolution) | ||
331 | expect(bitrate).to.be.below(getMaxBitrate(resolution2.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)) | ||
332 | } | ||
333 | } | ||
334 | } | ||
335 | }) | ||
336 | |||
284 | after(async function () { | 337 | after(async function () { |
338 | remove(tempFixturePath) | ||
285 | killallServers(servers) | 339 | killallServers(servers) |
286 | }) | 340 | }) |
287 | }) | 341 | }) |