]>
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 | function runSuite (mode: 'legacy' | 'resumable') { | |
365 | ||
366 | before(async function () { | |
367 | await updateCustomSubConfig(servers[1].url, servers[1].accessToken, { | |
368 | transcoding: { | |
369 | hls: { enabled: true }, | |
370 | webtorrent: { enabled: true }, | |
371 | resolutions: { | |
372 | '0p': false, | |
373 | '240p': false, | |
374 | '360p': false, | |
375 | '480p': false, | |
376 | '720p': false, | |
377 | '1080p': false, | |
378 | '1440p': false, | |
379 | '2160p': false | |
380 | } | |
381 | } | |
382 | }) | |
383 | }) | |
384 | ||
385 | it('Should merge an audio file with the preview file', async function () { | |
386 | this.timeout(60_000) | |
387 | ||
388 | const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } | |
389 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) | |
390 | ||
391 | await waitJobs(servers) | |
392 | ||
393 | for (const server of servers) { | |
394 | const res = await getVideosList(server.url) | |
395 | ||
396 | const video = res.body.data.find(v => v.name === 'audio_with_preview') | |
397 | const res2 = await getVideo(server.url, video.id) | |
398 | const videoDetails: VideoDetails = res2.body | |
399 | ||
400 | expect(videoDetails.files).to.have.lengthOf(1) | |
401 | ||
402 | await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 }) | |
403 | await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 }) | |
404 | ||
405 | const magnetUri = videoDetails.files[0].magnetUri | |
406 | expect(magnetUri).to.contain('.mp4') | |
407 | } | |
408 | }) | |
409 | ||
410 | it('Should upload an audio file and choose a default background image', async function () { | |
411 | this.timeout(60_000) | |
412 | ||
413 | const videoAttributesArg = { name: 'audio_without_preview', fixture: 'sample.ogg' } | |
414 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) | |
415 | ||
416 | await waitJobs(servers) | |
417 | ||
418 | for (const server of servers) { | |
419 | const res = await getVideosList(server.url) | |
420 | ||
421 | const video = res.body.data.find(v => v.name === 'audio_without_preview') | |
422 | const res2 = await getVideo(server.url, video.id) | |
423 | const videoDetails = res2.body | |
424 | ||
425 | expect(videoDetails.files).to.have.lengthOf(1) | |
426 | ||
427 | await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 }) | |
428 | await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 }) | |
429 | ||
430 | const magnetUri = videoDetails.files[0].magnetUri | |
431 | expect(magnetUri).to.contain('.mp4') | |
432 | } | |
433 | }) | |
434 | ||
435 | it('Should upload an audio file and create an audio version only', async function () { | |
436 | this.timeout(60_000) | |
437 | ||
438 | await updateCustomSubConfig(servers[1].url, servers[1].accessToken, { | |
439 | transcoding: { | |
440 | hls: { enabled: true }, | |
441 | webtorrent: { enabled: true }, | |
442 | resolutions: { | |
443 | '0p': true, | |
444 | '240p': false, | |
445 | '360p': false | |
446 | } | |
447 | } | |
448 | }) | |
449 | ||
450 | const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } | |
451 | const resVideo = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) | |
452 | ||
453 | await waitJobs(servers) | |
454 | ||
455 | for (const server of servers) { | |
456 | const res2 = await getVideo(server.url, resVideo.body.video.id) | |
457 | const videoDetails: VideoDetails = res2.body | |
458 | ||
459 | for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) { | |
460 | expect(files).to.have.lengthOf(2) | |
461 | expect(files.find(f => f.resolution.id === 0)).to.not.be.undefined | |
462 | } | |
463 | } | |
464 | ||
465 | await updateConfigForTranscoding(servers[1]) | |
466 | }) | |
467 | } | |
468 | ||
469 | describe('Legacy upload', function () { | |
470 | runSuite('legacy') | |
471 | }) | |
472 | ||
473 | describe('Resumable upload', function () { | |
474 | runSuite('resumable') | |
475 | }) | |
476 | }) | |
477 | ||
478 | describe('Framerate', function () { | |
479 | ||
480 | it('Should transcode a 60 FPS video', async function () { | |
481 | this.timeout(60_000) | |
482 | ||
483 | const videoAttributes = { | |
484 | name: 'my super 30fps name for server 2', | |
485 | description: 'my super 30fps description for server 2', | |
486 | fixture: '60fps_720p_small.mp4' | |
487 | } | |
488 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
489 | ||
490 | await waitJobs(servers) | |
491 | ||
492 | for (const server of servers) { | |
493 | const res = await getVideosList(server.url) | |
494 | ||
495 | const video = res.body.data.find(v => v.name === videoAttributes.name) | |
496 | const res2 = await getVideo(server.url, video.id) | |
497 | const videoDetails: VideoDetails = res2.body | |
498 | ||
499 | expect(videoDetails.files).to.have.lengthOf(4) | |
500 | expect(videoDetails.files[0].fps).to.be.above(58).and.below(62) | |
501 | expect(videoDetails.files[1].fps).to.be.below(31) | |
502 | expect(videoDetails.files[2].fps).to.be.below(31) | |
503 | expect(videoDetails.files[3].fps).to.be.below(31) | |
504 | ||
505 | for (const resolution of [ '240', '360', '480' ]) { | |
506 | const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4')) | |
507 | const fps = await getVideoFileFPS(path) | |
508 | ||
509 | expect(fps).to.be.below(31) | |
510 | } | |
511 | ||
512 | const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4')) | |
513 | const fps = await getVideoFileFPS(path) | |
514 | ||
515 | expect(fps).to.be.above(58).and.below(62) | |
516 | } | |
517 | }) | |
518 | ||
519 | it('Should downscale to the closest divisor standard framerate', async function () { | |
520 | this.timeout(200_000) | |
521 | ||
522 | let tempFixturePath: string | |
523 | ||
524 | { | |
525 | tempFixturePath = await generateVideoWithFramerate(59) | |
526 | ||
527 | const fps = await getVideoFileFPS(tempFixturePath) | |
528 | expect(fps).to.be.equal(59) | |
529 | } | |
530 | ||
531 | const videoAttributes = { | |
532 | name: '59fps video', | |
533 | description: '59fps video', | |
534 | fixture: tempFixturePath | |
535 | } | |
536 | ||
537 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
538 | ||
539 | await waitJobs(servers) | |
540 | ||
541 | for (const server of servers) { | |
542 | const res = await getVideosList(server.url) | |
543 | ||
544 | const video = res.body.data.find(v => v.name === videoAttributes.name) | |
545 | ||
546 | { | |
547 | const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) | |
548 | const fps = await getVideoFileFPS(path) | |
549 | expect(fps).to.be.equal(25) | |
550 | } | |
551 | ||
552 | { | |
553 | const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4')) | |
554 | const fps = await getVideoFileFPS(path) | |
555 | expect(fps).to.be.equal(59) | |
556 | } | |
557 | } | |
558 | }) | |
559 | }) | |
560 | ||
561 | describe('Bitrate control', function () { | |
562 | it('Should respect maximum bitrate values', async function () { | |
563 | this.timeout(160_000) | |
564 | ||
565 | let tempFixturePath: string | |
566 | ||
567 | { | |
568 | tempFixturePath = await generateHighBitrateVideo() | |
569 | ||
570 | const bitrate = await getVideoFileBitrate(tempFixturePath) | |
571 | expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS)) | |
572 | } | |
573 | ||
574 | const videoAttributes = { | |
575 | name: 'high bitrate video', | |
576 | description: 'high bitrate video', | |
577 | fixture: tempFixturePath | |
578 | } | |
579 | ||
580 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
581 | ||
582 | await waitJobs(servers) | |
583 | ||
584 | for (const server of servers) { | |
585 | const res = await getVideosList(server.url) | |
586 | ||
587 | const video = res.body.data.find(v => v.name === videoAttributes.name) | |
588 | ||
589 | for (const resolution of [ '240', '360', '480', '720', '1080' ]) { | |
590 | const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4')) | |
591 | ||
592 | const bitrate = await getVideoFileBitrate(path) | |
593 | const fps = await getVideoFileFPS(path) | |
594 | const resolution2 = await getVideoFileResolution(path) | |
595 | ||
596 | expect(resolution2.videoFileResolution.toString()).to.equal(resolution) | |
597 | expect(bitrate).to.be.below(getMaxBitrate(resolution2.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)) | |
598 | } | |
599 | } | |
600 | }) | |
601 | ||
602 | it('Should not transcode to an higher bitrate than the original file', async function () { | |
603 | this.timeout(160_000) | |
604 | ||
605 | const config = { | |
606 | transcoding: { | |
607 | enabled: true, | |
608 | resolutions: { | |
609 | '240p': true, | |
610 | '360p': true, | |
611 | '480p': true, | |
612 | '720p': true, | |
613 | '1080p': true, | |
614 | '1440p': true, | |
615 | '2160p': true | |
616 | }, | |
617 | webtorrent: { enabled: true }, | |
618 | hls: { enabled: true } | |
619 | } | |
620 | } | |
621 | await updateCustomSubConfig(servers[1].url, servers[1].accessToken, config) | |
622 | ||
623 | const videoAttributes = { | |
624 | name: 'low bitrate', | |
625 | fixture: 'low-bitrate.mp4' | |
626 | } | |
627 | ||
628 | const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
629 | const videoUUID = resUpload.body.video.uuid | |
630 | ||
631 | await waitJobs(servers) | |
632 | ||
633 | const resolutions = [ 240, 360, 480, 720, 1080 ] | |
634 | for (const r of resolutions) { | |
635 | const path = `videos/${videoUUID}-${r}.mp4` | |
636 | const size = await getServerFileSize(servers[1], path) | |
637 | expect(size, `${path} not below ${60_000}`).to.be.below(60_000) | |
638 | } | |
639 | }) | |
640 | }) | |
641 | ||
642 | describe('FFprobe', function () { | |
643 | ||
644 | it('Should provide valid ffprobe data', async function () { | |
645 | this.timeout(160_000) | |
646 | ||
647 | const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'ffprobe data' })).uuid | |
648 | await waitJobs(servers) | |
649 | ||
650 | { | |
651 | const path = buildServerDirectory(servers[1], join('videos', videoUUID + '-240.mp4')) | |
652 | const metadata = await getMetadataFromFile(path) | |
653 | ||
654 | // expected format properties | |
655 | for (const p of [ | |
656 | 'tags.encoder', | |
657 | 'format_long_name', | |
658 | 'size', | |
659 | 'bit_rate' | |
660 | ]) { | |
661 | expect(metadata.format).to.have.nested.property(p) | |
662 | } | |
663 | ||
664 | // expected stream properties | |
665 | for (const p of [ | |
666 | 'codec_long_name', | |
667 | 'profile', | |
668 | 'width', | |
669 | 'height', | |
670 | 'display_aspect_ratio', | |
671 | 'avg_frame_rate', | |
672 | 'pix_fmt' | |
673 | ]) { | |
674 | expect(metadata.streams[0]).to.have.nested.property(p) | |
675 | } | |
676 | ||
677 | expect(metadata).to.not.have.nested.property('format.filename') | |
678 | } | |
679 | ||
680 | for (const server of servers) { | |
681 | const res2 = await getVideo(server.url, videoUUID) | |
682 | const videoDetails: VideoDetails = res2.body | |
683 | ||
684 | const videoFiles = videoDetails.files | |
685 | .concat(videoDetails.streamingPlaylists[0].files) | |
686 | expect(videoFiles).to.have.lengthOf(8) | |
687 | ||
688 | for (const file of videoFiles) { | |
689 | expect(file.metadata).to.be.undefined | |
690 | expect(file.metadataUrl).to.exist | |
691 | expect(file.metadataUrl).to.contain(servers[1].url) | |
692 | expect(file.metadataUrl).to.contain(videoUUID) | |
693 | ||
694 | const res3 = await getVideoFileMetadataUrl(file.metadataUrl) | |
695 | const metadata: FfprobeData = res3.body | |
696 | expect(metadata).to.have.nested.property('format.size') | |
697 | } | |
698 | } | |
699 | }) | |
700 | ||
701 | it('Should correctly detect if quick transcode is possible', async function () { | |
702 | this.timeout(10_000) | |
703 | ||
704 | expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.mp4'))).to.be.true | |
705 | expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.webm'))).to.be.false | |
706 | }) | |
707 | }) | |
708 | ||
709 | describe('Transcoding job queue', function () { | |
710 | ||
711 | it('Should have the appropriate priorities for transcoding jobs', async function () { | |
712 | const res = await getJobsListPaginationAndSort({ | |
713 | url: servers[1].url, | |
714 | accessToken: servers[1].accessToken, | |
715 | start: 0, | |
716 | count: 100, | |
717 | sort: '-createdAt', | |
718 | jobType: 'video-transcoding' | |
719 | }) | |
720 | ||
721 | const jobs = res.body.data as Job[] | |
722 | ||
723 | const transcodingJobs = jobs.filter(j => j.data.videoUUID === video4k) | |
724 | ||
725 | expect(transcodingJobs).to.have.lengthOf(14) | |
726 | ||
727 | const hlsJobs = transcodingJobs.filter(j => j.data.type === 'new-resolution-to-hls') | |
728 | const webtorrentJobs = transcodingJobs.filter(j => j.data.type === 'new-resolution-to-webtorrent') | |
729 | const optimizeJobs = transcodingJobs.filter(j => j.data.type === 'optimize-to-webtorrent') | |
730 | ||
731 | expect(hlsJobs).to.have.lengthOf(7) | |
732 | expect(webtorrentJobs).to.have.lengthOf(6) | |
733 | expect(optimizeJobs).to.have.lengthOf(1) | |
734 | ||
735 | for (const j of optimizeJobs.concat(hlsJobs.concat(webtorrentJobs))) { | |
736 | expect(j.priority).to.be.greaterThan(100) | |
737 | expect(j.priority).to.be.lessThan(150) | |
738 | } | |
739 | }) | |
740 | }) | |
741 | ||
742 | after(async function () { | |
743 | await cleanupTests(servers) | |
744 | }) | |
745 | }) |