aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-01-28 15:52:44 +0100
committerChocobozzz <me@florianbigard.com>2021-01-28 15:55:39 +0100
commit1896bca09e088b0da9d5e845407ecebae330618c (patch)
tree56041c445c0cd49aca536d0fd6b586730f4d341e /server/tests
parent529b37527cff5203a0689a15ce73dcee6e1eece2 (diff)
downloadPeerTube-1896bca09e088b0da9d5e845407ecebae330618c.tar.gz
PeerTube-1896bca09e088b0da9d5e845407ecebae330618c.tar.zst
PeerTube-1896bca09e088b0da9d5e845407ecebae330618c.zip
Support transcoding options/encoders by plugins
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/config.ts2
-rw-r--r--server/tests/api/server/config.ts6
-rw-r--r--server/tests/api/videos/video-transcoder.ts4
-rw-r--r--server/tests/fixtures/peertube-plugin-test-transcoding-one/main.js35
-rw-r--r--server/tests/fixtures/peertube-plugin-test-transcoding-one/package.json20
-rw-r--r--server/tests/fixtures/peertube-plugin-test-transcoding-two/main.js38
-rw-r--r--server/tests/fixtures/peertube-plugin-test-transcoding-two/package.json20
-rw-r--r--server/tests/plugins/index.ts9
-rw-r--r--server/tests/plugins/plugin-transcoding.ts226
9 files changed, 355 insertions, 5 deletions
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index d3ae5fe0a..e6309b5f7 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -87,6 +87,7 @@ describe('Test config API validators', function () {
87 allowAdditionalExtensions: true, 87 allowAdditionalExtensions: true,
88 allowAudioFiles: true, 88 allowAudioFiles: true,
89 threads: 1, 89 threads: 1,
90 profile: 'vod_profile',
90 resolutions: { 91 resolutions: {
91 '0p': false, 92 '0p': false,
92 '240p': false, 93 '240p': false,
@@ -115,6 +116,7 @@ describe('Test config API validators', function () {
115 transcoding: { 116 transcoding: {
116 enabled: true, 117 enabled: true,
117 threads: 4, 118 threads: 4,
119 profile: 'live_profile',
118 resolutions: { 120 resolutions: {
119 '240p': true, 121 '240p': true,
120 '360p': true, 122 '360p': true,
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index e0575bdfd..e5bab0b77 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -70,6 +70,7 @@ function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
70 expect(data.transcoding.allowAdditionalExtensions).to.be.false 70 expect(data.transcoding.allowAdditionalExtensions).to.be.false
71 expect(data.transcoding.allowAudioFiles).to.be.false 71 expect(data.transcoding.allowAudioFiles).to.be.false
72 expect(data.transcoding.threads).to.equal(2) 72 expect(data.transcoding.threads).to.equal(2)
73 expect(data.transcoding.profile).to.equal('default')
73 expect(data.transcoding.resolutions['240p']).to.be.true 74 expect(data.transcoding.resolutions['240p']).to.be.true
74 expect(data.transcoding.resolutions['360p']).to.be.true 75 expect(data.transcoding.resolutions['360p']).to.be.true
75 expect(data.transcoding.resolutions['480p']).to.be.true 76 expect(data.transcoding.resolutions['480p']).to.be.true
@@ -87,6 +88,7 @@ function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
87 expect(data.live.maxUserLives).to.equal(3) 88 expect(data.live.maxUserLives).to.equal(3)
88 expect(data.live.transcoding.enabled).to.be.false 89 expect(data.live.transcoding.enabled).to.be.false
89 expect(data.live.transcoding.threads).to.equal(2) 90 expect(data.live.transcoding.threads).to.equal(2)
91 expect(data.live.transcoding.profile).to.equal('default')
90 expect(data.live.transcoding.resolutions['240p']).to.be.false 92 expect(data.live.transcoding.resolutions['240p']).to.be.false
91 expect(data.live.transcoding.resolutions['360p']).to.be.false 93 expect(data.live.transcoding.resolutions['360p']).to.be.false
92 expect(data.live.transcoding.resolutions['480p']).to.be.false 94 expect(data.live.transcoding.resolutions['480p']).to.be.false
@@ -159,6 +161,7 @@ function checkUpdatedConfig (data: CustomConfig) {
159 expect(data.transcoding.threads).to.equal(1) 161 expect(data.transcoding.threads).to.equal(1)
160 expect(data.transcoding.allowAdditionalExtensions).to.be.true 162 expect(data.transcoding.allowAdditionalExtensions).to.be.true
161 expect(data.transcoding.allowAudioFiles).to.be.true 163 expect(data.transcoding.allowAudioFiles).to.be.true
164 expect(data.transcoding.profile).to.equal('vod_profile')
162 expect(data.transcoding.resolutions['240p']).to.be.false 165 expect(data.transcoding.resolutions['240p']).to.be.false
163 expect(data.transcoding.resolutions['360p']).to.be.true 166 expect(data.transcoding.resolutions['360p']).to.be.true
164 expect(data.transcoding.resolutions['480p']).to.be.true 167 expect(data.transcoding.resolutions['480p']).to.be.true
@@ -175,6 +178,7 @@ function checkUpdatedConfig (data: CustomConfig) {
175 expect(data.live.maxUserLives).to.equal(10) 178 expect(data.live.maxUserLives).to.equal(10)
176 expect(data.live.transcoding.enabled).to.be.true 179 expect(data.live.transcoding.enabled).to.be.true
177 expect(data.live.transcoding.threads).to.equal(4) 180 expect(data.live.transcoding.threads).to.equal(4)
181 expect(data.live.transcoding.profile).to.equal('live_profile')
178 expect(data.live.transcoding.resolutions['240p']).to.be.true 182 expect(data.live.transcoding.resolutions['240p']).to.be.true
179 expect(data.live.transcoding.resolutions['360p']).to.be.true 183 expect(data.live.transcoding.resolutions['360p']).to.be.true
180 expect(data.live.transcoding.resolutions['480p']).to.be.true 184 expect(data.live.transcoding.resolutions['480p']).to.be.true
@@ -319,6 +323,7 @@ describe('Test config', function () {
319 allowAdditionalExtensions: true, 323 allowAdditionalExtensions: true,
320 allowAudioFiles: true, 324 allowAudioFiles: true,
321 threads: 1, 325 threads: 1,
326 profile: 'vod_profile',
322 resolutions: { 327 resolutions: {
323 '0p': false, 328 '0p': false,
324 '240p': false, 329 '240p': false,
@@ -345,6 +350,7 @@ describe('Test config', function () {
345 transcoding: { 350 transcoding: {
346 enabled: true, 351 enabled: true,
347 threads: 4, 352 threads: 4,
353 profile: 'live_profile',
348 resolutions: { 354 resolutions: {
349 '240p': true, 355 '240p': true,
350 '360p': true, 356 '360p': true,
diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts
index 631230f26..5ad02df2f 100644
--- a/server/tests/api/videos/video-transcoder.ts
+++ b/server/tests/api/videos/video-transcoder.ts
@@ -511,7 +511,9 @@ describe('Test video transcoding', function () {
511 511
512 const resolutions = [ 240, 360, 480, 720, 1080 ] 512 const resolutions = [ 240, 360, 480, 720, 1080 ]
513 for (const r of resolutions) { 513 for (const r of resolutions) {
514 expect(await getServerFileSize(servers[1], `videos/${videoUUID}-${r}.mp4`)).to.be.below(60_000) 514 const path = `videos/${videoUUID}-${r}.mp4`
515 const size = await getServerFileSize(servers[1], path)
516 expect(size, `${path} not below ${60_000}`).to.be.below(60_000)
515 } 517 }
516 }) 518 })
517 519
diff --git a/server/tests/fixtures/peertube-plugin-test-transcoding-one/main.js b/server/tests/fixtures/peertube-plugin-test-transcoding-one/main.js
new file mode 100644
index 000000000..5990ce1ce
--- /dev/null
+++ b/server/tests/fixtures/peertube-plugin-test-transcoding-one/main.js
@@ -0,0 +1,35 @@
1async function register ({ transcodingManager }) {
2
3 {
4 const builder = () => {
5 return {
6 outputOptions: [
7 '-r 10'
8 ]
9 }
10 }
11
12 transcodingManager.addVODProfile('libx264', 'low-vod', builder)
13 }
14
15 {
16 const builder = (options) => {
17 return {
18 outputOptions: [
19 '-r:' + options.streamNum + ' 5'
20 ]
21 }
22 }
23
24 transcodingManager.addLiveProfile('libx264', 'low-live', builder)
25 }
26}
27
28async function unregister () {
29 return
30}
31
32module.exports = {
33 register,
34 unregister
35}
diff --git a/server/tests/fixtures/peertube-plugin-test-transcoding-one/package.json b/server/tests/fixtures/peertube-plugin-test-transcoding-one/package.json
new file mode 100644
index 000000000..bedbfa051
--- /dev/null
+++ b/server/tests/fixtures/peertube-plugin-test-transcoding-one/package.json
@@ -0,0 +1,20 @@
1{
2 "name": "peertube-plugin-test-transcoding-one",
3 "version": "0.0.1",
4 "description": "Plugin test transcoding 1",
5 "engine": {
6 "peertube": ">=1.3.0"
7 },
8 "keywords": [
9 "peertube",
10 "plugin"
11 ],
12 "homepage": "https://github.com/Chocobozzz/PeerTube",
13 "author": "Chocobozzz",
14 "bugs": "https://github.com/Chocobozzz/PeerTube/issues",
15 "library": "./main.js",
16 "staticDirs": {},
17 "css": [],
18 "clientScripts": [],
19 "translations": {}
20}
diff --git a/server/tests/fixtures/peertube-plugin-test-transcoding-two/main.js b/server/tests/fixtures/peertube-plugin-test-transcoding-two/main.js
new file mode 100644
index 000000000..a914bce49
--- /dev/null
+++ b/server/tests/fixtures/peertube-plugin-test-transcoding-two/main.js
@@ -0,0 +1,38 @@
1async function register ({ transcodingManager }) {
2
3 {
4 const builder = () => {
5 return {
6 outputOptions: []
7 }
8 }
9
10 transcodingManager.addVODProfile('libopus', 'test-vod-profile', builder)
11 transcodingManager.addVODProfile('libvpx-vp9', 'test-vod-profile', builder)
12
13 transcodingManager.addVODEncoderPriority('audio', 'libopus', 1000)
14 transcodingManager.addVODEncoderPriority('video', 'libvpx-vp9', 1000)
15 }
16
17 {
18 const builder = (options) => {
19 return {
20 outputOptions: [
21 '-b:' + options.streamNum + ' 10K'
22 ]
23 }
24 }
25
26 transcodingManager.addLiveProfile('libopus', 'test-live-profile', builder)
27 transcodingManager.addLiveEncoderPriority('audio', 'libopus', 1000)
28 }
29}
30
31async function unregister () {
32 return
33}
34
35module.exports = {
36 register,
37 unregister
38}
diff --git a/server/tests/fixtures/peertube-plugin-test-transcoding-two/package.json b/server/tests/fixtures/peertube-plugin-test-transcoding-two/package.json
new file mode 100644
index 000000000..34be0454b
--- /dev/null
+++ b/server/tests/fixtures/peertube-plugin-test-transcoding-two/package.json
@@ -0,0 +1,20 @@
1{
2 "name": "peertube-plugin-test-transcoding-two",
3 "version": "0.0.1",
4 "description": "Plugin test transcoding 2",
5 "engine": {
6 "peertube": ">=1.3.0"
7 },
8 "keywords": [
9 "peertube",
10 "plugin"
11 ],
12 "homepage": "https://github.com/Chocobozzz/PeerTube",
13 "author": "Chocobozzz",
14 "bugs": "https://github.com/Chocobozzz/PeerTube/issues",
15 "library": "./main.js",
16 "staticDirs": {},
17 "css": [],
18 "clientScripts": [],
19 "translations": {}
20}
diff --git a/server/tests/plugins/index.ts b/server/tests/plugins/index.ts
index b870a4055..fd7116efd 100644
--- a/server/tests/plugins/index.ts
+++ b/server/tests/plugins/index.ts
@@ -1,10 +1,11 @@
1import './action-hooks' 1import './action-hooks'
2import './html-injection'
3import './id-and-pass-auth'
4import './external-auth' 2import './external-auth'
5import './filter-hooks' 3import './filter-hooks'
6import './translations' 4import './html-injection'
7import './video-constants' 5import './id-and-pass-auth'
8import './plugin-helpers' 6import './plugin-helpers'
9import './plugin-router' 7import './plugin-router'
10import './plugin-storage' 8import './plugin-storage'
9import './plugin-transcoding'
10import './translations'
11import './video-constants'
diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts
new file mode 100644
index 000000000..96ff4c2fe
--- /dev/null
+++ b/server/tests/plugins/plugin-transcoding.ts
@@ -0,0 +1,226 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import { expect } from 'chai'
5import { join } from 'path'
6import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils'
7import { ServerConfig, VideoDetails, VideoPrivacy } from '@shared/models'
8import {
9 buildServerDirectory,
10 createLive,
11 getConfig,
12 getPluginTestPath,
13 getVideo,
14 installPlugin,
15 sendRTMPStreamInVideo,
16 setAccessTokensToServers,
17 setDefaultVideoChannel,
18 uninstallPlugin,
19 updateCustomSubConfig,
20 uploadVideoAndGetId,
21 waitJobs,
22 waitUntilLivePublished
23} from '../../../shared/extra-utils'
24import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
25
26async function createLiveWrapper (server: ServerInfo) {
27 const liveAttributes = {
28 name: 'live video',
29 channelId: server.videoChannel.id,
30 privacy: VideoPrivacy.PUBLIC
31 }
32
33 const res = await createLive(server.url, server.accessToken, liveAttributes)
34 return res.body.video.uuid
35}
36
37function updateConf (server: ServerInfo, vodProfile: string, liveProfile: string) {
38 return updateCustomSubConfig(server.url, server.accessToken, {
39 transcoding: {
40 enabled: true,
41 profile: vodProfile,
42 hls: {
43 enabled: true
44 },
45 webtorrent: {
46 enabled: true
47 }
48 },
49 live: {
50 transcoding: {
51 profile: liveProfile,
52 enabled: true
53 }
54 }
55 })
56}
57
58describe('Test transcoding plugins', function () {
59 let server: ServerInfo
60
61 before(async function () {
62 this.timeout(60000)
63
64 server = await flushAndRunServer(1)
65 await setAccessTokensToServers([ server ])
66 await setDefaultVideoChannel([ server ])
67
68 await updateConf(server, 'default', 'default')
69 })
70
71 describe('When using a plugin adding profiles to existing encoders', function () {
72
73 async function checkVideoFPS (uuid: string, type: 'above' | 'below', fps: number) {
74 const res = await getVideo(server.url, uuid)
75 const video = res.body as VideoDetails
76 const files = video.files.concat(...video.streamingPlaylists.map(p => p.files))
77
78 for (const file of files) {
79 if (type === 'above') {
80 expect(file.fps).to.be.above(fps)
81 } else {
82 expect(file.fps).to.be.below(fps)
83 }
84 }
85 }
86
87 async function checkLiveFPS (uuid: string, type: 'above' | 'below', fps: number) {
88 const playlistUrl = `${server.url}/static/streaming-playlists/hls/${uuid}/0.m3u8`
89 const videoFPS = await getVideoFileFPS(playlistUrl)
90
91 if (type === 'above') {
92 expect(videoFPS).to.be.above(fps)
93 } else {
94 expect(videoFPS).to.be.below(fps)
95 }
96 }
97
98 before(async function () {
99 await installPlugin({
100 url: server.url,
101 accessToken: server.accessToken,
102 path: getPluginTestPath('-transcoding-one')
103 })
104 })
105
106 it('Should have the appropriate available profiles', async function () {
107 const res = await getConfig(server.url)
108 const config = res.body as ServerConfig
109
110 expect(config.transcoding.availableProfiles).to.have.members([ 'default', 'low-vod' ])
111 expect(config.live.transcoding.availableProfiles).to.have.members([ 'default', 'low-live' ])
112 })
113
114 it('Should not use the plugin profile if not chosen by the admin', async function () {
115 this.timeout(120000)
116
117 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid
118 await waitJobs([ server ])
119
120 await checkVideoFPS(videoUUID, 'above', 20)
121 })
122
123 it('Should use the vod profile', async function () {
124 this.timeout(120000)
125
126 await updateConf(server, 'low-vod', 'default')
127
128 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid
129 await waitJobs([ server ])
130
131 await checkVideoFPS(videoUUID, 'below', 12)
132 })
133
134 it('Should not use the plugin profile if not chosen by the admin', async function () {
135 this.timeout(120000)
136
137 const liveVideoId = await createLiveWrapper(server)
138
139 await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm')
140 await waitUntilLivePublished(server.url, server.accessToken, liveVideoId)
141 await waitJobs([ server ])
142
143 await checkLiveFPS(liveVideoId, 'above', 20)
144 })
145
146 it('Should use the live profile', async function () {
147 this.timeout(120000)
148
149 await updateConf(server, 'low-vod', 'low-live')
150
151 const liveVideoId = await createLiveWrapper(server)
152
153 await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm')
154 await waitUntilLivePublished(server.url, server.accessToken, liveVideoId)
155 await waitJobs([ server ])
156
157 await checkLiveFPS(liveVideoId, 'below', 12)
158 })
159
160 it('Should default to the default profile if the specified profile does not exist', async function () {
161 this.timeout(120000)
162
163 await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-transcoding-one' })
164
165 const res = await getConfig(server.url)
166 const config = res.body as ServerConfig
167
168 expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ])
169 expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ])
170
171 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid
172 await waitJobs([ server ])
173
174 await checkVideoFPS(videoUUID, 'above', 20)
175 })
176
177 })
178
179 describe('When using a plugin adding new encoders', function () {
180
181 before(async function () {
182 await installPlugin({
183 url: server.url,
184 accessToken: server.accessToken,
185 path: getPluginTestPath('-transcoding-two')
186 })
187
188 await updateConf(server, 'test-vod-profile', 'test-live-profile')
189 })
190
191 it('Should use the new vod encoders', async function () {
192 this.timeout(240000)
193
194 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid
195 await waitJobs([ server ])
196
197 const path = buildServerDirectory(server, join('videos', videoUUID + '-720.mp4'))
198 const audioProbe = await getAudioStream(path)
199 expect(audioProbe.audioStream.codec_name).to.equal('opus')
200
201 const videoProbe = await getVideoStreamFromFile(path)
202 expect(videoProbe.codec_name).to.equal('vp9')
203 })
204
205 it('Should use the new live encoders', async function () {
206 this.timeout(120000)
207
208 const liveVideoId = await createLiveWrapper(server)
209
210 await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm')
211 await waitUntilLivePublished(server.url, server.accessToken, liveVideoId)
212 await waitJobs([ server ])
213
214 const playlistUrl = `${server.url}/static/streaming-playlists/hls/${liveVideoId}/0.m3u8`
215 const audioProbe = await getAudioStream(playlistUrl)
216 expect(audioProbe.audioStream.codec_name).to.equal('opus')
217
218 const videoProbe = await getVideoStreamFromFile(playlistUrl)
219 expect(videoProbe.codec_name).to.equal('h264')
220 })
221 })
222
223 after(async function () {
224 await cleanupTests([ server ])
225 })
226})