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