aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/videos')
-rw-r--r--server/tests/api/videos/video-transcoder.ts62
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'
4import 'mocha' 4import 'mocha'
5import { omit } from 'lodash' 5import { omit } from 'lodash'
6import * as ffmpeg from 'fluent-ffmpeg' 6import * as ffmpeg from 'fluent-ffmpeg'
7import { VideoDetails, VideoState } from '../../../../shared/models/videos' 7import { VideoDetails, VideoState, getMaxBitrate, VideoResolution } from '../../../../shared/models/videos'
8import { getVideoFileFPS, audio } from '../../../helpers/ffmpeg-utils' 8import { getVideoFileFPS, audio, getVideoFileBitrate, getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
9import { 9import {
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'
23import { join } from 'path' 23import { join, basename } from 'path'
24import { waitJobs } from '../../utils/server/jobs' 24import { waitJobs } from '../../utils/server/jobs'
25import { remove } from 'fs-extra'
26import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants'
25 27
26const expect = chai.expect 28const 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})