]>
Commit | Line | Data |
---|---|---|
af4ae64f C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
86347717 | 3 | import { expect } from 'chai' |
764b1a14 | 4 | import { basename, join } from 'path' |
d102de1b | 5 | import { SQLCommand, testImage, testLiveVideoResolutions } from '@server/tests/shared' |
367a9dc6 | 6 | import { getAllFiles, wait } from '@shared/core-utils' |
d102de1b | 7 | import { ffprobePromise, getVideoStream } from '@shared/ffmpeg' |
c55e3d72 C |
8 | import { |
9 | HttpStatusCode, | |
10 | LiveVideo, | |
11 | LiveVideoCreate, | |
f443a746 | 12 | LiveVideoLatencyMode, |
c55e3d72 C |
13 | VideoDetails, |
14 | VideoPrivacy, | |
15 | VideoState, | |
16 | VideoStreamingPlaylistType | |
17 | } from '@shared/models' | |
af4ae64f | 18 | import { |
af4ae64f | 19 | cleanupTests, |
254d3579 | 20 | createMultipleServers, |
4c7e60bc | 21 | doubleFollow, |
5c0904fc | 22 | killallServers, |
4f219914 | 23 | LiveCommand, |
3545e72c | 24 | makeGetRequest, |
af4ae64f | 25 | makeRawRequest, |
254d3579 | 26 | PeerTubeServer, |
4c7e60bc | 27 | sendRTMPStream, |
af4ae64f C |
28 | setAccessTokensToServers, |
29 | setDefaultVideoChannel, | |
bd54ad19 | 30 | stopFfmpeg, |
97969c4e | 31 | testFfmpegStreamError, |
bd54ad19 | 32 | waitJobs, |
4f219914 | 33 | waitUntilLivePublishedOnAllServers |
bf54587a | 34 | } from '@shared/server-commands' |
af4ae64f | 35 | |
af4ae64f | 36 | describe('Test live', function () { |
254d3579 | 37 | let servers: PeerTubeServer[] = [] |
4f219914 | 38 | let commands: LiveCommand[] |
af4ae64f C |
39 | |
40 | before(async function () { | |
41 | this.timeout(120000) | |
42 | ||
254d3579 | 43 | servers = await createMultipleServers(2) |
af4ae64f C |
44 | |
45 | // Get the access tokens | |
46 | await setAccessTokensToServers(servers) | |
47 | await setDefaultVideoChannel(servers) | |
48 | ||
89d241a7 | 49 | await servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
50 | newConfig: { |
51 | live: { | |
52 | enabled: true, | |
53 | allowReplay: true, | |
f443a746 C |
54 | latencySetting: { |
55 | enabled: true | |
56 | }, | |
65e6e260 C |
57 | transcoding: { |
58 | enabled: false | |
59 | } | |
68e70a74 | 60 | } |
af4ae64f C |
61 | } |
62 | }) | |
63 | ||
64 | // Server 1 and server 2 follow each other | |
65 | await doubleFollow(servers[0], servers[1]) | |
4f219914 | 66 | |
89d241a7 | 67 | commands = servers.map(s => s.live) |
af4ae64f C |
68 | }) |
69 | ||
70 | describe('Live creation, update and delete', function () { | |
68e70a74 | 71 | let liveVideoUUID: string |
af4ae64f C |
72 | |
73 | it('Should create a live with the appropriate parameters', async function () { | |
74 | this.timeout(20000) | |
75 | ||
76 | const attributes: LiveVideoCreate = { | |
77 | category: 1, | |
78 | licence: 2, | |
79 | language: 'fr', | |
80 | description: 'super live description', | |
81 | support: 'support field', | |
89d241a7 | 82 | channelId: servers[0].store.channel.id, |
af4ae64f C |
83 | nsfw: false, |
84 | waitTranscoding: false, | |
85 | name: 'my super live', | |
86 | tags: [ 'tag1', 'tag2' ], | |
87 | commentsEnabled: false, | |
88 | downloadEnabled: false, | |
89 | saveReplay: true, | |
05a60d85 | 90 | replaySettings: { privacy: VideoPrivacy.PUBLIC }, |
f443a746 | 91 | latencyMode: LiveVideoLatencyMode.SMALL_LATENCY, |
af4ae64f C |
92 | privacy: VideoPrivacy.PUBLIC, |
93 | previewfile: 'video_short1-preview.webm.jpg', | |
94 | thumbnailfile: 'video_short1.webm.jpg' | |
95 | } | |
96 | ||
04aed767 | 97 | const live = await commands[0].create({ fields: attributes }) |
4f219914 | 98 | liveVideoUUID = live.uuid |
af4ae64f C |
99 | |
100 | await waitJobs(servers) | |
101 | ||
102 | for (const server of servers) { | |
89d241a7 | 103 | const video = await server.videos.get({ id: liveVideoUUID }) |
af4ae64f C |
104 | |
105 | expect(video.category.id).to.equal(1) | |
106 | expect(video.licence.id).to.equal(2) | |
107 | expect(video.language.id).to.equal('fr') | |
108 | expect(video.description).to.equal('super live description') | |
109 | expect(video.support).to.equal('support field') | |
110 | ||
89d241a7 C |
111 | expect(video.channel.name).to.equal(servers[0].store.channel.name) |
112 | expect(video.channel.host).to.equal(servers[0].store.channel.host) | |
af4ae64f | 113 | |
1ab60243 C |
114 | expect(video.isLive).to.be.true |
115 | ||
af4ae64f C |
116 | expect(video.nsfw).to.be.false |
117 | expect(video.waitTranscoding).to.be.false | |
118 | expect(video.name).to.equal('my super live') | |
119 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2' ]) | |
120 | expect(video.commentsEnabled).to.be.false | |
121 | expect(video.downloadEnabled).to.be.false | |
122 | expect(video.privacy.id).to.equal(VideoPrivacy.PUBLIC) | |
123 | ||
124 | await testImage(server.url, 'video_short1-preview.webm', video.previewPath) | |
125 | await testImage(server.url, 'video_short1.webm', video.thumbnailPath) | |
126 | ||
89d241a7 | 127 | const live = await server.live.get({ videoId: liveVideoUUID }) |
af4ae64f C |
128 | |
129 | if (server.url === servers[0].url) { | |
c655c9ef | 130 | expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live') |
af4ae64f | 131 | expect(live.streamKey).to.not.be.empty |
05a60d85 W |
132 | |
133 | expect(live.replaySettings).to.exist | |
134 | expect(live.replaySettings.privacy).to.equal(VideoPrivacy.PUBLIC) | |
af4ae64f | 135 | } else { |
5d9b867e C |
136 | expect(live.rtmpUrl).to.not.exist |
137 | expect(live.streamKey).to.not.exist | |
af4ae64f C |
138 | } |
139 | ||
140 | expect(live.saveReplay).to.be.true | |
f443a746 | 141 | expect(live.latencyMode).to.equal(LiveVideoLatencyMode.SMALL_LATENCY) |
af4ae64f C |
142 | } |
143 | }) | |
144 | ||
145 | it('Should have a default preview and thumbnail', async function () { | |
146 | this.timeout(20000) | |
147 | ||
148 | const attributes: LiveVideoCreate = { | |
149 | name: 'default live thumbnail', | |
89d241a7 | 150 | channelId: servers[0].store.channel.id, |
af4ae64f C |
151 | privacy: VideoPrivacy.UNLISTED, |
152 | nsfw: true | |
153 | } | |
154 | ||
04aed767 | 155 | const live = await commands[0].create({ fields: attributes }) |
4f219914 | 156 | const videoId = live.uuid |
af4ae64f C |
157 | |
158 | await waitJobs(servers) | |
159 | ||
160 | for (const server of servers) { | |
89d241a7 | 161 | const video = await server.videos.get({ id: videoId }) |
af4ae64f C |
162 | expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED) |
163 | expect(video.nsfw).to.be.true | |
164 | ||
3545e72c C |
165 | await makeGetRequest({ url: server.url, path: video.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 }) |
166 | await makeGetRequest({ url: server.url, path: video.previewPath, expectedStatus: HttpStatusCode.OK_200 }) | |
af4ae64f C |
167 | } |
168 | }) | |
169 | ||
170 | it('Should not have the live listed since nobody streams into', async function () { | |
171 | for (const server of servers) { | |
89d241a7 | 172 | const { total, data } = await server.videos.list() |
af4ae64f | 173 | |
d23dd9fb C |
174 | expect(total).to.equal(0) |
175 | expect(data).to.have.lengthOf(0) | |
af4ae64f C |
176 | } |
177 | }) | |
178 | ||
179 | it('Should not be able to update a live of another server', async function () { | |
04aed767 | 180 | await commands[1].update({ videoId: liveVideoUUID, fields: { saveReplay: false }, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
af4ae64f C |
181 | }) |
182 | ||
183 | it('Should update the live', async function () { | |
184 | this.timeout(10000) | |
185 | ||
f443a746 | 186 | await commands[0].update({ videoId: liveVideoUUID, fields: { saveReplay: false, latencyMode: LiveVideoLatencyMode.DEFAULT } }) |
af4ae64f C |
187 | await waitJobs(servers) |
188 | }) | |
189 | ||
190 | it('Have the live updated', async function () { | |
191 | for (const server of servers) { | |
89d241a7 | 192 | const live = await server.live.get({ videoId: liveVideoUUID }) |
af4ae64f C |
193 | |
194 | if (server.url === servers[0].url) { | |
c655c9ef | 195 | expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live') |
af4ae64f C |
196 | expect(live.streamKey).to.not.be.empty |
197 | } else { | |
5d9b867e C |
198 | expect(live.rtmpUrl).to.not.exist |
199 | expect(live.streamKey).to.not.exist | |
af4ae64f C |
200 | } |
201 | ||
202 | expect(live.saveReplay).to.be.false | |
05a60d85 | 203 | expect(live.replaySettings).to.not.exist |
f443a746 | 204 | expect(live.latencyMode).to.equal(LiveVideoLatencyMode.DEFAULT) |
af4ae64f C |
205 | } |
206 | }) | |
207 | ||
208 | it('Delete the live', async function () { | |
209 | this.timeout(10000) | |
210 | ||
89d241a7 | 211 | await servers[0].videos.remove({ id: liveVideoUUID }) |
af4ae64f C |
212 | await waitJobs(servers) |
213 | }) | |
214 | ||
215 | it('Should have the live deleted', async function () { | |
216 | for (const server of servers) { | |
89d241a7 C |
217 | await server.videos.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
218 | await server.live.get({ videoId: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | |
af4ae64f C |
219 | } |
220 | }) | |
221 | }) | |
222 | ||
1fd61899 | 223 | describe('Live filters', function () { |
4f219914 | 224 | let ffmpegCommand: any |
1fd61899 C |
225 | let liveVideoId: string |
226 | let vodVideoId: string | |
227 | ||
228 | before(async function () { | |
3b2006bb | 229 | this.timeout(240000) |
1fd61899 | 230 | |
89d241a7 | 231 | vodVideoId = (await servers[0].videos.quickUpload({ name: 'vod video' })).uuid |
1fd61899 | 232 | |
89d241a7 | 233 | const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].store.channel.id } |
04aed767 | 234 | const live = await commands[0].create({ fields: liveOptions }) |
4f219914 | 235 | liveVideoId = live.uuid |
1fd61899 | 236 | |
89d241a7 | 237 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoId }) |
8ebf2a5d | 238 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
1fd61899 C |
239 | await waitJobs(servers) |
240 | }) | |
241 | ||
242 | it('Should only display lives', async function () { | |
89d241a7 | 243 | const { data, total } = await servers[0].videos.list({ isLive: true }) |
1fd61899 | 244 | |
d23dd9fb C |
245 | expect(total).to.equal(1) |
246 | expect(data).to.have.lengthOf(1) | |
247 | expect(data[0].name).to.equal('live') | |
1fd61899 C |
248 | }) |
249 | ||
250 | it('Should not display lives', async function () { | |
89d241a7 | 251 | const { data, total } = await servers[0].videos.list({ isLive: false }) |
1fd61899 | 252 | |
d23dd9fb C |
253 | expect(total).to.equal(1) |
254 | expect(data).to.have.lengthOf(1) | |
255 | expect(data[0].name).to.equal('vod video') | |
1fd61899 C |
256 | }) |
257 | ||
258 | it('Should display my lives', async function () { | |
259 | this.timeout(60000) | |
260 | ||
4f219914 | 261 | await stopFfmpeg(ffmpegCommand) |
1fd61899 C |
262 | await waitJobs(servers) |
263 | ||
89d241a7 | 264 | const { data } = await servers[0].videos.listMyVideos({ isLive: true }) |
1fd61899 | 265 | |
d23dd9fb | 266 | const result = data.every(v => v.isLive) |
1fd61899 C |
267 | expect(result).to.be.true |
268 | }) | |
269 | ||
270 | it('Should not display my lives', async function () { | |
89d241a7 | 271 | const { data } = await servers[0].videos.listMyVideos({ isLive: false }) |
1fd61899 | 272 | |
d23dd9fb | 273 | const result = data.every(v => !v.isLive) |
1fd61899 C |
274 | expect(result).to.be.true |
275 | }) | |
276 | ||
277 | after(async function () { | |
89d241a7 C |
278 | await servers[0].videos.remove({ id: vodVideoId }) |
279 | await servers[0].videos.remove({ id: liveVideoId }) | |
1fd61899 C |
280 | }) |
281 | }) | |
282 | ||
68e70a74 C |
283 | describe('Stream checks', function () { |
284 | let liveVideo: LiveVideo & VideoDetails | |
285 | let rtmpUrl: string | |
286 | ||
287 | before(function () { | |
c655c9ef | 288 | rtmpUrl = 'rtmp://' + servers[0].hostname + ':' + servers[0].rtmpPort + '' |
68e70a74 | 289 | }) |
af4ae64f | 290 | |
68e70a74 | 291 | async function createLiveWrapper () { |
97969c4e C |
292 | const liveAttributes = { |
293 | name: 'user live', | |
89d241a7 | 294 | channelId: servers[0].store.channel.id, |
97969c4e | 295 | privacy: VideoPrivacy.PUBLIC, |
68e70a74 | 296 | saveReplay: false |
97969c4e C |
297 | } |
298 | ||
04aed767 | 299 | const { uuid } = await commands[0].create({ fields: liveAttributes }) |
97969c4e | 300 | |
04aed767 | 301 | const live = await commands[0].get({ videoId: uuid }) |
89d241a7 | 302 | const video = await servers[0].videos.get({ id: uuid }) |
97969c4e | 303 | |
d23dd9fb | 304 | return Object.assign(video, live) |
68e70a74 | 305 | } |
97969c4e | 306 | |
68e70a74 | 307 | it('Should not allow a stream without the appropriate path', async function () { |
2df6f943 | 308 | this.timeout(60000) |
97969c4e | 309 | |
68e70a74 | 310 | liveVideo = await createLiveWrapper() |
97969c4e | 311 | |
c826f34a | 312 | const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/bad-live', streamKey: liveVideo.streamKey }) |
68e70a74 | 313 | await testFfmpegStreamError(command, true) |
af4ae64f C |
314 | }) |
315 | ||
68e70a74 | 316 | it('Should not allow a stream without the appropriate stream key', async function () { |
2df6f943 | 317 | this.timeout(60000) |
97969c4e | 318 | |
c826f34a | 319 | const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/live', streamKey: 'bad-stream-key' }) |
68e70a74 | 320 | await testFfmpegStreamError(command, true) |
97969c4e C |
321 | }) |
322 | ||
68e70a74 | 323 | it('Should succeed with the correct params', async function () { |
2df6f943 | 324 | this.timeout(60000) |
97969c4e | 325 | |
c826f34a | 326 | const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/live', streamKey: liveVideo.streamKey }) |
68e70a74 | 327 | await testFfmpegStreamError(command, false) |
af4ae64f C |
328 | }) |
329 | ||
1ab60243 C |
330 | it('Should list this live now someone stream into it', async function () { |
331 | for (const server of servers) { | |
89d241a7 | 332 | const { total, data } = await server.videos.list() |
1ab60243 | 333 | |
d23dd9fb C |
334 | expect(total).to.equal(1) |
335 | expect(data).to.have.lengthOf(1) | |
1ab60243 | 336 | |
d23dd9fb | 337 | const video = data[0] |
1ab60243 C |
338 | expect(video.name).to.equal('user live') |
339 | expect(video.isLive).to.be.true | |
340 | } | |
341 | }) | |
342 | ||
68e70a74 | 343 | it('Should not allow a stream on a live that was blacklisted', async function () { |
2df6f943 | 344 | this.timeout(60000) |
97969c4e | 345 | |
68e70a74 | 346 | liveVideo = await createLiveWrapper() |
af4ae64f | 347 | |
89d241a7 | 348 | await servers[0].blacklist.add({ videoId: liveVideo.uuid }) |
af4ae64f | 349 | |
c826f34a | 350 | const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/live', streamKey: liveVideo.streamKey }) |
68e70a74 | 351 | await testFfmpegStreamError(command, true) |
af4ae64f C |
352 | }) |
353 | ||
68e70a74 | 354 | it('Should not allow a stream on a live that was deleted', async function () { |
2df6f943 | 355 | this.timeout(60000) |
af4ae64f | 356 | |
68e70a74 | 357 | liveVideo = await createLiveWrapper() |
af4ae64f | 358 | |
89d241a7 | 359 | await servers[0].videos.remove({ id: liveVideo.uuid }) |
af4ae64f | 360 | |
c826f34a | 361 | const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/live', streamKey: liveVideo.streamKey }) |
68e70a74 | 362 | await testFfmpegStreamError(command, true) |
af4ae64f C |
363 | }) |
364 | }) | |
365 | ||
366 | describe('Live transcoding', function () { | |
bd54ad19 | 367 | let liveVideoId: string |
d102de1b | 368 | let sqlCommandServer1: SQLCommand |
bd54ad19 C |
369 | |
370 | async function createLiveWrapper (saveReplay: boolean) { | |
371 | const liveAttributes = { | |
372 | name: 'live video', | |
89d241a7 | 373 | channelId: servers[0].store.channel.id, |
bd54ad19 | 374 | privacy: VideoPrivacy.PUBLIC, |
05a60d85 W |
375 | saveReplay, |
376 | replaySettings: saveReplay | |
377 | ? { privacy: VideoPrivacy.PUBLIC } | |
378 | : undefined | |
bd54ad19 C |
379 | } |
380 | ||
04aed767 | 381 | const { uuid } = await commands[0].create({ fields: liveAttributes }) |
4f219914 | 382 | return uuid |
bd54ad19 C |
383 | } |
384 | ||
bd54ad19 | 385 | function updateConf (resolutions: number[]) { |
89d241a7 | 386 | return servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
387 | newConfig: { |
388 | live: { | |
bd54ad19 | 389 | enabled: true, |
65e6e260 C |
390 | allowReplay: true, |
391 | maxDuration: -1, | |
392 | transcoding: { | |
393 | enabled: true, | |
394 | resolutions: { | |
8dd754c7 | 395 | '144p': resolutions.includes(144), |
65e6e260 C |
396 | '240p': resolutions.includes(240), |
397 | '360p': resolutions.includes(360), | |
398 | '480p': resolutions.includes(480), | |
399 | '720p': resolutions.includes(720), | |
400 | '1080p': resolutions.includes(1080), | |
401 | '2160p': resolutions.includes(2160) | |
402 | } | |
bd54ad19 C |
403 | } |
404 | } | |
405 | } | |
406 | }) | |
407 | } | |
408 | ||
409 | before(async function () { | |
410 | await updateConf([]) | |
d102de1b C |
411 | |
412 | sqlCommandServer1 = new SQLCommand(servers[0]) | |
bd54ad19 | 413 | }) |
af4ae64f C |
414 | |
415 | it('Should enable transcoding without additional resolutions', async function () { | |
d8fb3a2f | 416 | this.timeout(120000) |
bd54ad19 C |
417 | |
418 | liveVideoId = await createLiveWrapper(false) | |
419 | ||
4f219914 | 420 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }) |
8ebf2a5d | 421 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
bd54ad19 | 422 | await waitJobs(servers) |
af4ae64f | 423 | |
d102de1b | 424 | await testLiveVideoResolutions({ |
cfd57d2c | 425 | originServer: servers[0], |
d102de1b | 426 | sqlCommand: sqlCommandServer1, |
cfd57d2c C |
427 | servers, |
428 | liveVideoId, | |
429 | resolutions: [ 720 ], | |
430 | objectStorage: false, | |
431 | transcoded: true | |
432 | }) | |
bd54ad19 | 433 | |
4f219914 | 434 | await stopFfmpeg(ffmpegCommand) |
af4ae64f C |
435 | }) |
436 | ||
1593e0dd C |
437 | it('Should transcode audio only RTMP stream', async function () { |
438 | this.timeout(120000) | |
439 | ||
440 | liveVideoId = await createLiveWrapper(false) | |
441 | ||
442 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short_no_audio.mp4' }) | |
443 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | |
444 | await waitJobs(servers) | |
445 | ||
446 | await stopFfmpeg(ffmpegCommand) | |
447 | }) | |
448 | ||
af4ae64f | 449 | it('Should enable transcoding with some resolutions', async function () { |
21609258 | 450 | this.timeout(240000) |
bd54ad19 C |
451 | |
452 | const resolutions = [ 240, 480 ] | |
453 | await updateConf(resolutions) | |
454 | liveVideoId = await createLiveWrapper(false) | |
455 | ||
4f219914 | 456 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }) |
8ebf2a5d | 457 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
bd54ad19 C |
458 | await waitJobs(servers) |
459 | ||
d102de1b | 460 | await testLiveVideoResolutions({ |
cfd57d2c | 461 | originServer: servers[0], |
d102de1b | 462 | sqlCommand: sqlCommandServer1, |
cfd57d2c C |
463 | servers, |
464 | liveVideoId, | |
465 | resolutions: resolutions.concat([ 720 ]), | |
466 | objectStorage: false, | |
467 | transcoded: true | |
468 | }) | |
bd54ad19 | 469 | |
4f219914 | 470 | await stopFfmpeg(ffmpegCommand) |
af4ae64f C |
471 | }) |
472 | ||
c826f34a C |
473 | it('Should correctly set the appropriate bitrate depending on the input', async function () { |
474 | this.timeout(120000) | |
475 | ||
476 | liveVideoId = await createLiveWrapper(false) | |
477 | ||
478 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ | |
479 | videoId: liveVideoId, | |
480 | fixtureName: 'video_short.mp4', | |
481 | copyCodecs: true | |
482 | }) | |
483 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | |
484 | await waitJobs(servers) | |
485 | ||
486 | const video = await servers[0].videos.get({ id: liveVideoId }) | |
487 | ||
488 | const masterPlaylist = video.streamingPlaylists[0].playlistUrl | |
489 | const probe = await ffprobePromise(masterPlaylist) | |
490 | ||
491 | const bitrates = probe.streams.map(s => parseInt(s.tags.variant_bitrate)) | |
492 | for (const bitrate of bitrates) { | |
493 | expect(bitrate).to.exist | |
494 | expect(isNaN(bitrate)).to.be.false | |
495 | expect(bitrate).to.be.below(61_000_000) // video_short.mp4 bitrate | |
496 | } | |
497 | ||
498 | await stopFfmpeg(ffmpegCommand) | |
499 | }) | |
500 | ||
af4ae64f | 501 | it('Should enable transcoding with some resolutions and correctly save them', async function () { |
21609258 | 502 | this.timeout(500_000) |
bd54ad19 C |
503 | |
504 | const resolutions = [ 240, 360, 720 ] | |
ca5c612b | 505 | |
bd54ad19 C |
506 | await updateConf(resolutions) |
507 | liveVideoId = await createLiveWrapper(true) | |
508 | ||
4f219914 | 509 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) |
8ebf2a5d | 510 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
bd54ad19 C |
511 | await waitJobs(servers) |
512 | ||
d102de1b | 513 | await testLiveVideoResolutions({ |
cfd57d2c | 514 | originServer: servers[0], |
d102de1b | 515 | sqlCommand: sqlCommandServer1, |
cfd57d2c C |
516 | servers, |
517 | liveVideoId, | |
518 | resolutions, | |
519 | objectStorage: false, | |
520 | transcoded: true | |
521 | }) | |
bd54ad19 | 522 | |
4f219914 | 523 | await stopFfmpeg(ffmpegCommand) |
04aed767 | 524 | await commands[0].waitUntilEnded({ videoId: liveVideoId }) |
34caef7f | 525 | |
bd54ad19 C |
526 | await waitJobs(servers) |
527 | ||
8ebf2a5d | 528 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
e0783718 | 529 | |
9f430a53 C |
530 | const maxBitrateLimits = { |
531 | 720: 6500 * 1000, // 60FPS | |
532 | 360: 1250 * 1000, | |
533 | 240: 700 * 1000 | |
534 | } | |
535 | ||
536 | const minBitrateLimits = { | |
dd84f4f2 | 537 | 720: 4800 * 1000, |
9f430a53 C |
538 | 360: 1000 * 1000, |
539 | 240: 550 * 1000 | |
ca5c612b C |
540 | } |
541 | ||
bd54ad19 | 542 | for (const server of servers) { |
89d241a7 | 543 | const video = await server.videos.get({ id: liveVideoId }) |
bd54ad19 | 544 | |
e0783718 | 545 | expect(video.state.id).to.equal(VideoState.PUBLISHED) |
bd54ad19 C |
546 | expect(video.duration).to.be.greaterThan(1) |
547 | expect(video.files).to.have.lengthOf(0) | |
548 | ||
549 | const hlsPlaylist = video.streamingPlaylists.find(s => s.type === VideoStreamingPlaylistType.HLS) | |
3545e72c C |
550 | await makeRawRequest({ url: hlsPlaylist.playlistUrl, expectedStatus: HttpStatusCode.OK_200 }) |
551 | await makeRawRequest({ url: hlsPlaylist.segmentsSha256Url, expectedStatus: HttpStatusCode.OK_200 }) | |
bd54ad19 | 552 | |
764b1a14 C |
553 | // We should have generated random filenames |
554 | expect(basename(hlsPlaylist.playlistUrl)).to.not.equal('master.m3u8') | |
555 | expect(basename(hlsPlaylist.segmentsSha256Url)).to.not.equal('segments-sha256.json') | |
556 | ||
bd54ad19 C |
557 | expect(hlsPlaylist.files).to.have.lengthOf(resolutions.length) |
558 | ||
559 | for (const resolution of resolutions) { | |
560 | const file = hlsPlaylist.files.find(f => f.resolution.id === resolution) | |
561 | ||
562 | expect(file).to.exist | |
bd54ad19 C |
563 | expect(file.size).to.be.greaterThan(1) |
564 | ||
884d2c39 | 565 | if (resolution >= 720) { |
f4057afd | 566 | expect(file.fps).to.be.approximately(60, 10) |
884d2c39 | 567 | } else { |
43972ee4 | 568 | expect(file.fps).to.be.approximately(30, 3) |
884d2c39 C |
569 | } |
570 | ||
764b1a14 C |
571 | const filename = basename(file.fileUrl) |
572 | expect(filename).to.not.contain(video.uuid) | |
573 | ||
89d241a7 | 574 | const segmentPath = servers[0].servers.buildDirectory(join('streaming-playlists', 'hls', video.uuid, filename)) |
ca5c612b C |
575 | |
576 | const probe = await ffprobePromise(segmentPath) | |
c729caf6 | 577 | const videoStream = await getVideoStream(segmentPath, probe) |
6b67897e | 578 | |
9f430a53 C |
579 | expect(probe.format.bit_rate).to.be.below(maxBitrateLimits[videoStream.height]) |
580 | expect(probe.format.bit_rate).to.be.at.least(minBitrateLimits[videoStream.height]) | |
ca5c612b | 581 | |
3545e72c C |
582 | await makeRawRequest({ url: file.torrentUrl, expectedStatus: HttpStatusCode.OK_200 }) |
583 | await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) | |
bd54ad19 C |
584 | } |
585 | } | |
af4ae64f C |
586 | }) |
587 | ||
84cae54e | 588 | it('Should not generate an upper resolution than original file', async function () { |
21609258 | 589 | this.timeout(500_000) |
84cae54e C |
590 | |
591 | const resolutions = [ 240, 480 ] | |
592 | await updateConf(resolutions) | |
593 | ||
594 | await servers[0].config.updateExistingSubConfig({ | |
595 | newConfig: { | |
596 | live: { | |
597 | transcoding: { | |
598 | alwaysTranscodeOriginalResolution: false | |
599 | } | |
600 | } | |
601 | } | |
602 | }) | |
603 | ||
604 | liveVideoId = await createLiveWrapper(true) | |
605 | ||
606 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) | |
607 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | |
608 | await waitJobs(servers) | |
609 | ||
d102de1b | 610 | await testLiveVideoResolutions({ |
cfd57d2c | 611 | originServer: servers[0], |
d102de1b | 612 | sqlCommand: sqlCommandServer1, |
cfd57d2c C |
613 | servers, |
614 | liveVideoId, | |
615 | resolutions, | |
616 | objectStorage: false, | |
617 | transcoded: true | |
618 | }) | |
84cae54e C |
619 | |
620 | await stopFfmpeg(ffmpegCommand) | |
621 | await commands[0].waitUntilEnded({ videoId: liveVideoId }) | |
622 | ||
623 | await waitJobs(servers) | |
624 | ||
625 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | |
626 | ||
627 | const video = await servers[0].videos.get({ id: liveVideoId }) | |
628 | const hlsFiles = video.streamingPlaylists[0].files | |
629 | ||
630 | expect(video.files).to.have.lengthOf(0) | |
631 | expect(hlsFiles).to.have.lengthOf(resolutions.length) | |
632 | ||
633 | // eslint-disable-next-line @typescript-eslint/require-array-sort-compare | |
634 | expect(getAllFiles(video).map(f => f.resolution.id).sort()).to.deep.equal(resolutions) | |
635 | }) | |
636 | ||
637 | it('Should only keep the original resolution if all resolutions are disabled', async function () { | |
70c6a848 | 638 | this.timeout(600_000) |
84cae54e C |
639 | |
640 | await updateConf([]) | |
641 | liveVideoId = await createLiveWrapper(true) | |
642 | ||
643 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) | |
644 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | |
645 | await waitJobs(servers) | |
646 | ||
d102de1b | 647 | await testLiveVideoResolutions({ |
cfd57d2c | 648 | originServer: servers[0], |
d102de1b | 649 | sqlCommand: sqlCommandServer1, |
cfd57d2c C |
650 | servers, |
651 | liveVideoId, | |
652 | resolutions: [ 720 ], | |
653 | objectStorage: false, | |
654 | transcoded: true | |
655 | }) | |
84cae54e C |
656 | |
657 | await stopFfmpeg(ffmpegCommand) | |
658 | await commands[0].waitUntilEnded({ videoId: liveVideoId }) | |
659 | ||
660 | await waitJobs(servers) | |
661 | ||
662 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | |
663 | ||
664 | const video = await servers[0].videos.get({ id: liveVideoId }) | |
665 | const hlsFiles = video.streamingPlaylists[0].files | |
666 | ||
667 | expect(video.files).to.have.lengthOf(0) | |
668 | expect(hlsFiles).to.have.lengthOf(1) | |
bd54ad19 | 669 | |
84cae54e | 670 | expect(hlsFiles[0].resolution.id).to.equal(720) |
af4ae64f | 671 | }) |
d102de1b C |
672 | |
673 | after(async function () { | |
674 | await sqlCommandServer1.cleanup() | |
675 | }) | |
af4ae64f C |
676 | }) |
677 | ||
5c0904fc C |
678 | describe('After a server restart', function () { |
679 | let liveVideoId: string | |
680 | let liveVideoReplayId: string | |
98ebfa39 | 681 | let permanentLiveVideoReplayId: string |
5c0904fc | 682 | |
98ebfa39 C |
683 | let permanentLiveReplayName: string |
684 | ||
26e3e98f C |
685 | let beforeServerRestart: Date |
686 | ||
98ebfa39 C |
687 | async function createLiveWrapper (options: { saveReplay: boolean, permanent: boolean }) { |
688 | const liveAttributes: LiveVideoCreate = { | |
5c0904fc | 689 | name: 'live video', |
89d241a7 | 690 | channelId: servers[0].store.channel.id, |
5c0904fc | 691 | privacy: VideoPrivacy.PUBLIC, |
98ebfa39 | 692 | saveReplay: options.saveReplay, |
05a60d85 W |
693 | replaySettings: options.saveReplay |
694 | ? { privacy: VideoPrivacy.PUBLIC } | |
695 | : undefined, | |
98ebfa39 | 696 | permanentLive: options.permanent |
5c0904fc C |
697 | } |
698 | ||
04aed767 | 699 | const { uuid } = await commands[0].create({ fields: liveAttributes }) |
4f219914 | 700 | return uuid |
5c0904fc C |
701 | } |
702 | ||
703 | before(async function () { | |
70c6a848 | 704 | this.timeout(600_000) |
5c0904fc | 705 | |
98ebfa39 C |
706 | liveVideoId = await createLiveWrapper({ saveReplay: false, permanent: false }) |
707 | liveVideoReplayId = await createLiveWrapper({ saveReplay: true, permanent: false }) | |
708 | permanentLiveVideoReplayId = await createLiveWrapper({ saveReplay: true, permanent: true }) | |
5c0904fc C |
709 | |
710 | await Promise.all([ | |
4f219914 | 711 | commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }), |
98ebfa39 | 712 | commands[0].sendRTMPStreamInVideo({ videoId: permanentLiveVideoReplayId }), |
4f219914 | 713 | commands[0].sendRTMPStreamInVideo({ videoId: liveVideoReplayId }) |
5c0904fc C |
714 | ]) |
715 | ||
716 | await Promise.all([ | |
04aed767 | 717 | commands[0].waitUntilPublished({ videoId: liveVideoId }), |
98ebfa39 | 718 | commands[0].waitUntilPublished({ videoId: permanentLiveVideoReplayId }), |
04aed767 | 719 | commands[0].waitUntilPublished({ videoId: liveVideoReplayId }) |
5c0904fc C |
720 | ]) |
721 | ||
bbae45c3 C |
722 | for (const videoUUID of [ liveVideoId, liveVideoReplayId, permanentLiveVideoReplayId ]) { |
723 | await commands[0].waitUntilSegmentGeneration({ | |
724 | server: servers[0], | |
725 | videoUUID, | |
726 | playlistNumber: 0, | |
727 | segment: 2, | |
728 | objectStorage: false | |
729 | }) | |
730 | } | |
98ebfa39 C |
731 | |
732 | { | |
733 | const video = await servers[0].videos.get({ id: permanentLiveVideoReplayId }) | |
734 | permanentLiveReplayName = video.name + ' - ' + new Date(video.publishedAt).toLocaleString() | |
735 | } | |
0d8de275 | 736 | |
9293139f | 737 | await killallServers([ servers[0] ]) |
26e3e98f C |
738 | |
739 | beforeServerRestart = new Date() | |
254d3579 | 740 | await servers[0].run() |
5c0904fc C |
741 | |
742 | await wait(5000) | |
98ebfa39 | 743 | await waitJobs(servers) |
5c0904fc C |
744 | }) |
745 | ||
746 | it('Should cleanup lives', async function () { | |
747 | this.timeout(60000) | |
748 | ||
04aed767 | 749 | await commands[0].waitUntilEnded({ videoId: liveVideoId }) |
98ebfa39 | 750 | await commands[0].waitUntilWaiting({ videoId: permanentLiveVideoReplayId }) |
5c0904fc C |
751 | }) |
752 | ||
98ebfa39 | 753 | it('Should save a non permanent live replay', async function () { |
3cb60ca1 | 754 | this.timeout(240000) |
5c0904fc | 755 | |
04aed767 | 756 | await commands[0].waitUntilPublished({ videoId: liveVideoReplayId }) |
26e3e98f C |
757 | |
758 | const session = await commands[0].getReplaySession({ videoId: liveVideoReplayId }) | |
759 | expect(session.endDate).to.exist | |
760 | expect(new Date(session.endDate)).to.be.above(beforeServerRestart) | |
5c0904fc | 761 | }) |
98ebfa39 C |
762 | |
763 | it('Should have saved a permanent live replay', async function () { | |
764 | this.timeout(120000) | |
765 | ||
766 | const { data } = await servers[0].videos.listMyVideos({ sort: '-publishedAt' }) | |
767 | expect(data.find(v => v.name === permanentLiveReplayName)).to.exist | |
768 | }) | |
5c0904fc C |
769 | }) |
770 | ||
af4ae64f C |
771 | after(async function () { |
772 | await cleanupTests(servers) | |
773 | }) | |
774 | }) |