diff options
Diffstat (limited to 'server/tests/plugins/plugin-transcoding.ts')
-rw-r--r-- | server/tests/plugins/plugin-transcoding.ts | 256 |
1 files changed, 122 insertions, 134 deletions
diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts index eefb2294d..c14c34c7e 100644 --- a/server/tests/plugins/plugin-transcoding.ts +++ b/server/tests/plugins/plugin-transcoding.ts | |||
@@ -4,77 +4,72 @@ import 'mocha' | |||
4 | import { expect } from 'chai' | 4 | import { expect } from 'chai' |
5 | import { join } from 'path' | 5 | import { join } from 'path' |
6 | import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' | 6 | import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' |
7 | import { ServerConfig, VideoDetails, VideoPrivacy } from '@shared/models' | ||
8 | import { | 7 | import { |
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, | 17 | import { VideoPrivacy } from '@shared/models' |
22 | waitJobs, | 18 | |
23 | waitUntilLivePublished | 19 | async function createLiveWrapper (server: PeerTubeServer) { |
24 | } from '../../../shared/extra-utils' | ||
25 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' | ||
26 | |||
27 | async 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 | ||
38 | function updateConf (server: ServerInfo, vodProfile: string, liveProfile: string) { | 31 | function 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 | ||
71 | describe('Test transcoding plugins', function () { | 66 | describe('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,134 +103,132 @@ 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', 'high-live', 'input-options-live', 'bad-scale-live' ]) |
125 | }) | 114 | }) |
126 | 115 | ||
127 | it('Should not use the plugin profile if not chosen by the admin', async function () { | 116 | describe('VOD', function () { |
128 | this.timeout(240000) | ||
129 | 117 | ||
130 | const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid | 118 | it('Should not use the plugin profile if not chosen by the admin', async function () { |
131 | await waitJobs([ server ]) | 119 | this.timeout(240000) |
132 | 120 | ||
133 | await checkVideoFPS(videoUUID, 'above', 20) | 121 | const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid |
134 | }) | 122 | await waitJobs([ server ]) |
135 | 123 | ||
136 | it('Should use the vod profile', async function () { | 124 | await checkVideoFPS(videoUUID, 'above', 20) |
137 | this.timeout(240000) | 125 | }) |
138 | 126 | ||
139 | await updateConf(server, 'low-vod', 'default') | 127 | it('Should use the vod profile', async function () { |
128 | this.timeout(240000) | ||
140 | 129 | ||
141 | const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid | 130 | await updateConf(server, 'low-vod', 'default') |
142 | await waitJobs([ server ]) | ||
143 | 131 | ||
144 | await checkVideoFPS(videoUUID, 'below', 12) | 132 | const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid |
145 | }) | 133 | await waitJobs([ server ]) |
146 | 134 | ||
147 | it('Should apply input options in vod profile', async function () { | 135 | await checkVideoFPS(videoUUID, 'below', 12) |
148 | this.timeout(240000) | 136 | }) |
149 | 137 | ||
150 | await updateConf(server, 'input-options-vod', 'default') | 138 | it('Should apply input options in vod profile', async function () { |
139 | this.timeout(240000) | ||
151 | 140 | ||
152 | const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid | 141 | await updateConf(server, 'input-options-vod', 'default') |
153 | await waitJobs([ server ]) | ||
154 | 142 | ||
155 | await checkVideoFPS(videoUUID, 'below', 6) | 143 | const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid |
156 | }) | 144 | await waitJobs([ server ]) |
157 | 145 | ||
158 | it('Should apply the scale filter in vod profile', async function () { | 146 | await checkVideoFPS(videoUUID, 'below', 6) |
159 | this.timeout(240000) | 147 | }) |
160 | 148 | ||
161 | await updateConf(server, 'bad-scale-vod', 'default') | 149 | it('Should apply the scale filter in vod profile', async function () { |
150 | this.timeout(240000) | ||
162 | 151 | ||
163 | const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid | 152 | await updateConf(server, 'bad-scale-vod', 'default') |
164 | await waitJobs([ server ]) | ||
165 | 153 | ||
166 | // Transcoding failed | 154 | const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid |
167 | const res = await getVideo(server.url, videoUUID) | 155 | await waitJobs([ server ]) |
168 | const video: VideoDetails = res.body | ||
169 | 156 | ||
170 | expect(video.files).to.have.lengthOf(1) | 157 | // Transcoding failed |
171 | expect(video.streamingPlaylists).to.have.lengthOf(0) | 158 | const video = await server.videos.get({ id: videoUUID }) |
159 | expect(video.files).to.have.lengthOf(1) | ||
160 | expect(video.streamingPlaylists).to.have.lengthOf(0) | ||
161 | }) | ||
172 | }) | 162 | }) |
173 | 163 | ||
174 | it('Should not use the plugin profile if not chosen by the admin', async function () { | 164 | describe('Live', function () { |
175 | this.timeout(240000) | ||
176 | 165 | ||
177 | const liveVideoId = await createLiveWrapper(server) | 166 | it('Should not use the plugin profile if not chosen by the admin', async function () { |
167 | this.timeout(240000) | ||
178 | 168 | ||
179 | await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') | 169 | const liveVideoId = await createLiveWrapper(server) |
180 | await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) | ||
181 | await waitJobs([ server ]) | ||
182 | 170 | ||
183 | await checkLiveFPS(liveVideoId, 'above', 20) | 171 | await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_very_short_240p.mp4' }) |
184 | }) | 172 | await server.live.waitUntilPublished({ videoId: liveVideoId }) |
173 | await waitJobs([ server ]) | ||
185 | 174 | ||
186 | it('Should use the live profile', async function () { | 175 | await checkLiveFPS(liveVideoId, 'above', 20) |
187 | this.timeout(240000) | 176 | }) |
188 | 177 | ||
189 | await updateConf(server, 'low-vod', 'low-live') | 178 | it('Should use the live profile', async function () { |
179 | this.timeout(240000) | ||
190 | 180 | ||
191 | const liveVideoId = await createLiveWrapper(server) | 181 | await updateConf(server, 'low-vod', 'high-live') |
192 | 182 | ||
193 | await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') | 183 | const liveVideoId = await createLiveWrapper(server) |
194 | await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) | ||
195 | await waitJobs([ server ]) | ||
196 | 184 | ||
197 | await checkLiveFPS(liveVideoId, 'below', 12) | 185 | await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_very_short_240p.mp4' }) |
198 | }) | 186 | await server.live.waitUntilPublished({ videoId: liveVideoId }) |
187 | await waitJobs([ server ]) | ||
199 | 188 | ||
200 | it('Should apply the input options on live profile', async function () { | 189 | await checkLiveFPS(liveVideoId, 'above', 45) |
201 | this.timeout(240000) | 190 | }) |
202 | 191 | ||
203 | await updateConf(server, 'low-vod', 'input-options-live') | 192 | it('Should apply the input options on live profile', async function () { |
193 | this.timeout(240000) | ||
204 | 194 | ||
205 | const liveVideoId = await createLiveWrapper(server) | 195 | await updateConf(server, 'low-vod', 'input-options-live') |
206 | 196 | ||
207 | await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') | 197 | const liveVideoId = await createLiveWrapper(server) |
208 | await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) | ||
209 | await waitJobs([ server ]) | ||
210 | 198 | ||
211 | await checkLiveFPS(liveVideoId, 'below', 6) | 199 | await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_very_short_240p.mp4' }) |
212 | }) | 200 | await server.live.waitUntilPublished({ videoId: liveVideoId }) |
201 | await waitJobs([ server ]) | ||
213 | 202 | ||
214 | it('Should apply the scale filter name on live profile', async function () { | 203 | await checkLiveFPS(liveVideoId, 'above', 45) |
215 | this.timeout(240000) | 204 | }) |
216 | 205 | ||
217 | await updateConf(server, 'low-vod', 'bad-scale-live') | 206 | it('Should apply the scale filter name on live profile', async function () { |
207 | this.timeout(240000) | ||
218 | 208 | ||
219 | const liveVideoId = await createLiveWrapper(server) | 209 | await updateConf(server, 'low-vod', 'bad-scale-live') |
220 | 210 | ||
221 | const command = await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') | 211 | const liveVideoId = await createLiveWrapper(server) |
222 | await testFfmpegStreamError(command, true) | ||
223 | }) | ||
224 | 212 | ||
225 | it('Should default to the default profile if the specified profile does not exist', async function () { | 213 | const command = await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_very_short_240p.mp4' }) |
226 | this.timeout(240000) | 214 | await testFfmpegStreamError(command, true) |
215 | }) | ||
227 | 216 | ||
228 | await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-transcoding-one' }) | 217 | it('Should default to the default profile if the specified profile does not exist', async function () { |
218 | this.timeout(240000) | ||
229 | 219 | ||
230 | const res = await getConfig(server.url) | 220 | await server.plugins.uninstall({ npmName: 'peertube-plugin-test-transcoding-one' }) |
231 | const config = res.body as ServerConfig | ||
232 | 221 | ||
233 | expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ]) | 222 | const config = await server.config.getConfig() |
234 | expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ]) | ||
235 | 223 | ||
236 | const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid | 224 | expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ]) |
237 | await waitJobs([ server ]) | 225 | expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ]) |
226 | |||
227 | const videoUUID = (await server.videos.quickUpload({ name: 'video', fixture: 'video_very_short_240p.mp4' })).uuid | ||
228 | await waitJobs([ server ]) | ||
238 | 229 | ||
239 | await checkVideoFPS(videoUUID, 'above', 20) | 230 | await checkVideoFPS(videoUUID, 'above', 20) |
231 | }) | ||
240 | }) | 232 | }) |
241 | 233 | ||
242 | }) | 234 | }) |
@@ -244,11 +236,7 @@ describe('Test transcoding plugins', function () { | |||
244 | describe('When using a plugin adding new encoders', function () { | 236 | describe('When using a plugin adding new encoders', function () { |
245 | 237 | ||
246 | before(async function () { | 238 | before(async function () { |
247 | await installPlugin({ | 239 | await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-transcoding-two') }) |
248 | url: server.url, | ||
249 | accessToken: server.accessToken, | ||
250 | path: getPluginTestPath('-transcoding-two') | ||
251 | }) | ||
252 | 240 | ||
253 | await updateConf(server, 'test-vod-profile', 'test-live-profile') | 241 | await updateConf(server, 'test-vod-profile', 'test-live-profile') |
254 | }) | 242 | }) |
@@ -256,10 +244,10 @@ describe('Test transcoding plugins', function () { | |||
256 | it('Should use the new vod encoders', async function () { | 244 | it('Should use the new vod encoders', async function () { |
257 | this.timeout(240000) | 245 | this.timeout(240000) |
258 | 246 | ||
259 | const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video', fixture: 'video_short_240p.mp4' })).uuid | 247 | const videoUUID = (await server.videos.quickUpload({ name: 'video', fixture: 'video_very_short_240p.mp4' })).uuid |
260 | await waitJobs([ server ]) | 248 | await waitJobs([ server ]) |
261 | 249 | ||
262 | const path = buildServerDirectory(server, join('videos', videoUUID + '-240.mp4')) | 250 | const path = server.servers.buildDirectory(join('videos', videoUUID + '-240.mp4')) |
263 | const audioProbe = await getAudioStream(path) | 251 | const audioProbe = await getAudioStream(path) |
264 | expect(audioProbe.audioStream.codec_name).to.equal('opus') | 252 | expect(audioProbe.audioStream.codec_name).to.equal('opus') |
265 | 253 | ||
@@ -272,8 +260,8 @@ describe('Test transcoding plugins', function () { | |||
272 | 260 | ||
273 | const liveVideoId = await createLiveWrapper(server) | 261 | const liveVideoId = await createLiveWrapper(server) |
274 | 262 | ||
275 | await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') | 263 | await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) |
276 | await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) | 264 | await server.live.waitUntilPublished({ videoId: liveVideoId }) |
277 | await waitJobs([ server ]) | 265 | await waitJobs([ server ]) |
278 | 266 | ||
279 | const playlistUrl = `${server.url}/static/streaming-playlists/hls/${liveVideoId}/0.m3u8` | 267 | const playlistUrl = `${server.url}/static/streaming-playlists/hls/${liveVideoId}/0.m3u8` |