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