aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins/plugin-transcoding.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/plugins/plugin-transcoding.ts')
-rw-r--r--server/tests/plugins/plugin-transcoding.ts138
1 files changed, 60 insertions, 78 deletions
diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts
index eefb2294d..0bf1fab01 100644
--- a/server/tests/plugins/plugin-transcoding.ts
+++ b/server/tests/plugins/plugin-transcoding.ts
@@ -4,77 +4,72 @@ import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { join } from 'path' 5import { join } from 'path'
6import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' 6import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils'
7import { ServerConfig, VideoDetails, VideoPrivacy } from '@shared/models'
8import { 7import {
9 buildServerDirectory, 8 cleanupTests,
10 createLive, 9 createSingleServer,
11 getConfig, 10 PeerTubeServer,
12 getPluginTestPath, 11 PluginsCommand,
13 getVideo,
14 installPlugin,
15 sendRTMPStreamInVideo,
16 setAccessTokensToServers, 12 setAccessTokensToServers,
17 setDefaultVideoChannel, 13 setDefaultVideoChannel,
18 testFfmpegStreamError, 14 testFfmpegStreamError,
19 uninstallPlugin, 15 waitJobs
20 updateCustomSubConfig, 16} from '@shared/extra-utils'
21 uploadVideoAndGetId, 17import { VideoPrivacy } from '@shared/models'
22 waitJobs, 18
23 waitUntilLivePublished 19async function createLiveWrapper (server: PeerTubeServer) {
24} from '../../../shared/extra-utils'
25import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
26
27async function createLiveWrapper (server: ServerInfo) {
28 const liveAttributes = { 20 const liveAttributes = {
29 name: 'live video', 21 name: 'live video',
30 channelId: server.videoChannel.id, 22 channelId: server.store.channel.id,
31 privacy: VideoPrivacy.PUBLIC 23 privacy: VideoPrivacy.PUBLIC
32 } 24 }
33 25
34 const res = await createLive(server.url, server.accessToken, liveAttributes) 26 const { uuid } = await server.live.create({ fields: liveAttributes })
35 return res.body.video.uuid 27
28 return uuid
36} 29}
37 30
38function updateConf (server: ServerInfo, vodProfile: string, liveProfile: string) { 31function updateConf (server: PeerTubeServer, vodProfile: string, liveProfile: string) {
39 return updateCustomSubConfig(server.url, server.accessToken, { 32 return server.config.updateCustomSubConfig({
40 transcoding: { 33 newConfig: {
41 enabled: true,
42 profile: vodProfile,
43 hls: {
44 enabled: true
45 },
46 webtorrent: {
47 enabled: true
48 },
49 resolutions: {
50 '240p': true,
51 '360p': false,
52 '480p': false,
53 '720p': true
54 }
55 },
56 live: {
57 transcoding: { 34 transcoding: {
58 profile: liveProfile,
59 enabled: true, 35 enabled: true,
36 profile: vodProfile,
37 hls: {
38 enabled: true
39 },
40 webtorrent: {
41 enabled: true
42 },
60 resolutions: { 43 resolutions: {
61 '240p': true, 44 '240p': true,
62 '360p': false, 45 '360p': false,
63 '480p': false, 46 '480p': false,
64 '720p': true 47 '720p': true
65 } 48 }
49 },
50 live: {
51 transcoding: {
52 profile: liveProfile,
53 enabled: true,
54 resolutions: {
55 '240p': true,
56 '360p': false,
57 '480p': false,
58 '720p': true
59 }
60 }
66 } 61 }
67 } 62 }
68 }) 63 })
69} 64}
70 65
71describe('Test transcoding plugins', function () { 66describe('Test transcoding plugins', function () {
72 let server: ServerInfo 67 let server: PeerTubeServer
73 68
74 before(async function () { 69 before(async function () {
75 this.timeout(60000) 70 this.timeout(60000)
76 71
77 server = await flushAndRunServer(1) 72 server = await createSingleServer(1)
78 await setAccessTokensToServers([ server ]) 73 await setAccessTokensToServers([ server ])
79 await setDefaultVideoChannel([ server ]) 74 await setDefaultVideoChannel([ server ])
80 75
@@ -84,8 +79,7 @@ describe('Test transcoding plugins', function () {
84 describe('When using a plugin adding profiles to existing encoders', function () { 79 describe('When using a plugin adding profiles to existing encoders', function () {
85 80
86 async function checkVideoFPS (uuid: string, type: 'above' | 'below', fps: number) { 81 async function checkVideoFPS (uuid: string, type: 'above' | 'below', fps: number) {
87 const res = await getVideo(server.url, uuid) 82 const video = await server.videos.get({ id: uuid })
88 const video = res.body as VideoDetails
89 const files = video.files.concat(...video.streamingPlaylists.map(p => p.files)) 83 const files = video.files.concat(...video.streamingPlaylists.map(p => p.files))
90 84
91 for (const file of files) { 85 for (const file of files) {
@@ -109,16 +103,11 @@ describe('Test transcoding plugins', function () {
109 } 103 }
110 104
111 before(async function () { 105 before(async function () {
112 await installPlugin({ 106 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-transcoding-one') })
113 url: server.url,
114 accessToken: server.accessToken,
115 path: getPluginTestPath('-transcoding-one')
116 })
117 }) 107 })
118 108
119 it('Should have the appropriate available profiles', async function () { 109 it('Should have the appropriate available profiles', async function () {
120 const res = await getConfig(server.url) 110 const config = await server.config.getConfig()
121 const config = res.body as ServerConfig
122 111
123 expect(config.transcoding.availableProfiles).to.have.members([ 'default', 'low-vod', 'input-options-vod', 'bad-scale-vod' ]) 112 expect(config.transcoding.availableProfiles).to.have.members([ 'default', 'low-vod', 'input-options-vod', 'bad-scale-vod' ])
124 expect(config.live.transcoding.availableProfiles).to.have.members([ 'default', 'low-live', 'input-options-live', 'bad-scale-live' ]) 113 expect(config.live.transcoding.availableProfiles).to.have.members([ 'default', 'low-live', 'input-options-live', 'bad-scale-live' ])
@@ -127,7 +116,7 @@ describe('Test transcoding plugins', function () {
127 it('Should not use the plugin profile if not chosen by the admin', async function () { 116 it('Should not use the plugin profile if not chosen by the admin', async function () {
128 this.timeout(240000) 117 this.timeout(240000)
129 118
130 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid 119 const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
131 await waitJobs([ server ]) 120 await waitJobs([ server ])
132 121
133 await checkVideoFPS(videoUUID, 'above', 20) 122 await checkVideoFPS(videoUUID, 'above', 20)
@@ -138,7 +127,7 @@ describe('Test transcoding plugins', function () {
138 127
139 await updateConf(server, 'low-vod', 'default') 128 await updateConf(server, 'low-vod', 'default')
140 129
141 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid 130 const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
142 await waitJobs([ server ]) 131 await waitJobs([ server ])
143 132
144 await checkVideoFPS(videoUUID, 'below', 12) 133 await checkVideoFPS(videoUUID, 'below', 12)
@@ -149,7 +138,7 @@ describe('Test transcoding plugins', function () {
149 138
150 await updateConf(server, 'input-options-vod', 'default') 139 await updateConf(server, 'input-options-vod', 'default')
151 140
152 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid 141 const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
153 await waitJobs([ server ]) 142 await waitJobs([ server ])
154 143
155 await checkVideoFPS(videoUUID, 'below', 6) 144 await checkVideoFPS(videoUUID, 'below', 6)
@@ -160,13 +149,11 @@ describe('Test transcoding plugins', function () {
160 149
161 await updateConf(server, 'bad-scale-vod', 'default') 150 await updateConf(server, 'bad-scale-vod', 'default')
162 151
163 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid 152 const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
164 await waitJobs([ server ]) 153 await waitJobs([ server ])
165 154
166 // Transcoding failed 155 // Transcoding failed
167 const res = await getVideo(server.url, videoUUID) 156 const video = await server.videos.get({ id: videoUUID })
168 const video: VideoDetails = res.body
169
170 expect(video.files).to.have.lengthOf(1) 157 expect(video.files).to.have.lengthOf(1)
171 expect(video.streamingPlaylists).to.have.lengthOf(0) 158 expect(video.streamingPlaylists).to.have.lengthOf(0)
172 }) 159 })
@@ -176,8 +163,8 @@ describe('Test transcoding plugins', function () {
176 163
177 const liveVideoId = await createLiveWrapper(server) 164 const liveVideoId = await createLiveWrapper(server)
178 165
179 await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') 166 await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' })
180 await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) 167 await server.live.waitUntilPublished({ videoId: liveVideoId })
181 await waitJobs([ server ]) 168 await waitJobs([ server ])
182 169
183 await checkLiveFPS(liveVideoId, 'above', 20) 170 await checkLiveFPS(liveVideoId, 'above', 20)
@@ -190,8 +177,8 @@ describe('Test transcoding plugins', function () {
190 177
191 const liveVideoId = await createLiveWrapper(server) 178 const liveVideoId = await createLiveWrapper(server)
192 179
193 await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') 180 await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' })
194 await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) 181 await server.live.waitUntilPublished({ videoId: liveVideoId })
195 await waitJobs([ server ]) 182 await waitJobs([ server ])
196 183
197 await checkLiveFPS(liveVideoId, 'below', 12) 184 await checkLiveFPS(liveVideoId, 'below', 12)
@@ -204,8 +191,8 @@ describe('Test transcoding plugins', function () {
204 191
205 const liveVideoId = await createLiveWrapper(server) 192 const liveVideoId = await createLiveWrapper(server)
206 193
207 await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') 194 await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' })
208 await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) 195 await server.live.waitUntilPublished({ videoId: liveVideoId })
209 await waitJobs([ server ]) 196 await waitJobs([ server ])
210 197
211 await checkLiveFPS(liveVideoId, 'below', 6) 198 await checkLiveFPS(liveVideoId, 'below', 6)
@@ -218,22 +205,21 @@ describe('Test transcoding plugins', function () {
218 205
219 const liveVideoId = await createLiveWrapper(server) 206 const liveVideoId = await createLiveWrapper(server)
220 207
221 const command = await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') 208 const command = await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' })
222 await testFfmpegStreamError(command, true) 209 await testFfmpegStreamError(command, true)
223 }) 210 })
224 211
225 it('Should default to the default profile if the specified profile does not exist', async function () { 212 it('Should default to the default profile if the specified profile does not exist', async function () {
226 this.timeout(240000) 213 this.timeout(240000)
227 214
228 await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-transcoding-one' }) 215 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-transcoding-one' })
229 216
230 const res = await getConfig(server.url) 217 const config = await server.config.getConfig()
231 const config = res.body as ServerConfig
232 218
233 expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ]) 219 expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ])
234 expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ]) 220 expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ])
235 221
236 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid 222 const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
237 await waitJobs([ server ]) 223 await waitJobs([ server ])
238 224
239 await checkVideoFPS(videoUUID, 'above', 20) 225 await checkVideoFPS(videoUUID, 'above', 20)
@@ -244,11 +230,7 @@ describe('Test transcoding plugins', function () {
244 describe('When using a plugin adding new encoders', function () { 230 describe('When using a plugin adding new encoders', function () {
245 231
246 before(async function () { 232 before(async function () {
247 await installPlugin({ 233 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-transcoding-two') })
248 url: server.url,
249 accessToken: server.accessToken,
250 path: getPluginTestPath('-transcoding-two')
251 })
252 234
253 await updateConf(server, 'test-vod-profile', 'test-live-profile') 235 await updateConf(server, 'test-vod-profile', 'test-live-profile')
254 }) 236 })
@@ -256,10 +238,10 @@ describe('Test transcoding plugins', function () {
256 it('Should use the new vod encoders', async function () { 238 it('Should use the new vod encoders', async function () {
257 this.timeout(240000) 239 this.timeout(240000)
258 240
259 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video', fixture: 'video_short_240p.mp4' })).uuid 241 const videoUUID = (await server.videos.quickUpload({ name: 'video', fixture: 'video_short_240p.mp4' })).uuid
260 await waitJobs([ server ]) 242 await waitJobs([ server ])
261 243
262 const path = buildServerDirectory(server, join('videos', videoUUID + '-240.mp4')) 244 const path = server.servers.buildDirectory(join('videos', videoUUID + '-240.mp4'))
263 const audioProbe = await getAudioStream(path) 245 const audioProbe = await getAudioStream(path)
264 expect(audioProbe.audioStream.codec_name).to.equal('opus') 246 expect(audioProbe.audioStream.codec_name).to.equal('opus')
265 247
@@ -272,8 +254,8 @@ describe('Test transcoding plugins', function () {
272 254
273 const liveVideoId = await createLiveWrapper(server) 255 const liveVideoId = await createLiveWrapper(server)
274 256
275 await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') 257 await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' })
276 await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) 258 await server.live.waitUntilPublished({ videoId: liveVideoId })
277 await waitJobs([ server ]) 259 await waitJobs([ server ])
278 260
279 const playlistUrl = `${server.url}/static/streaming-playlists/hls/${liveVideoId}/0.m3u8` 261 const playlistUrl = `${server.url}/static/streaming-playlists/hls/${liveVideoId}/0.m3u8`