]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-transcoder.ts
Fix NSFW tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-transcoder.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
0e1dc3e7 2
a7ba16b6 3import 'mocha'
daf6e480
C
4import * as chai from 'chai'
5import { FfprobeData } from 'fluent-ffmpeg'
7160878c 6import { omit } from 'lodash'
daf6e480 7import { join } from 'path'
daf6e480 8import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants'
6939cbac 9import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
0e1dc3e7 10import {
7243f84d 11 buildAbsoluteFixturePath,
ca5c612b 12 buildServerDirectory,
7243f84d 13 cleanupTests,
2186386c
C
14 doubleFollow,
15 flushAndRunMultipleServers,
d175a6f7 16 generateHighBitrateVideo,
837666fe 17 generateVideoWithFramerate,
2186386c 18 getMyVideos,
d218e7de 19 getServerFileSize,
2186386c 20 getVideo,
8319d6ae 21 getVideoFileMetadataUrl,
2186386c 22 getVideosList,
b345a804 23 makeGetRequest,
2186386c
C
24 ServerInfo,
25 setAccessTokensToServers,
daf6e480
C
26 uploadVideo,
27 uploadVideoAndGetId,
1600235a 28 waitJobs,
d175a6f7 29 webtorrentAdd
94565d52 30} from '../../../../shared/extra-utils'
daf6e480
C
31import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos'
32import {
33 canDoQuickTranscode,
34 getAudioStream,
35 getMetadataFromFile,
36 getVideoFileBitrate,
37 getVideoFileFPS,
38 getVideoFileResolution
39} from '../../../helpers/ffprobe-utils'
a7ba16b6
C
40
41const expect = chai.expect
0e1dc3e7 42
40930fda 43function updateConfigForTranscoding (server: ServerInfo) {
65e6e260
C
44 return server.configCommand.updateCustomSubConfig({
45 newConfig: {
46 transcoding: {
47 enabled: true,
48 allowAdditionalExtensions: true,
49 allowAudioFiles: true,
50 hls: { enabled: true },
51 webtorrent: { enabled: true },
52 resolutions: {
53 '0p': false,
54 '240p': true,
55 '360p': true,
56 '480p': true,
57 '720p': true,
58 '1080p': true,
59 '1440p': true,
60 '2160p': true
61 }
40930fda
C
62 }
63 }
64 })
65}
66
0e1dc3e7
C
67describe('Test video transcoding', function () {
68 let servers: ServerInfo[] = []
6939cbac 69 let video4k: string
0e1dc3e7
C
70
71 before(async function () {
454c20fa 72 this.timeout(30_000)
0e1dc3e7
C
73
74 // Run servers
75 servers = await flushAndRunMultipleServers(2)
76
77 await setAccessTokensToServers(servers)
b2977eec
C
78
79 await doubleFollow(servers[0], servers[1])
40930fda
C
80
81 await updateConfigForTranscoding(servers[1])
0e1dc3e7
C
82 })
83
40930fda 84 describe('Basic transcoding (or not)', function () {
0e1dc3e7 85
40930fda
C
86 it('Should not transcode video on server 1', async function () {
87 this.timeout(60_000)
0e1dc3e7 88
40930fda
C
89 const videoAttributes = {
90 name: 'my super name for server 1',
91 description: 'my super description for server 1',
92 fixture: 'video_short.webm'
93 }
94 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
0e1dc3e7 95
40930fda 96 await waitJobs(servers)
40298b02 97
40930fda
C
98 for (const server of servers) {
99 const res = await getVideosList(server.url)
100 const video = res.body.data[0]
5f04dd2f 101
40930fda
C
102 const res2 = await getVideo(server.url, video.id)
103 const videoDetails = res2.body
104 expect(videoDetails.files).to.have.lengthOf(1)
0e1dc3e7 105
40930fda
C
106 const magnetUri = videoDetails.files[0].magnetUri
107 expect(magnetUri).to.match(/\.webm/)
0e1dc3e7 108
40930fda
C
109 const torrent = await webtorrentAdd(magnetUri, true)
110 expect(torrent.files).to.be.an('array')
111 expect(torrent.files.length).to.equal(1)
112 expect(torrent.files[0].path).match(/\.webm$/)
113 }
114 })
0e1dc3e7 115
40930fda
C
116 it('Should transcode video on server 2', async function () {
117 this.timeout(120_000)
118
119 const videoAttributes = {
120 name: 'my super name for server 2',
121 description: 'my super description for server 2',
122 fixture: 'video_short.webm'
123 }
124 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
125
126 await waitJobs(servers)
127
128 for (const server of servers) {
129 const res = await getVideosList(server.url)
0e1dc3e7 130
40930fda
C
131 const video = res.body.data.find(v => v.name === videoAttributes.name)
132 const res2 = await getVideo(server.url, video.id)
133 const videoDetails = res2.body
0e1dc3e7 134
40930fda 135 expect(videoDetails.files).to.have.lengthOf(4)
0e1dc3e7 136
40930fda
C
137 const magnetUri = videoDetails.files[0].magnetUri
138 expect(magnetUri).to.match(/\.mp4/)
5f04dd2f 139
40930fda
C
140 const torrent = await webtorrentAdd(magnetUri, true)
141 expect(torrent.files).to.be.an('array')
142 expect(torrent.files.length).to.equal(1)
143 expect(torrent.files[0].path).match(/\.mp4$/)
144 }
145 })
40298b02 146
40930fda
C
147 it('Should wait for transcoding before publishing the video', async function () {
148 this.timeout(160_000)
0e1dc3e7 149
40930fda
C
150 {
151 // Upload the video, but wait transcoding
152 const videoAttributes = {
153 name: 'waiting video',
154 fixture: 'video_short1.webm',
155 waitTranscoding: true
156 }
157 const resVideo = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
158 const videoId = resVideo.body.video.uuid
159
160 // Should be in transcode state
161 const { body } = await getVideo(servers[1].url, videoId)
162 expect(body.name).to.equal('waiting video')
163 expect(body.state.id).to.equal(VideoState.TO_TRANSCODE)
164 expect(body.state.label).to.equal('To transcode')
165 expect(body.waitTranscoding).to.be.true
166
167 // Should have my video
168 const resMyVideos = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 10)
169 const videoToFindInMine = resMyVideos.body.data.find(v => v.name === videoAttributes.name)
170 expect(videoToFindInMine).not.to.be.undefined
171 expect(videoToFindInMine.state.id).to.equal(VideoState.TO_TRANSCODE)
172 expect(videoToFindInMine.state.label).to.equal('To transcode')
173 expect(videoToFindInMine.waitTranscoding).to.be.true
174
175 // Should not list this video
176 const resVideos = await getVideosList(servers[1].url)
177 const videoToFindInList = resVideos.body.data.find(v => v.name === videoAttributes.name)
178 expect(videoToFindInList).to.be.undefined
179
180 // Server 1 should not have the video yet
181 await getVideo(servers[0].url, videoId, HttpStatusCode.NOT_FOUND_404)
182 }
0e1dc3e7 183
40930fda 184 await waitJobs(servers)
7160878c 185
40930fda
C
186 for (const server of servers) {
187 const res = await getVideosList(server.url)
188 const videoToFind = res.body.data.find(v => v.name === 'waiting video')
189 expect(videoToFind).not.to.be.undefined
7160878c 190
40930fda
C
191 const res2 = await getVideo(server.url, videoToFind.id)
192 const videoDetails: VideoDetails = res2.body
7160878c 193
40930fda
C
194 expect(videoDetails.state.id).to.equal(VideoState.PUBLISHED)
195 expect(videoDetails.state.label).to.equal('Published')
196 expect(videoDetails.waitTranscoding).to.be.true
197 }
198 })
7160878c 199
40930fda
C
200 it('Should accept and transcode additional extensions', async function () {
201 this.timeout(300_000)
7160878c 202
40930fda 203 let tempFixturePath: string
7160878c 204
40930fda
C
205 {
206 tempFixturePath = await generateHighBitrateVideo()
7160878c 207
40930fda
C
208 const bitrate = await getVideoFileBitrate(tempFixturePath)
209 expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS))
b2977eec 210 }
7160878c 211
40930fda
C
212 for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) {
213 const videoAttributes = {
214 name: fixture,
215 fixture
216 }
7160878c 217
40930fda 218 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
7160878c 219
40930fda 220 await waitJobs(servers)
7160878c 221
40930fda
C
222 for (const server of servers) {
223 const res = await getVideosList(server.url)
7160878c 224
40930fda
C
225 const video = res.body.data.find(v => v.name === videoAttributes.name)
226 const res2 = await getVideo(server.url, video.id)
227 const videoDetails = res2.body
7160878c 228
40930fda 229 expect(videoDetails.files).to.have.lengthOf(4)
7160878c 230
40930fda
C
231 const magnetUri = videoDetails.files[0].magnetUri
232 expect(magnetUri).to.contain('.mp4')
233 }
234 }
235 })
7160878c 236
40930fda
C
237 it('Should transcode a 4k video', async function () {
238 this.timeout(200_000)
7160878c 239
40930fda
C
240 const videoAttributes = {
241 name: '4k video',
242 fixture: 'video_short_4k.mp4'
243 }
7160878c 244
40930fda
C
245 const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
246 video4k = resUpload.body.video.uuid
b2977eec 247
40930fda 248 await waitJobs(servers)
b2977eec 249
40930fda 250 const resolutions = [ 240, 360, 480, 720, 1080, 1440, 2160 ]
ca5c612b 251
40930fda
C
252 for (const server of servers) {
253 const res = await getVideo(server.url, video4k)
254 const videoDetails: VideoDetails = res.body
ca5c612b 255
40930fda 256 expect(videoDetails.files).to.have.lengthOf(resolutions.length)
ca5c612b 257
40930fda
C
258 for (const r of resolutions) {
259 expect(videoDetails.files.find(f => f.resolution.id === r)).to.not.be.undefined
260 expect(videoDetails.streamingPlaylists[0].files.find(f => f.resolution.id === r)).to.not.be.undefined
261 }
b2977eec 262 }
40930fda 263 })
7160878c
RK
264 })
265
40930fda 266 describe('Audio transcoding', function () {
73c69591 267
40930fda
C
268 it('Should transcode high bit rate mp3 to proper bit rate', async function () {
269 this.timeout(60_000)
73c69591 270
40930fda
C
271 const videoAttributes = {
272 name: 'mp3_256k',
273 fixture: 'video_short_mp3_256k.mp4'
274 }
275 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
73c69591 276
40930fda 277 await waitJobs(servers)
73c69591 278
40930fda
C
279 for (const server of servers) {
280 const res = await getVideosList(server.url)
73c69591 281
40930fda
C
282 const video = res.body.data.find(v => v.name === videoAttributes.name)
283 const res2 = await getVideo(server.url, video.id)
284 const videoDetails: VideoDetails = res2.body
73c69591 285
40930fda 286 expect(videoDetails.files).to.have.lengthOf(4)
73c69591 287
40930fda
C
288 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4'))
289 const probe = await getAudioStream(path)
290
291 if (probe.audioStream) {
292 expect(probe.audioStream['codec_name']).to.be.equal('aac')
293 expect(probe.audioStream['bit_rate']).to.be.at.most(384 * 8000)
294 } else {
295 this.fail('Could not retrieve the audio stream on ' + probe.absolutePath)
296 }
b2977eec 297 }
40930fda 298 })
3a6f351b 299
40930fda
C
300 it('Should transcode video with no audio and have no audio itself', async function () {
301 this.timeout(60_000)
2186386c 302
2186386c 303 const videoAttributes = {
40930fda
C
304 name: 'no_audio',
305 fixture: 'video_short_no_audio.mp4'
306 }
307 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
2186386c 308
40930fda 309 await waitJobs(servers)
2186386c 310
40930fda
C
311 for (const server of servers) {
312 const res = await getVideosList(server.url)
2186386c 313
40930fda
C
314 const video = res.body.data.find(v => v.name === videoAttributes.name)
315 const res2 = await getVideo(server.url, video.id)
316 const videoDetails: VideoDetails = res2.body
2186386c 317
40930fda
C
318 expect(videoDetails.files).to.have.lengthOf(4)
319 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4'))
320 const probe = await getAudioStream(path)
321 expect(probe).to.not.have.property('audioStream')
322 }
323 })
2186386c 324
40930fda
C
325 it('Should leave the audio untouched, but properly transcode the video', async function () {
326 this.timeout(60_000)
edb4ffc7 327
40930fda
C
328 const videoAttributes = {
329 name: 'untouched_audio',
330 fixture: 'video_short.mp4'
331 }
332 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
74cd011b 333
40930fda 334 await waitJobs(servers)
edb4ffc7 335
40930fda
C
336 for (const server of servers) {
337 const res = await getVideosList(server.url)
edb4ffc7 338
40930fda
C
339 const video = res.body.data.find(v => v.name === videoAttributes.name)
340 const res2 = await getVideo(server.url, video.id)
341 const videoDetails: VideoDetails = res2.body
edb4ffc7 342
40930fda 343 expect(videoDetails.files).to.have.lengthOf(4)
edb4ffc7 344
40930fda
C
345 const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture)
346 const fixtureVideoProbe = await getAudioStream(fixturePath)
347 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4'))
edb4ffc7 348
40930fda 349 const videoProbe = await getAudioStream(path)
edb4ffc7 350
40930fda
C
351 if (videoProbe.audioStream && fixtureVideoProbe.audioStream) {
352 const toOmit = [ 'max_bit_rate', 'duration', 'duration_ts', 'nb_frames', 'start_time', 'start_pts' ]
353 expect(omit(videoProbe.audioStream, toOmit)).to.be.deep.equal(omit(fixtureVideoProbe.audioStream, toOmit))
354 } else {
355 this.fail('Could not retrieve the audio stream on ' + videoProbe.absolutePath)
356 }
357 }
358 })
359 })
edb4ffc7 360
40930fda
C
361 describe('Audio upload', function () {
362
f6d6e7f8 363 function runSuite (mode: 'legacy' | 'resumable') {
364
365 before(async function () {
65e6e260
C
366 await servers[1].configCommand.updateCustomSubConfig({
367 newConfig: {
368 transcoding: {
369 hls: { enabled: true },
370 webtorrent: { enabled: true },
371 resolutions: {
372 '0p': false,
373 '240p': false,
374 '360p': false,
375 '480p': false,
376 '720p': false,
377 '1080p': false,
378 '1440p': false,
379 '2160p': false
380 }
f6d6e7f8 381 }
40930fda 382 }
f6d6e7f8 383 })
40930fda 384 })
edb4ffc7 385
f6d6e7f8 386 it('Should merge an audio file with the preview file', async function () {
387 this.timeout(60_000)
edb4ffc7 388
f6d6e7f8 389 const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
390 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode)
14e2014a 391
f6d6e7f8 392 await waitJobs(servers)
7ed2c1a4 393
f6d6e7f8 394 for (const server of servers) {
395 const res = await getVideosList(server.url)
7ed2c1a4 396
f6d6e7f8 397 const video = res.body.data.find(v => v.name === 'audio_with_preview')
398 const res2 = await getVideo(server.url, video.id)
399 const videoDetails: VideoDetails = res2.body
7ed2c1a4 400
f6d6e7f8 401 expect(videoDetails.files).to.have.lengthOf(1)
14e2014a 402
f6d6e7f8 403 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 })
404 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 })
40930fda 405
f6d6e7f8 406 const magnetUri = videoDetails.files[0].magnetUri
407 expect(magnetUri).to.contain('.mp4')
408 }
409 })
14e2014a 410
f6d6e7f8 411 it('Should upload an audio file and choose a default background image', async function () {
412 this.timeout(60_000)
14e2014a 413
f6d6e7f8 414 const videoAttributesArg = { name: 'audio_without_preview', fixture: 'sample.ogg' }
415 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode)
14e2014a 416
f6d6e7f8 417 await waitJobs(servers)
14e2014a 418
f6d6e7f8 419 for (const server of servers) {
420 const res = await getVideosList(server.url)
40930fda 421
f6d6e7f8 422 const video = res.body.data.find(v => v.name === 'audio_without_preview')
423 const res2 = await getVideo(server.url, video.id)
424 const videoDetails = res2.body
14e2014a 425
f6d6e7f8 426 expect(videoDetails.files).to.have.lengthOf(1)
14e2014a 427
f6d6e7f8 428 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 })
429 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 })
7ed2c1a4 430
f6d6e7f8 431 const magnetUri = videoDetails.files[0].magnetUri
432 expect(magnetUri).to.contain('.mp4')
40930fda
C
433 }
434 })
7ed2c1a4 435
f6d6e7f8 436 it('Should upload an audio file and create an audio version only', async function () {
437 this.timeout(60_000)
438
65e6e260
C
439 await servers[1].configCommand.updateCustomSubConfig({
440 newConfig: {
441 transcoding: {
442 hls: { enabled: true },
443 webtorrent: { enabled: true },
444 resolutions: {
445 '0p': true,
446 '240p': false,
447 '360p': false
448 }
f6d6e7f8 449 }
450 }
451 })
b345a804 452
f6d6e7f8 453 const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' }
454 const resVideo = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode)
b345a804 455
f6d6e7f8 456 await waitJobs(servers)
b345a804 457
f6d6e7f8 458 for (const server of servers) {
459 const res2 = await getVideo(server.url, resVideo.body.video.id)
460 const videoDetails: VideoDetails = res2.body
461
462 for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) {
463 expect(files).to.have.lengthOf(2)
464 expect(files.find(f => f.resolution.id === 0)).to.not.be.undefined
465 }
40930fda 466 }
b345a804 467
f6d6e7f8 468 await updateConfigForTranscoding(servers[1])
469 })
470 }
471
472 describe('Legacy upload', function () {
473 runSuite('legacy')
474 })
475
476 describe('Resumable upload', function () {
477 runSuite('resumable')
40930fda
C
478 })
479 })
b345a804 480
40930fda 481 describe('Framerate', function () {
b345a804 482
40930fda
C
483 it('Should transcode a 60 FPS video', async function () {
484 this.timeout(60_000)
b345a804 485
40930fda
C
486 const videoAttributes = {
487 name: 'my super 30fps name for server 2',
488 description: 'my super 30fps description for server 2',
489 fixture: '60fps_720p_small.mp4'
490 }
491 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
b345a804 492
40930fda 493 await waitJobs(servers)
b345a804 494
40930fda
C
495 for (const server of servers) {
496 const res = await getVideosList(server.url)
b345a804 497
40930fda
C
498 const video = res.body.data.find(v => v.name === videoAttributes.name)
499 const res2 = await getVideo(server.url, video.id)
500 const videoDetails: VideoDetails = res2.body
b345a804 501
40930fda
C
502 expect(videoDetails.files).to.have.lengthOf(4)
503 expect(videoDetails.files[0].fps).to.be.above(58).and.below(62)
504 expect(videoDetails.files[1].fps).to.be.below(31)
505 expect(videoDetails.files[2].fps).to.be.below(31)
506 expect(videoDetails.files[3].fps).to.be.below(31)
b345a804 507
40930fda
C
508 for (const resolution of [ '240', '360', '480' ]) {
509 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4'))
510 const fps = await getVideoFileFPS(path)
b345a804 511
40930fda
C
512 expect(fps).to.be.below(31)
513 }
b345a804 514
40930fda
C
515 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4'))
516 const fps = await getVideoFileFPS(path)
b345a804 517
40930fda
C
518 expect(fps).to.be.above(58).and.below(62)
519 }
520 })
b345a804 521
40930fda
C
522 it('Should downscale to the closest divisor standard framerate', async function () {
523 this.timeout(200_000)
837666fe 524
40930fda 525 let tempFixturePath: string
837666fe 526
40930fda
C
527 {
528 tempFixturePath = await generateVideoWithFramerate(59)
837666fe 529
40930fda
C
530 const fps = await getVideoFileFPS(tempFixturePath)
531 expect(fps).to.be.equal(59)
532 }
837666fe 533
40930fda
C
534 const videoAttributes = {
535 name: '59fps video',
536 description: '59fps video',
537 fixture: tempFixturePath
538 }
837666fe 539
40930fda 540 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
837666fe 541
40930fda 542 await waitJobs(servers)
837666fe 543
40930fda
C
544 for (const server of servers) {
545 const res = await getVideosList(server.url)
837666fe 546
40930fda 547 const video = res.body.data.find(v => v.name === videoAttributes.name)
837666fe 548
40930fda
C
549 {
550 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4'))
551 const fps = await getVideoFileFPS(path)
552 expect(fps).to.be.equal(25)
553 }
554
555 {
556 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4'))
557 const fps = await getVideoFileFPS(path)
558 expect(fps).to.be.equal(59)
559 }
c7f36e4f 560 }
40930fda
C
561 })
562 })
563
564 describe('Bitrate control', function () {
565 it('Should respect maximum bitrate values', async function () {
566 this.timeout(160_000)
567
568 let tempFixturePath: string
c7f36e4f
C
569
570 {
40930fda 571 tempFixturePath = await generateHighBitrateVideo()
837666fe 572
40930fda
C
573 const bitrate = await getVideoFileBitrate(tempFixturePath)
574 expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS))
d218e7de 575 }
d218e7de 576
40930fda
C
577 const videoAttributes = {
578 name: 'high bitrate video',
579 description: 'high bitrate video',
580 fixture: tempFixturePath
581 }
d218e7de 582
40930fda 583 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
d218e7de 584
40930fda 585 await waitJobs(servers)
d218e7de 586
40930fda
C
587 for (const server of servers) {
588 const res = await getVideosList(server.url)
d218e7de 589
40930fda 590 const video = res.body.data.find(v => v.name === videoAttributes.name)
8319d6ae 591
40930fda
C
592 for (const resolution of [ '240', '360', '480', '720', '1080' ]) {
593 const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4'))
8319d6ae 594
40930fda
C
595 const bitrate = await getVideoFileBitrate(path)
596 const fps = await getVideoFileFPS(path)
597 const resolution2 = await getVideoFileResolution(path)
8319d6ae 598
40930fda
C
599 expect(resolution2.videoFileResolution.toString()).to.equal(resolution)
600 expect(bitrate).to.be.below(getMaxBitrate(resolution2.videoFileResolution, fps, VIDEO_TRANSCODING_FPS))
601 }
7b81edc8 602 }
40930fda 603 })
8319d6ae 604
40930fda
C
605 it('Should not transcode to an higher bitrate than the original file', async function () {
606 this.timeout(160_000)
607
65e6e260 608 const newConfig = {
40930fda
C
609 transcoding: {
610 enabled: true,
611 resolutions: {
612 '240p': true,
613 '360p': true,
614 '480p': true,
615 '720p': true,
616 '1080p': true,
617 '1440p': true,
618 '2160p': true
619 },
620 webtorrent: { enabled: true },
621 hls: { enabled: true }
622 }
8319d6ae 623 }
65e6e260 624 await servers[1].configCommand.updateCustomSubConfig({ newConfig })
7b81edc8 625
40930fda
C
626 const videoAttributes = {
627 name: 'low bitrate',
628 fixture: 'low-bitrate.mp4'
629 }
8319d6ae 630
40930fda
C
631 const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
632 const videoUUID = resUpload.body.video.uuid
7b81edc8 633
40930fda 634 await waitJobs(servers)
8319d6ae 635
40930fda
C
636 const resolutions = [ 240, 360, 480, 720, 1080 ]
637 for (const r of resolutions) {
638 const path = `videos/${videoUUID}-${r}.mp4`
639 const size = await getServerFileSize(servers[1], path)
640 expect(size, `${path} not below ${60_000}`).to.be.below(60_000)
8319d6ae 641 }
40930fda 642 })
8319d6ae
RK
643 })
644
40930fda 645 describe('FFprobe', function () {
f5961a8c 646
40930fda
C
647 it('Should provide valid ffprobe data', async function () {
648 this.timeout(160_000)
f5961a8c 649
40930fda
C
650 const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'ffprobe data' })).uuid
651 await waitJobs(servers)
f5961a8c 652
40930fda
C
653 {
654 const path = buildServerDirectory(servers[1], join('videos', videoUUID + '-240.mp4'))
655 const metadata = await getMetadataFromFile(path)
656
657 // expected format properties
658 for (const p of [
659 'tags.encoder',
660 'format_long_name',
661 'size',
662 'bit_rate'
663 ]) {
664 expect(metadata.format).to.have.nested.property(p)
665 }
666
667 // expected stream properties
668 for (const p of [
669 'codec_long_name',
670 'profile',
671 'width',
672 'height',
673 'display_aspect_ratio',
674 'avg_frame_rate',
675 'pix_fmt'
676 ]) {
677 expect(metadata.streams[0]).to.have.nested.property(p)
678 }
679
680 expect(metadata).to.not.have.nested.property('format.filename')
681 }
f5961a8c 682
40930fda
C
683 for (const server of servers) {
684 const res2 = await getVideo(server.url, videoUUID)
685 const videoDetails: VideoDetails = res2.body
686
687 const videoFiles = videoDetails.files
688 .concat(videoDetails.streamingPlaylists[0].files)
689 expect(videoFiles).to.have.lengthOf(8)
690
691 for (const file of videoFiles) {
692 expect(file.metadata).to.be.undefined
693 expect(file.metadataUrl).to.exist
694 expect(file.metadataUrl).to.contain(servers[1].url)
695 expect(file.metadataUrl).to.contain(videoUUID)
696
697 const res3 = await getVideoFileMetadataUrl(file.metadataUrl)
698 const metadata: FfprobeData = res3.body
699 expect(metadata).to.have.nested.property('format.size')
700 }
701 }
702 })
f5961a8c 703
40930fda
C
704 it('Should correctly detect if quick transcode is possible', async function () {
705 this.timeout(10_000)
f5961a8c 706
40930fda
C
707 expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.mp4'))).to.be.true
708 expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.webm'))).to.be.false
709 })
f5961a8c
C
710 })
711
40930fda 712 describe('Transcoding job queue', function () {
6939cbac 713
40930fda 714 it('Should have the appropriate priorities for transcoding jobs', async function () {
9c6327f8 715 const body = await servers[1].jobsCommand.getJobsList({
40930fda
C
716 start: 0,
717 count: 100,
718 sort: '-createdAt',
719 jobType: 'video-transcoding'
720 })
6939cbac 721
9c6327f8 722 const jobs = body.data
40930fda 723 const transcodingJobs = jobs.filter(j => j.data.videoUUID === video4k)
6939cbac 724
40930fda 725 expect(transcodingJobs).to.have.lengthOf(14)
6939cbac 726
40930fda
C
727 const hlsJobs = transcodingJobs.filter(j => j.data.type === 'new-resolution-to-hls')
728 const webtorrentJobs = transcodingJobs.filter(j => j.data.type === 'new-resolution-to-webtorrent')
729 const optimizeJobs = transcodingJobs.filter(j => j.data.type === 'optimize-to-webtorrent')
6939cbac 730
40930fda
C
731 expect(hlsJobs).to.have.lengthOf(7)
732 expect(webtorrentJobs).to.have.lengthOf(6)
733 expect(optimizeJobs).to.have.lengthOf(1)
6939cbac 734
a6e37eeb 735 for (const j of optimizeJobs.concat(hlsJobs.concat(webtorrentJobs))) {
40930fda
C
736 expect(j.priority).to.be.greaterThan(100)
737 expect(j.priority).to.be.lessThan(150)
738 }
739 })
6939cbac
C
740 })
741
7c3b7976
C
742 after(async function () {
743 await cleanupTests(servers)
0e1dc3e7
C
744 })
745})