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