]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { FfprobeData } from 'fluent-ffmpeg' | |
6 | import { omit } from 'lodash' | |
7 | import { join } from 'path' | |
8 | import { Job } from '@shared/models' | |
9 | import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' | |
10 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | |
11 | import { | |
12 | buildAbsoluteFixturePath, | |
13 | buildServerDirectory, | |
14 | cleanupTests, | |
15 | doubleFollow, | |
16 | flushAndRunMultipleServers, | |
17 | generateHighBitrateVideo, | |
18 | generateVideoWithFramerate, | |
19 | getJobsListPaginationAndSort, | |
20 | getMyVideos, | |
21 | getServerFileSize, | |
22 | getVideo, | |
23 | getVideoFileMetadataUrl, | |
24 | getVideosList, | |
25 | makeGetRequest, | |
26 | ServerInfo, | |
27 | setAccessTokensToServers, | |
28 | updateCustomSubConfig, | |
29 | uploadVideo, | |
30 | uploadVideoAndGetId, | |
31 | waitJobs, | |
32 | webtorrentAdd | |
33 | } from '../../../../shared/extra-utils' | |
34 | import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos' | |
35 | import { | |
36 | canDoQuickTranscode, | |
37 | getAudioStream, | |
38 | getMetadataFromFile, | |
39 | getVideoFileBitrate, | |
40 | getVideoFileFPS, | |
41 | getVideoFileResolution | |
42 | } from '../../../helpers/ffprobe-utils' | |
43 | ||
44 | const expect = chai.expect | |
45 | ||
46 | function 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 | ||
68 | describe('Test video transcoding', function () { | |
69 | let servers: ServerInfo[] = [] | |
70 | let video4k: string | |
71 | ||
72 | before(async function () { | |
73 | this.timeout(30_000) | |
74 | ||
75 | // Run servers | |
76 | servers = await flushAndRunMultipleServers(2) | |
77 | ||
78 | await setAccessTokensToServers(servers) | |
79 | ||
80 | await doubleFollow(servers[0], servers[1]) | |
81 | ||
82 | await updateConfigForTranscoding(servers[1]) | |
83 | }) | |
84 | ||
85 | describe('Basic transcoding (or not)', function () { | |
86 | ||
87 | it('Should not transcode video on server 1', async function () { | |
88 | this.timeout(60_000) | |
89 | ||
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) | |
96 | ||
97 | await waitJobs(servers) | |
98 | ||
99 | for (const server of servers) { | |
100 | const res = await getVideosList(server.url) | |
101 | const video = res.body.data[0] | |
102 | ||
103 | const res2 = await getVideo(server.url, video.id) | |
104 | const videoDetails = res2.body | |
105 | expect(videoDetails.files).to.have.lengthOf(1) | |
106 | ||
107 | const magnetUri = videoDetails.files[0].magnetUri | |
108 | expect(magnetUri).to.match(/\.webm/) | |
109 | ||
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 | }) | |
116 | ||
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) | |
131 | ||
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 | |
135 | ||
136 | expect(videoDetails.files).to.have.lengthOf(4) | |
137 | ||
138 | const magnetUri = videoDetails.files[0].magnetUri | |
139 | expect(magnetUri).to.match(/\.mp4/) | |
140 | ||
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 | }) | |
147 | ||
148 | it('Should wait for transcoding before publishing the video', async function () { | |
149 | this.timeout(160_000) | |
150 | ||
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 | } | |
184 | ||
185 | await waitJobs(servers) | |
186 | ||
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 | |
191 | ||
192 | const res2 = await getVideo(server.url, videoToFind.id) | |
193 | const videoDetails: VideoDetails = res2.body | |
194 | ||
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 | }) | |
200 | ||
201 | it('Should accept and transcode additional extensions', async function () { | |
202 | this.timeout(300_000) | |
203 | ||
204 | let tempFixturePath: string | |
205 | ||
206 | { | |
207 | tempFixturePath = await generateHighBitrateVideo() | |
208 | ||
209 | const bitrate = await getVideoFileBitrate(tempFixturePath) | |
210 | expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS)) | |
211 | } | |
212 | ||
213 | for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) { | |
214 | const videoAttributes = { | |
215 | name: fixture, | |
216 | fixture | |
217 | } | |
218 | ||
219 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
220 | ||
221 | await waitJobs(servers) | |
222 | ||
223 | for (const server of servers) { | |
224 | const res = await getVideosList(server.url) | |
225 | ||
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 | |
229 | ||
230 | expect(videoDetails.files).to.have.lengthOf(4) | |
231 | ||
232 | const magnetUri = videoDetails.files[0].magnetUri | |
233 | expect(magnetUri).to.contain('.mp4') | |
234 | } | |
235 | } | |
236 | }) | |
237 | ||
238 | it('Should transcode a 4k video', async function () { | |
239 | this.timeout(200_000) | |
240 | ||
241 | const videoAttributes = { | |
242 | name: '4k video', | |
243 | fixture: 'video_short_4k.mp4' | |
244 | } | |
245 | ||
246 | const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
247 | video4k = resUpload.body.video.uuid | |
248 | ||
249 | await waitJobs(servers) | |
250 | ||
251 | const resolutions = [ 240, 360, 480, 720, 1080, 1440, 2160 ] | |
252 | ||
253 | for (const server of servers) { | |
254 | const res = await getVideo(server.url, video4k) | |
255 | const videoDetails: VideoDetails = res.body | |
256 | ||
257 | expect(videoDetails.files).to.have.lengthOf(resolutions.length) | |
258 | ||
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 | } | |
263 | } | |
264 | }) | |
265 | }) | |
266 | ||
267 | describe('Audio transcoding', function () { | |
268 | ||
269 | it('Should transcode high bit rate mp3 to proper bit rate', async function () { | |
270 | this.timeout(60_000) | |
271 | ||
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) | |
277 | ||
278 | await waitJobs(servers) | |
279 | ||
280 | for (const server of servers) { | |
281 | const res = await getVideosList(server.url) | |
282 | ||
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 | |
286 | ||
287 | expect(videoDetails.files).to.have.lengthOf(4) | |
288 | ||
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 | } | |
298 | } | |
299 | }) | |
300 | ||
301 | it('Should transcode video with no audio and have no audio itself', async function () { | |
302 | this.timeout(60_000) | |
303 | ||
304 | const videoAttributes = { | |
305 | name: 'no_audio', | |
306 | fixture: 'video_short_no_audio.mp4' | |
307 | } | |
308 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
309 | ||
310 | await waitJobs(servers) | |
311 | ||
312 | for (const server of servers) { | |
313 | const res = await getVideosList(server.url) | |
314 | ||
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 | |
318 | ||
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 | }) | |
325 | ||
326 | it('Should leave the audio untouched, but properly transcode the video', async function () { | |
327 | this.timeout(60_000) | |
328 | ||
329 | const videoAttributes = { | |
330 | name: 'untouched_audio', | |
331 | fixture: 'video_short.mp4' | |
332 | } | |
333 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
334 | ||
335 | await waitJobs(servers) | |
336 | ||
337 | for (const server of servers) { | |
338 | const res = await getVideosList(server.url) | |
339 | ||
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 | |
343 | ||
344 | expect(videoDetails.files).to.have.lengthOf(4) | |
345 | ||
346 | const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) | |
347 | const fixtureVideoProbe = await getAudioStream(fixturePath) | |
348 | const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) | |
349 | ||
350 | const videoProbe = await getAudioStream(path) | |
351 | ||
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 | }) | |
361 | ||
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 | }) | |
382 | ||
383 | it('Should merge an audio file with the preview file', async function () { | |
384 | this.timeout(60_000) | |
385 | ||
386 | const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } | |
387 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg) | |
388 | ||
389 | await waitJobs(servers) | |
390 | ||
391 | for (const server of servers) { | |
392 | const res = await getVideosList(server.url) | |
393 | ||
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 | |
397 | ||
398 | expect(videoDetails.files).to.have.lengthOf(1) | |
399 | ||
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 }) | |
402 | ||
403 | const magnetUri = videoDetails.files[0].magnetUri | |
404 | expect(magnetUri).to.contain('.mp4') | |
405 | } | |
406 | }) | |
407 | ||
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) | |
413 | ||
414 | await waitJobs(servers) | |
415 | ||
416 | for (const server of servers) { | |
417 | const res = await getVideosList(server.url) | |
418 | ||
419 | const video = res.body.data.find(v => v.name === 'audio_without_preview') | |
420 | const res2 = await getVideo(server.url, video.id) | |
421 | const videoDetails = res2.body | |
422 | ||
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 }) | |
427 | ||
428 | const magnetUri = videoDetails.files[0].magnetUri | |
429 | expect(magnetUri).to.contain('.mp4') | |
430 | } | |
431 | }) | |
432 | ||
433 | it('Should upload an audio file and create an audio version only', async function () { | |
434 | this.timeout(60_000) | |
435 | ||
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 | }) | |
447 | ||
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) | |
450 | ||
451 | await waitJobs(servers) | |
452 | ||
453 | for (const server of servers) { | |
454 | const res2 = await getVideo(server.url, resVideo.body.video.id) | |
455 | const videoDetails: VideoDetails = res2.body | |
456 | ||
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 | } | |
462 | ||
463 | await updateConfigForTranscoding(servers[1]) | |
464 | }) | |
465 | }) | |
466 | ||
467 | describe('Framerate', function () { | |
468 | ||
469 | it('Should transcode a 60 FPS video', async function () { | |
470 | this.timeout(60_000) | |
471 | ||
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) | |
478 | ||
479 | await waitJobs(servers) | |
480 | ||
481 | for (const server of servers) { | |
482 | const res = await getVideosList(server.url) | |
483 | ||
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 | |
487 | ||
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) | |
493 | ||
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) | |
497 | ||
498 | expect(fps).to.be.below(31) | |
499 | } | |
500 | ||
501 | const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4')) | |
502 | const fps = await getVideoFileFPS(path) | |
503 | ||
504 | expect(fps).to.be.above(58).and.below(62) | |
505 | } | |
506 | }) | |
507 | ||
508 | it('Should downscale to the closest divisor standard framerate', async function () { | |
509 | this.timeout(200_000) | |
510 | ||
511 | let tempFixturePath: string | |
512 | ||
513 | { | |
514 | tempFixturePath = await generateVideoWithFramerate(59) | |
515 | ||
516 | const fps = await getVideoFileFPS(tempFixturePath) | |
517 | expect(fps).to.be.equal(59) | |
518 | } | |
519 | ||
520 | const videoAttributes = { | |
521 | name: '59fps video', | |
522 | description: '59fps video', | |
523 | fixture: tempFixturePath | |
524 | } | |
525 | ||
526 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
527 | ||
528 | await waitJobs(servers) | |
529 | ||
530 | for (const server of servers) { | |
531 | const res = await getVideosList(server.url) | |
532 | ||
533 | const video = res.body.data.find(v => v.name === videoAttributes.name) | |
534 | ||
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 | } | |
546 | } | |
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 | |
555 | ||
556 | { | |
557 | tempFixturePath = await generateHighBitrateVideo() | |
558 | ||
559 | const bitrate = await getVideoFileBitrate(tempFixturePath) | |
560 | expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS)) | |
561 | } | |
562 | ||
563 | const videoAttributes = { | |
564 | name: 'high bitrate video', | |
565 | description: 'high bitrate video', | |
566 | fixture: tempFixturePath | |
567 | } | |
568 | ||
569 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
570 | ||
571 | await waitJobs(servers) | |
572 | ||
573 | for (const server of servers) { | |
574 | const res = await getVideosList(server.url) | |
575 | ||
576 | const video = res.body.data.find(v => v.name === videoAttributes.name) | |
577 | ||
578 | for (const resolution of [ '240', '360', '480', '720', '1080' ]) { | |
579 | const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4')) | |
580 | ||
581 | const bitrate = await getVideoFileBitrate(path) | |
582 | const fps = await getVideoFileFPS(path) | |
583 | const resolution2 = await getVideoFileResolution(path) | |
584 | ||
585 | expect(resolution2.videoFileResolution.toString()).to.equal(resolution) | |
586 | expect(bitrate).to.be.below(getMaxBitrate(resolution2.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)) | |
587 | } | |
588 | } | |
589 | }) | |
590 | ||
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 | } | |
609 | } | |
610 | await updateCustomSubConfig(servers[1].url, servers[1].accessToken, config) | |
611 | ||
612 | const videoAttributes = { | |
613 | name: 'low bitrate', | |
614 | fixture: 'low-bitrate.mp4' | |
615 | } | |
616 | ||
617 | const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
618 | const videoUUID = resUpload.body.video.uuid | |
619 | ||
620 | await waitJobs(servers) | |
621 | ||
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) | |
627 | } | |
628 | }) | |
629 | }) | |
630 | ||
631 | describe('FFprobe', function () { | |
632 | ||
633 | it('Should provide valid ffprobe data', async function () { | |
634 | this.timeout(160_000) | |
635 | ||
636 | const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'ffprobe data' })).uuid | |
637 | await waitJobs(servers) | |
638 | ||
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 | } | |
668 | ||
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 | }) | |
689 | ||
690 | it('Should correctly detect if quick transcode is possible', async function () { | |
691 | this.timeout(10_000) | |
692 | ||
693 | expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.mp4'))).to.be.true | |
694 | expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.webm'))).to.be.false | |
695 | }) | |
696 | }) | |
697 | ||
698 | describe('Transcoding job queue', function () { | |
699 | ||
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 | }) | |
709 | ||
710 | const jobs = res.body.data as Job[] | |
711 | ||
712 | const transcodingJobs = jobs.filter(j => j.data.videoUUID === video4k) | |
713 | ||
714 | expect(transcodingJobs).to.have.lengthOf(14) | |
715 | ||
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') | |
719 | ||
720 | expect(hlsJobs).to.have.lengthOf(7) | |
721 | expect(webtorrentJobs).to.have.lengthOf(6) | |
722 | expect(optimizeJobs).to.have.lengthOf(1) | |
723 | ||
724 | for (const j of optimizeJobs) { | |
725 | expect(j.priority).to.be.greaterThan(11) | |
726 | expect(j.priority).to.be.lessThan(50) | |
727 | } | |
728 | ||
729 | for (const j of hlsJobs.concat(webtorrentJobs)) { | |
730 | expect(j.priority).to.be.greaterThan(100) | |
731 | expect(j.priority).to.be.lessThan(150) | |
732 | } | |
733 | }) | |
734 | }) | |
735 | ||
736 | after(async function () { | |
737 | await cleanupTests(servers) | |
738 | }) | |
739 | }) |