aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-10-08 17:47:19 +0200
committerChocobozzz <me@florianbigard.com>2018-10-08 17:47:19 +0200
commitc1c86c1599acf8aad71fb7d7f312c43d6d1fa5ac (patch)
treed11cc73c8943c3261c04442a7eed5caf68e86e14 /server
parent9f1ddd249652c1e35b45db33885a00a005f9b059 (diff)
downloadPeerTube-c1c86c1599acf8aad71fb7d7f312c43d6d1fa5ac.tar.gz
PeerTube-c1c86c1599acf8aad71fb7d7f312c43d6d1fa5ac.tar.zst
PeerTube-c1c86c1599acf8aad71fb7d7f312c43d6d1fa5ac.zip
Try to cache video_high_bitrate_1080p in travis
Diffstat (limited to 'server')
-rw-r--r--server/tests/api/videos/video-transcoder.ts79
-rw-r--r--server/tests/utils/miscs/miscs.ts4
2 files changed, 44 insertions, 39 deletions
diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts
index ec554ed19..0ce5197ea 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, getMaxBitrate, VideoResolution } from '../../../../shared/models/videos' 7import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos'
8import { getVideoFileFPS, audio, getVideoFileBitrate, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' 8import { audio, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
9import { 9import {
10 buildAbsoluteFixturePath, 10 buildAbsoluteFixturePath,
11 doubleFollow, 11 doubleFollow,
@@ -20,9 +20,9 @@ import {
20 uploadVideo, 20 uploadVideo,
21 webtorrentAdd 21 webtorrentAdd
22} from '../../utils' 22} from '../../utils'
23import { join, basename } from 'path' 23import { join } from 'path'
24import { waitJobs } from '../../utils/server/jobs' 24import { waitJobs } from '../../utils/server/jobs'
25import { remove } from 'fs-extra' 25import { pathExists } from 'fs-extra'
26import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' 26import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants'
27 27
28const expect = chai.expect 28const expect = chai.expect
@@ -283,59 +283,62 @@ describe('Test video transcoding', function () {
283 } 283 }
284 }) 284 })
285 285
286 const tempFixturePath = buildAbsoluteFixturePath('video_high_bitrate_1080p.mp4') 286 const tempFixturePath = buildAbsoluteFixturePath('video_high_bitrate_1080p.mp4', true)
287 it('Should respect maximum bitrate values', async function () { 287 it('Should respect maximum bitrate values', async function () {
288 this.timeout(160000) 288 this.timeout(160000)
289 289
290 { 290 {
291 // Generate a random, high bitrate video on the fly, so we don't have to include 291 const exists = await pathExists(tempFixturePath)
292 // a large file in the repo. The video needs to have a certain minimum length so 292 if (!exists) {
293 // that FFmpeg properly applies bitrate limits. 293
294 // https://stackoverflow.com/a/15795112 294 // Generate a random, high bitrate video on the fly, so we don't have to include
295 await new Promise<void>(async (res, rej) => { 295 // a large file in the repo. The video needs to have a certain minimum length so
296 ffmpeg() 296 // that FFmpeg properly applies bitrate limits.
297 .outputOptions(['-f rawvideo', '-video_size 1920x1080', '-i /dev/urandom']) 297 // https://stackoverflow.com/a/15795112
298 .outputOptions(['-ac 2', '-f s16le', '-i /dev/urandom', '-t 10']) 298 await new Promise<void>(async (res, rej) => {
299 .outputOptions(['-maxrate 10M', '-bufsize 10M']) 299 ffmpeg()
300 .output(tempFixturePath) 300 .outputOptions([ '-f rawvideo', '-video_size 1920x1080', '-i /dev/urandom' ])
301 .on('error', rej) 301 .outputOptions([ '-ac 2', '-f s16le', '-i /dev/urandom', '-t 10' ])
302 .on('end', res) 302 .outputOptions([ '-maxrate 10M', '-bufsize 10M' ])
303 .run() 303 .output(tempFixturePath)
304 }) 304 .on('error', rej)
305 .on('end', res)
306 .run()
307 })
308 }
305 309
306 const bitrate = await getVideoFileBitrate(tempFixturePath) 310 const bitrate = await getVideoFileBitrate(tempFixturePath)
307 expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 60, VIDEO_TRANSCODING_FPS)) 311 expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 60, VIDEO_TRANSCODING_FPS))
312 }
308 313
309 const videoAttributes = { 314 const videoAttributes = {
310 name: 'high bitrate video', 315 name: 'high bitrate video',
311 description: 'high bitrate video', 316 description: 'high bitrate video',
312 fixture: basename(tempFixturePath) 317 fixture: tempFixturePath
313 } 318 }
314 319
315 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 320 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
316 321
317 await waitJobs(servers) 322 await waitJobs(servers)
318 323
319 for (const server of servers) { 324 for (const server of servers) {
320 const res = await getVideosList(server.url) 325 const res = await getVideosList(server.url)
321 326
322 const video = res.body.data.find(v => v.name === videoAttributes.name) 327 const video = res.body.data.find(v => v.name === videoAttributes.name)
323 328
324 for (const resolution of ['240', '360', '480', '720', '1080']) { 329 for (const resolution of ['240', '360', '480', '720', '1080']) {
325 const path = join(root(), 'test2', 'videos', video.uuid + '-' + resolution + '.mp4') 330 const path = join(root(), 'test2', 'videos', video.uuid + '-' + resolution + '.mp4')
326 const bitrate = await getVideoFileBitrate(path) 331 const bitrate = await getVideoFileBitrate(path)
327 const fps = await getVideoFileFPS(path) 332 const fps = await getVideoFileFPS(path)
328 const resolution2 = await getVideoFileResolution(path) 333 const resolution2 = await getVideoFileResolution(path)
329 334
330 expect(resolution2.videoFileResolution.toString()).to.equal(resolution) 335 expect(resolution2.videoFileResolution.toString()).to.equal(resolution)
331 expect(bitrate).to.be.below(getMaxBitrate(resolution2.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)) 336 expect(bitrate).to.be.below(getMaxBitrate(resolution2.videoFileResolution, fps, VIDEO_TRANSCODING_FPS))
332 }
333 } 337 }
334 } 338 }
335 }) 339 })
336 340
337 after(async function () { 341 after(async function () {
338 remove(tempFixturePath)
339 killallServers(servers) 342 killallServers(servers)
340 }) 343 })
341}) 344})
diff --git a/server/tests/utils/miscs/miscs.ts b/server/tests/utils/miscs/miscs.ts
index b2f80e9b1..d20fa96b8 100644
--- a/server/tests/utils/miscs/miscs.ts
+++ b/server/tests/utils/miscs/miscs.ts
@@ -51,11 +51,13 @@ async function testImage (url: string, imageName: string, imagePath: string, ext
51 expect(data.length).to.be.below(maxLength) 51 expect(data.length).to.be.below(maxLength)
52} 52}
53 53
54function buildAbsoluteFixturePath (path: string) { 54function buildAbsoluteFixturePath (path: string, customTravisPath = false) {
55 if (isAbsolute(path)) { 55 if (isAbsolute(path)) {
56 return path 56 return path
57 } 57 }
58 58
59 if (customTravisPath && process.env.TRAVIS) return join(process.env.HOME, 'fixtures', path)
60
59 return join(__dirname, '..', '..', 'fixtures', path) 61 return join(__dirname, '..', '..', 'fixtures', path)
60} 62}
61 63