aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-24 15:22:56 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-11-25 10:07:51 +0100
commitca5c612bfdd225433bcc6ace01c8024df3f674ba (patch)
tree1b722cc346c9079c65338f0792ce7bcd2a20f8a0 /server
parent5a547f69d5dc5867e253f7721513479c754b4f15 (diff)
downloadPeerTube-ca5c612bfdd225433bcc6ace01c8024df3f674ba.tar.gz
PeerTube-ca5c612bfdd225433bcc6ace01c8024df3f674ba.tar.zst
PeerTube-ca5c612bfdd225433bcc6ace01c8024df3f674ba.zip
Add live transcoding bit rate tests
Diffstat (limited to 'server')
-rw-r--r--server/initializers/checker-before-init.ts2
-rw-r--r--server/lib/video-transcoding-profiles.ts3
-rw-r--r--server/tests/api/live/live.ts22
-rw-r--r--server/tests/api/videos/audio-only.ts6
-rw-r--r--server/tests/api/videos/video-transcoder.ts25
-rw-r--r--server/tests/cli/optimize-old-videos.ts4
-rw-r--r--server/tests/cli/prune-storage.ts14
7 files changed, 48 insertions, 28 deletions
diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts
index 4ffd6fad9..b04f3e538 100644
--- a/server/initializers/checker-before-init.ts
+++ b/server/initializers/checker-before-init.ts
@@ -82,8 +82,6 @@ function checkMissedConfig () {
82async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) { 82async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) {
83 if (CONFIG.TRANSCODING.ENABLED === false) return undefined 83 if (CONFIG.TRANSCODING.ENABLED === false) return undefined
84 84
85 checkFFmpegEncoders()
86
87 const Ffmpeg = require('fluent-ffmpeg') 85 const Ffmpeg = require('fluent-ffmpeg')
88 const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs) 86 const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs)
89 const codecs = await getAvailableCodecsPromise() 87 const codecs = await getAvailableCodecsPromise()
diff --git a/server/lib/video-transcoding-profiles.ts b/server/lib/video-transcoding-profiles.ts
index 12e22a19d..91a5c65f2 100644
--- a/server/lib/video-transcoding-profiles.ts
+++ b/server/lib/video-transcoding-profiles.ts
@@ -38,7 +38,8 @@ const defaultX264LiveOptionsBuilder: EncoderOptionsBuilder = async ({ resolution
38 return { 38 return {
39 outputOptions: [ 39 outputOptions: [
40 `${buildStreamSuffix('-b:v', streamNum)} ${targetBitrate}`, 40 `${buildStreamSuffix('-b:v', streamNum)} ${targetBitrate}`,
41 `-maxrate ${targetBitrate}`, `-bufsize ${targetBitrate * 2}` 41 `-maxrate ${targetBitrate}`,
42 `-bufsize ${targetBitrate * 2}`
42 ] 43 ]
43 } 44 }
44} 45}
diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts
index ac91b6b08..e685be08e 100644
--- a/server/tests/api/live/live.ts
+++ b/server/tests/api/live/live.ts
@@ -3,10 +3,13 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { FfmpegCommand } from 'fluent-ffmpeg' 5import { FfmpegCommand } from 'fluent-ffmpeg'
6import { join } from 'path'
7import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils'
6import { getLiveNotificationSocket } from '@shared/extra-utils/socket/socket-io' 8import { getLiveNotificationSocket } from '@shared/extra-utils/socket/socket-io'
7import { LiveVideo, LiveVideoCreate, Video, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' 9import { LiveVideo, LiveVideoCreate, Video, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models'
8import { 10import {
9 addVideoToBlacklist, 11 addVideoToBlacklist,
12 buildServerDirectory,
10 checkLiveCleanup, 13 checkLiveCleanup,
11 checkLiveSegmentHash, 14 checkLiveSegmentHash,
12 checkResolutionsInMasterPlaylist, 15 checkResolutionsInMasterPlaylist,
@@ -396,10 +399,11 @@ describe('Test live', function () {
396 this.timeout(60000) 399 this.timeout(60000)
397 400
398 const resolutions = [ 240, 360, 720 ] 401 const resolutions = [ 240, 360, 720 ]
402
399 await updateConf(resolutions) 403 await updateConf(resolutions)
400 liveVideoId = await createLiveWrapper(true) 404 liveVideoId = await createLiveWrapper(true)
401 405
402 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) 406 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId, 'video_short2.webm')
403 await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoId) 407 await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoId)
404 await waitJobs(servers) 408 await waitJobs(servers)
405 409
@@ -409,6 +413,12 @@ describe('Test live', function () {
409 413
410 await waitJobs(servers) 414 await waitJobs(servers)
411 415
416 const bitrateLimits = {
417 720: 2800 * 1000,
418 360: 780 * 1000,
419 240: 320 * 1000
420 }
421
412 for (const server of servers) { 422 for (const server of servers) {
413 const resVideo = await getVideo(server.url, liveVideoId) 423 const resVideo = await getVideo(server.url, liveVideoId)
414 const video: VideoDetails = resVideo.body 424 const video: VideoDetails = resVideo.body
@@ -424,9 +434,17 @@ describe('Test live', function () {
424 const file = hlsPlaylist.files.find(f => f.resolution.id === resolution) 434 const file = hlsPlaylist.files.find(f => f.resolution.id === resolution)
425 435
426 expect(file).to.exist 436 expect(file).to.exist
427 expect(file.fps).to.be.oneOf([ 24, 25 ]) 437 expect(file.fps).to.be.approximately(30, 5)
428 expect(file.size).to.be.greaterThan(1) 438 expect(file.size).to.be.greaterThan(1)
429 439
440 const filename = `${video.uuid}-${resolution}-fragmented.mp4`
441 const segmentPath = buildServerDirectory(servers[0], join('streaming-playlists', 'hls', video.uuid, filename))
442
443 const probe = await ffprobePromise(segmentPath)
444 const videoStream = await getVideoStreamFromFile(segmentPath, probe)
445 console.log(videoStream)
446 expect(probe.format.bit_rate).to.be.below(bitrateLimits[videoStream.height])
447
430 await makeRawRequest(file.torrentUrl, 200) 448 await makeRawRequest(file.torrentUrl, 200)
431 await makeRawRequest(file.fileUrl, 200) 449 await makeRawRequest(file.fileUrl, 200)
432 } 450 }
diff --git a/server/tests/api/videos/audio-only.ts b/server/tests/api/videos/audio-only.ts
index 053b29ca1..294a00112 100644
--- a/server/tests/api/videos/audio-only.ts
+++ b/server/tests/api/videos/audio-only.ts
@@ -5,11 +5,11 @@ import * as chai from 'chai'
5import { join } from 'path' 5import { join } from 'path'
6import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils' 6import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils'
7import { 7import {
8 buildServerDirectory,
8 cleanupTests, 9 cleanupTests,
9 doubleFollow, 10 doubleFollow,
10 flushAndRunMultipleServers, 11 flushAndRunMultipleServers,
11 getVideo, 12 getVideo,
12 root,
13 ServerInfo, 13 ServerInfo,
14 setAccessTokensToServers, 14 setAccessTokensToServers,
15 uploadVideo, 15 uploadVideo,
@@ -80,8 +80,8 @@ describe('Test audio only video transcoding', function () {
80 80
81 it('0p transcoded video should not have video', async function () { 81 it('0p transcoded video should not have video', async function () {
82 const paths = [ 82 const paths = [
83 join(root(), 'test' + servers[0].internalServerNumber, 'videos', videoUUID + '-0.mp4'), 83 buildServerDirectory(servers[0], join('videos', videoUUID + '-0.mp4')),
84 join(root(), 'test' + servers[0].internalServerNumber, 'streaming-playlists', 'hls', videoUUID, videoUUID + '-0-fragmented.mp4') 84 buildServerDirectory(servers[0], join('streaming-playlists', 'hls', videoUUID, videoUUID + '-0-fragmented.mp4'))
85 ] 85 ]
86 86
87 for (const path of paths) { 87 for (const path of paths) {
diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts
index 3e336e786..164843d32 100644
--- a/server/tests/api/videos/video-transcoder.ts
+++ b/server/tests/api/videos/video-transcoder.ts
@@ -5,10 +5,10 @@ import * as chai from 'chai'
5import { FfprobeData } from 'fluent-ffmpeg' 5import { FfprobeData } from 'fluent-ffmpeg'
6import { omit } from 'lodash' 6import { omit } from 'lodash'
7import { join } from 'path' 7import { join } from 'path'
8
9import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' 8import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants'
10import { 9import {
11 buildAbsoluteFixturePath, 10 buildAbsoluteFixturePath,
11 buildServerDirectory,
12 cleanupTests, 12 cleanupTests,
13 doubleFollow, 13 doubleFollow,
14 flushAndRunMultipleServers, 14 flushAndRunMultipleServers,
@@ -20,7 +20,6 @@ import {
20 getVideoFileMetadataUrl, 20 getVideoFileMetadataUrl,
21 getVideosList, 21 getVideosList,
22 makeGetRequest, 22 makeGetRequest,
23 root,
24 ServerInfo, 23 ServerInfo,
25 setAccessTokensToServers, 24 setAccessTokensToServers,
26 updateCustomSubConfig, 25 updateCustomSubConfig,
@@ -136,7 +135,7 @@ describe('Test video transcoding', function () {
136 135
137 expect(videoDetails.files).to.have.lengthOf(4) 136 expect(videoDetails.files).to.have.lengthOf(4)
138 137
139 const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-240.mp4') 138 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4'))
140 const probe = await getAudioStream(path) 139 const probe = await getAudioStream(path)
141 140
142 if (probe.audioStream) { 141 if (probe.audioStream) {
@@ -167,7 +166,7 @@ describe('Test video transcoding', function () {
167 const videoDetails: VideoDetails = res2.body 166 const videoDetails: VideoDetails = res2.body
168 167
169 expect(videoDetails.files).to.have.lengthOf(4) 168 expect(videoDetails.files).to.have.lengthOf(4)
170 const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-240.mp4') 169 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4'))
171 const probe = await getAudioStream(path) 170 const probe = await getAudioStream(path)
172 expect(probe).to.not.have.property('audioStream') 171 expect(probe).to.not.have.property('audioStream')
173 } 172 }
@@ -192,10 +191,13 @@ describe('Test video transcoding', function () {
192 const videoDetails: VideoDetails = res2.body 191 const videoDetails: VideoDetails = res2.body
193 192
194 expect(videoDetails.files).to.have.lengthOf(4) 193 expect(videoDetails.files).to.have.lengthOf(4)
194
195 const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) 195 const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture)
196 const fixtureVideoProbe = await getAudioStream(fixturePath) 196 const fixtureVideoProbe = await getAudioStream(fixturePath)
197 const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-240.mp4') 197 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4'))
198
198 const videoProbe = await getAudioStream(path) 199 const videoProbe = await getAudioStream(path)
200
199 if (videoProbe.audioStream && fixtureVideoProbe.audioStream) { 201 if (videoProbe.audioStream && fixtureVideoProbe.audioStream) {
200 const toOmit = [ 'max_bit_rate', 'duration', 'duration_ts', 'nb_frames', 'start_time', 'start_pts' ] 202 const toOmit = [ 'max_bit_rate', 'duration', 'duration_ts', 'nb_frames', 'start_time', 'start_pts' ]
201 expect(omit(videoProbe.audioStream, toOmit)).to.be.deep.equal(omit(fixtureVideoProbe.audioStream, toOmit)) 203 expect(omit(videoProbe.audioStream, toOmit)).to.be.deep.equal(omit(fixtureVideoProbe.audioStream, toOmit))
@@ -231,13 +233,13 @@ describe('Test video transcoding', function () {
231 expect(videoDetails.files[3].fps).to.be.below(31) 233 expect(videoDetails.files[3].fps).to.be.below(31)
232 234
233 for (const resolution of [ '240', '360', '480' ]) { 235 for (const resolution of [ '240', '360', '480' ]) {
234 const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-' + resolution + '.mp4') 236 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4'))
235 const fps = await getVideoFileFPS(path) 237 const fps = await getVideoFileFPS(path)
236 238
237 expect(fps).to.be.below(31) 239 expect(fps).to.be.below(31)
238 } 240 }
239 241
240 const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-720.mp4') 242 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4'))
241 const fps = await getVideoFileFPS(path) 243 const fps = await getVideoFileFPS(path)
242 244
243 expect(fps).to.be.above(58).and.below(62) 245 expect(fps).to.be.above(58).and.below(62)
@@ -325,7 +327,8 @@ describe('Test video transcoding', function () {
325 const video = res.body.data.find(v => v.name === videoAttributes.name) 327 const video = res.body.data.find(v => v.name === videoAttributes.name)
326 328
327 for (const resolution of [ '240', '360', '480', '720', '1080' ]) { 329 for (const resolution of [ '240', '360', '480', '720', '1080' ]) {
328 const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-' + resolution + '.mp4') 330 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4'))
331
329 const bitrate = await getVideoFileBitrate(path) 332 const bitrate = await getVideoFileBitrate(path)
330 const fps = await getVideoFileFPS(path) 333 const fps = await getVideoFileFPS(path)
331 const resolution2 = await getVideoFileResolution(path) 334 const resolution2 = await getVideoFileResolution(path)
@@ -458,13 +461,13 @@ describe('Test video transcoding', function () {
458 const video = res.body.data.find(v => v.name === videoAttributes.name) 461 const video = res.body.data.find(v => v.name === videoAttributes.name)
459 462
460 { 463 {
461 const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-240.mp4') 464 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4'))
462 const fps = await getVideoFileFPS(path) 465 const fps = await getVideoFileFPS(path)
463 expect(fps).to.be.equal(25) 466 expect(fps).to.be.equal(25)
464 } 467 }
465 468
466 { 469 {
467 const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-720.mp4') 470 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4'))
468 const fps = await getVideoFileFPS(path) 471 const fps = await getVideoFileFPS(path)
469 expect(fps).to.be.equal(59) 472 expect(fps).to.be.equal(59)
470 } 473 }
@@ -513,7 +516,7 @@ describe('Test video transcoding', function () {
513 await waitJobs(servers) 516 await waitJobs(servers)
514 517
515 { 518 {
516 const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', videoUUID + '-240.mp4') 519 const path = buildServerDirectory(servers[1], join('videos', videoUUID + '-240.mp4'))
517 const metadata = await getMetadataFromFile(path) 520 const metadata = await getMetadataFromFile(path)
518 521
519 // expected format properties 522 // expected format properties
diff --git a/server/tests/cli/optimize-old-videos.ts b/server/tests/cli/optimize-old-videos.ts
index 420fb8049..91a1c9cc4 100644
--- a/server/tests/cli/optimize-old-videos.ts
+++ b/server/tests/cli/optimize-old-videos.ts
@@ -4,6 +4,7 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { join } from 'path' 5import { join } from 'path'
6import { 6import {
7 buildServerDirectory,
7 cleanupTests, 8 cleanupTests,
8 doubleFollow, 9 doubleFollow,
9 execCLI, 10 execCLI,
@@ -12,7 +13,6 @@ import {
12 getEnvCli, 13 getEnvCli,
13 getVideo, 14 getVideo,
14 getVideosList, 15 getVideosList,
15 root,
16 ServerInfo, 16 ServerInfo,
17 setAccessTokensToServers, 17 setAccessTokensToServers,
18 uploadVideo, 18 uploadVideo,
@@ -100,7 +100,7 @@ describe('Test optimize old videos', function () {
100 100
101 expect(file.size).to.be.below(8000000) 101 expect(file.size).to.be.below(8000000)
102 102
103 const path = join(root(), 'test' + servers[0].internalServerNumber, 'videos', video.uuid + '-' + file.resolution.id + '.mp4') 103 const path = buildServerDirectory(servers[0], join('videos', video.uuid + '-' + file.resolution.id + '.mp4'))
104 const bitrate = await getVideoFileBitrate(path) 104 const bitrate = await getVideoFileBitrate(path)
105 const fps = await getVideoFileFPS(path) 105 const fps = await getVideoFileFPS(path)
106 const resolution = await getVideoFileResolution(path) 106 const resolution = await getVideoFileResolution(path)
diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts
index 6cda80070..052a5f91e 100644
--- a/server/tests/cli/prune-storage.ts
+++ b/server/tests/cli/prune-storage.ts
@@ -28,13 +28,13 @@ import { join } from 'path'
28const expect = chai.expect 28const expect = chai.expect
29 29
30async function countFiles (internalServerNumber: number, directory: string) { 30async function countFiles (internalServerNumber: number, directory: string) {
31 const files = await readdir(buildServerDirectory(internalServerNumber, directory)) 31 const files = await readdir(buildServerDirectory({ internalServerNumber }, directory))
32 32
33 return files.length 33 return files.length
34} 34}
35 35
36async function assertNotExists (internalServerNumber: number, directory: string, substring: string) { 36async function assertNotExists (internalServerNumber: number, directory: string, substring: string) {
37 const files = await readdir(buildServerDirectory(internalServerNumber, directory)) 37 const files = await readdir(buildServerDirectory({ internalServerNumber }, directory))
38 38
39 for (const f of files) { 39 for (const f of files) {
40 expect(f).to.not.contain(substring) 40 expect(f).to.not.contain(substring)
@@ -124,7 +124,7 @@ describe('Test prune storage scripts', function () {
124 it('Should create some dirty files', async function () { 124 it('Should create some dirty files', async function () {
125 for (let i = 0; i < 2; i++) { 125 for (let i = 0; i < 2; i++) {
126 { 126 {
127 const base = buildServerDirectory(servers[0].internalServerNumber, 'videos') 127 const base = buildServerDirectory(servers[0], 'videos')
128 128
129 const n1 = uuidv4() + '.mp4' 129 const n1 = uuidv4() + '.mp4'
130 const n2 = uuidv4() + '.webm' 130 const n2 = uuidv4() + '.webm'
@@ -136,7 +136,7 @@ describe('Test prune storage scripts', function () {
136 } 136 }
137 137
138 { 138 {
139 const base = buildServerDirectory(servers[0].internalServerNumber, 'torrents') 139 const base = buildServerDirectory(servers[0], 'torrents')
140 140
141 const n1 = uuidv4() + '-240.torrent' 141 const n1 = uuidv4() + '-240.torrent'
142 const n2 = uuidv4() + '-480.torrent' 142 const n2 = uuidv4() + '-480.torrent'
@@ -148,7 +148,7 @@ describe('Test prune storage scripts', function () {
148 } 148 }
149 149
150 { 150 {
151 const base = buildServerDirectory(servers[0].internalServerNumber, 'thumbnails') 151 const base = buildServerDirectory(servers[0], 'thumbnails')
152 152
153 const n1 = uuidv4() + '.jpg' 153 const n1 = uuidv4() + '.jpg'
154 const n2 = uuidv4() + '.jpg' 154 const n2 = uuidv4() + '.jpg'
@@ -160,7 +160,7 @@ describe('Test prune storage scripts', function () {
160 } 160 }
161 161
162 { 162 {
163 const base = buildServerDirectory(servers[0].internalServerNumber, 'previews') 163 const base = buildServerDirectory(servers[0], 'previews')
164 164
165 const n1 = uuidv4() + '.jpg' 165 const n1 = uuidv4() + '.jpg'
166 const n2 = uuidv4() + '.jpg' 166 const n2 = uuidv4() + '.jpg'
@@ -172,7 +172,7 @@ describe('Test prune storage scripts', function () {
172 } 172 }
173 173
174 { 174 {
175 const base = buildServerDirectory(servers[0].internalServerNumber, 'avatars') 175 const base = buildServerDirectory(servers[0], 'avatars')
176 176
177 const n1 = uuidv4() + '.png' 177 const n1 = uuidv4() + '.png'
178 const n2 = uuidv4() + '.jpg' 178 const n2 = uuidv4() + '.jpg'