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