]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
0e1dc3e7 | 2 | |
a7ba16b6 | 3 | import 'mocha' |
daf6e480 C |
4 | import * as chai from 'chai' |
5 | import { FfprobeData } from 'fluent-ffmpeg' | |
7160878c | 6 | import { omit } from 'lodash' |
daf6e480 | 7 | import { join } from 'path' |
6939cbac | 8 | import { Job } from '@shared/models' |
daf6e480 | 9 | import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' |
6939cbac | 10 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
0e1dc3e7 | 11 | import { |
7243f84d | 12 | buildAbsoluteFixturePath, |
ca5c612b | 13 | buildServerDirectory, |
7243f84d | 14 | cleanupTests, |
2186386c C |
15 | doubleFollow, |
16 | flushAndRunMultipleServers, | |
d175a6f7 | 17 | generateHighBitrateVideo, |
837666fe | 18 | generateVideoWithFramerate, |
6939cbac | 19 | getJobsListPaginationAndSort, |
2186386c | 20 | getMyVideos, |
d218e7de | 21 | getServerFileSize, |
2186386c | 22 | getVideo, |
8319d6ae | 23 | getVideoFileMetadataUrl, |
2186386c | 24 | getVideosList, |
b345a804 | 25 | makeGetRequest, |
2186386c C |
26 | ServerInfo, |
27 | setAccessTokensToServers, | |
d218e7de | 28 | updateCustomSubConfig, |
daf6e480 C |
29 | uploadVideo, |
30 | uploadVideoAndGetId, | |
1600235a | 31 | waitJobs, |
d175a6f7 | 32 | webtorrentAdd |
94565d52 | 33 | } from '../../../../shared/extra-utils' |
daf6e480 C |
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' | |
a7ba16b6 C |
43 | |
44 | const expect = chai.expect | |
0e1dc3e7 | 45 | |
40930fda C |
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 | ||
0e1dc3e7 C |
68 | describe('Test video transcoding', function () { |
69 | let servers: ServerInfo[] = [] | |
6939cbac | 70 | let video4k: string |
0e1dc3e7 C |
71 | |
72 | before(async function () { | |
454c20fa | 73 | this.timeout(30_000) |
0e1dc3e7 C |
74 | |
75 | // Run servers | |
76 | servers = await flushAndRunMultipleServers(2) | |
77 | ||
78 | await setAccessTokensToServers(servers) | |
b2977eec C |
79 | |
80 | await doubleFollow(servers[0], servers[1]) | |
40930fda C |
81 | |
82 | await updateConfigForTranscoding(servers[1]) | |
0e1dc3e7 C |
83 | }) |
84 | ||
40930fda | 85 | describe('Basic transcoding (or not)', function () { |
0e1dc3e7 | 86 | |
40930fda C |
87 | it('Should not transcode video on server 1', async function () { |
88 | this.timeout(60_000) | |
0e1dc3e7 | 89 | |
40930fda C |
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) | |
0e1dc3e7 | 96 | |
40930fda | 97 | await waitJobs(servers) |
40298b02 | 98 | |
40930fda C |
99 | for (const server of servers) { |
100 | const res = await getVideosList(server.url) | |
101 | const video = res.body.data[0] | |
5f04dd2f | 102 | |
40930fda C |
103 | const res2 = await getVideo(server.url, video.id) |
104 | const videoDetails = res2.body | |
105 | expect(videoDetails.files).to.have.lengthOf(1) | |
0e1dc3e7 | 106 | |
40930fda C |
107 | const magnetUri = videoDetails.files[0].magnetUri |
108 | expect(magnetUri).to.match(/\.webm/) | |
0e1dc3e7 | 109 | |
40930fda C |
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 | }) | |
0e1dc3e7 | 116 | |
40930fda C |
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) | |
0e1dc3e7 | 131 | |
40930fda C |
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 | |
0e1dc3e7 | 135 | |
40930fda | 136 | expect(videoDetails.files).to.have.lengthOf(4) |
0e1dc3e7 | 137 | |
40930fda C |
138 | const magnetUri = videoDetails.files[0].magnetUri |
139 | expect(magnetUri).to.match(/\.mp4/) | |
5f04dd2f | 140 | |
40930fda C |
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 | }) | |
40298b02 | 147 | |
40930fda C |
148 | it('Should wait for transcoding before publishing the video', async function () { |
149 | this.timeout(160_000) | |
0e1dc3e7 | 150 | |
40930fda C |
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 | } | |
0e1dc3e7 | 184 | |
40930fda | 185 | await waitJobs(servers) |
7160878c | 186 | |
40930fda C |
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 | |
7160878c | 191 | |
40930fda C |
192 | const res2 = await getVideo(server.url, videoToFind.id) |
193 | const videoDetails: VideoDetails = res2.body | |
7160878c | 194 | |
40930fda C |
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 | }) | |
7160878c | 200 | |
40930fda C |
201 | it('Should accept and transcode additional extensions', async function () { |
202 | this.timeout(300_000) | |
7160878c | 203 | |
40930fda | 204 | let tempFixturePath: string |
7160878c | 205 | |
40930fda C |
206 | { |
207 | tempFixturePath = await generateHighBitrateVideo() | |
7160878c | 208 | |
40930fda C |
209 | const bitrate = await getVideoFileBitrate(tempFixturePath) |
210 | expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS)) | |
b2977eec | 211 | } |
7160878c | 212 | |
40930fda C |
213 | for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) { |
214 | const videoAttributes = { | |
215 | name: fixture, | |
216 | fixture | |
217 | } | |
7160878c | 218 | |
40930fda | 219 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) |
7160878c | 220 | |
40930fda | 221 | await waitJobs(servers) |
7160878c | 222 | |
40930fda C |
223 | for (const server of servers) { |
224 | const res = await getVideosList(server.url) | |
7160878c | 225 | |
40930fda C |
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 | |
7160878c | 229 | |
40930fda | 230 | expect(videoDetails.files).to.have.lengthOf(4) |
7160878c | 231 | |
40930fda C |
232 | const magnetUri = videoDetails.files[0].magnetUri |
233 | expect(magnetUri).to.contain('.mp4') | |
234 | } | |
235 | } | |
236 | }) | |
7160878c | 237 | |
40930fda C |
238 | it('Should transcode a 4k video', async function () { |
239 | this.timeout(200_000) | |
7160878c | 240 | |
40930fda C |
241 | const videoAttributes = { |
242 | name: '4k video', | |
243 | fixture: 'video_short_4k.mp4' | |
244 | } | |
7160878c | 245 | |
40930fda C |
246 | const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) |
247 | video4k = resUpload.body.video.uuid | |
b2977eec | 248 | |
40930fda | 249 | await waitJobs(servers) |
b2977eec | 250 | |
40930fda | 251 | const resolutions = [ 240, 360, 480, 720, 1080, 1440, 2160 ] |
ca5c612b | 252 | |
40930fda C |
253 | for (const server of servers) { |
254 | const res = await getVideo(server.url, video4k) | |
255 | const videoDetails: VideoDetails = res.body | |
ca5c612b | 256 | |
40930fda | 257 | expect(videoDetails.files).to.have.lengthOf(resolutions.length) |
ca5c612b | 258 | |
40930fda C |
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 | } | |
b2977eec | 263 | } |
40930fda | 264 | }) |
7160878c RK |
265 | }) |
266 | ||
40930fda | 267 | describe('Audio transcoding', function () { |
73c69591 | 268 | |
40930fda C |
269 | it('Should transcode high bit rate mp3 to proper bit rate', async function () { |
270 | this.timeout(60_000) | |
73c69591 | 271 | |
40930fda C |
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) | |
73c69591 | 277 | |
40930fda | 278 | await waitJobs(servers) |
73c69591 | 279 | |
40930fda C |
280 | for (const server of servers) { |
281 | const res = await getVideosList(server.url) | |
73c69591 | 282 | |
40930fda C |
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 | |
73c69591 | 286 | |
40930fda | 287 | expect(videoDetails.files).to.have.lengthOf(4) |
73c69591 | 288 | |
40930fda C |
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 | } | |
b2977eec | 298 | } |
40930fda | 299 | }) |
3a6f351b | 300 | |
40930fda C |
301 | it('Should transcode video with no audio and have no audio itself', async function () { |
302 | this.timeout(60_000) | |
2186386c | 303 | |
2186386c | 304 | const videoAttributes = { |
40930fda C |
305 | name: 'no_audio', |
306 | fixture: 'video_short_no_audio.mp4' | |
307 | } | |
308 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
2186386c | 309 | |
40930fda | 310 | await waitJobs(servers) |
2186386c | 311 | |
40930fda C |
312 | for (const server of servers) { |
313 | const res = await getVideosList(server.url) | |
2186386c | 314 | |
40930fda C |
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 | |
2186386c | 318 | |
40930fda C |
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 | }) | |
2186386c | 325 | |
40930fda C |
326 | it('Should leave the audio untouched, but properly transcode the video', async function () { |
327 | this.timeout(60_000) | |
edb4ffc7 | 328 | |
40930fda C |
329 | const videoAttributes = { |
330 | name: 'untouched_audio', | |
331 | fixture: 'video_short.mp4' | |
332 | } | |
333 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
74cd011b | 334 | |
40930fda | 335 | await waitJobs(servers) |
edb4ffc7 | 336 | |
40930fda C |
337 | for (const server of servers) { |
338 | const res = await getVideosList(server.url) | |
edb4ffc7 | 339 | |
40930fda C |
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 | |
edb4ffc7 | 343 | |
40930fda | 344 | expect(videoDetails.files).to.have.lengthOf(4) |
edb4ffc7 | 345 | |
40930fda C |
346 | const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) |
347 | const fixtureVideoProbe = await getAudioStream(fixturePath) | |
348 | const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) | |
edb4ffc7 | 349 | |
40930fda | 350 | const videoProbe = await getAudioStream(path) |
edb4ffc7 | 351 | |
40930fda C |
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 | }) | |
edb4ffc7 | 361 | |
40930fda C |
362 | describe('Audio upload', function () { |
363 | ||
f6d6e7f8 | 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 | } | |
40930fda | 381 | } |
f6d6e7f8 | 382 | }) |
40930fda | 383 | }) |
edb4ffc7 | 384 | |
f6d6e7f8 | 385 | it('Should merge an audio file with the preview file', async function () { |
386 | this.timeout(60_000) | |
edb4ffc7 | 387 | |
f6d6e7f8 | 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) | |
14e2014a | 390 | |
f6d6e7f8 | 391 | await waitJobs(servers) |
7ed2c1a4 | 392 | |
f6d6e7f8 | 393 | for (const server of servers) { |
394 | const res = await getVideosList(server.url) | |
7ed2c1a4 | 395 | |
f6d6e7f8 | 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 | |
7ed2c1a4 | 399 | |
f6d6e7f8 | 400 | expect(videoDetails.files).to.have.lengthOf(1) |
14e2014a | 401 | |
f6d6e7f8 | 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 }) | |
40930fda | 404 | |
f6d6e7f8 | 405 | const magnetUri = videoDetails.files[0].magnetUri |
406 | expect(magnetUri).to.contain('.mp4') | |
407 | } | |
408 | }) | |
14e2014a | 409 | |
f6d6e7f8 | 410 | it('Should upload an audio file and choose a default background image', async function () { |
411 | this.timeout(60_000) | |
14e2014a | 412 | |
f6d6e7f8 | 413 | const videoAttributesArg = { name: 'audio_without_preview', fixture: 'sample.ogg' } |
414 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) | |
14e2014a | 415 | |
f6d6e7f8 | 416 | await waitJobs(servers) |
14e2014a | 417 | |
f6d6e7f8 | 418 | for (const server of servers) { |
419 | const res = await getVideosList(server.url) | |
40930fda | 420 | |
f6d6e7f8 | 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 | |
14e2014a | 424 | |
f6d6e7f8 | 425 | expect(videoDetails.files).to.have.lengthOf(1) |
14e2014a | 426 | |
f6d6e7f8 | 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 }) | |
7ed2c1a4 | 429 | |
f6d6e7f8 | 430 | const magnetUri = videoDetails.files[0].magnetUri |
431 | expect(magnetUri).to.contain('.mp4') | |
40930fda C |
432 | } |
433 | }) | |
7ed2c1a4 | 434 | |
f6d6e7f8 | 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 | }) | |
b345a804 | 449 | |
f6d6e7f8 | 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) | |
b345a804 | 452 | |
f6d6e7f8 | 453 | await waitJobs(servers) |
b345a804 | 454 | |
f6d6e7f8 | 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 | } | |
40930fda | 463 | } |
b345a804 | 464 | |
f6d6e7f8 | 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') | |
40930fda C |
475 | }) |
476 | }) | |
b345a804 | 477 | |
40930fda | 478 | describe('Framerate', function () { |
b345a804 | 479 | |
40930fda C |
480 | it('Should transcode a 60 FPS video', async function () { |
481 | this.timeout(60_000) | |
b345a804 | 482 | |
40930fda C |
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) | |
b345a804 | 489 | |
40930fda | 490 | await waitJobs(servers) |
b345a804 | 491 | |
40930fda C |
492 | for (const server of servers) { |
493 | const res = await getVideosList(server.url) | |
b345a804 | 494 | |
40930fda C |
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 | |
b345a804 | 498 | |
40930fda C |
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) | |
b345a804 | 504 | |
40930fda C |
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) | |
b345a804 | 508 | |
40930fda C |
509 | expect(fps).to.be.below(31) |
510 | } | |
b345a804 | 511 | |
40930fda C |
512 | const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4')) |
513 | const fps = await getVideoFileFPS(path) | |
b345a804 | 514 | |
40930fda C |
515 | expect(fps).to.be.above(58).and.below(62) |
516 | } | |
517 | }) | |
b345a804 | 518 | |
40930fda C |
519 | it('Should downscale to the closest divisor standard framerate', async function () { |
520 | this.timeout(200_000) | |
837666fe | 521 | |
40930fda | 522 | let tempFixturePath: string |
837666fe | 523 | |
40930fda C |
524 | { |
525 | tempFixturePath = await generateVideoWithFramerate(59) | |
837666fe | 526 | |
40930fda C |
527 | const fps = await getVideoFileFPS(tempFixturePath) |
528 | expect(fps).to.be.equal(59) | |
529 | } | |
837666fe | 530 | |
40930fda C |
531 | const videoAttributes = { |
532 | name: '59fps video', | |
533 | description: '59fps video', | |
534 | fixture: tempFixturePath | |
535 | } | |
837666fe | 536 | |
40930fda | 537 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) |
837666fe | 538 | |
40930fda | 539 | await waitJobs(servers) |
837666fe | 540 | |
40930fda C |
541 | for (const server of servers) { |
542 | const res = await getVideosList(server.url) | |
837666fe | 543 | |
40930fda | 544 | const video = res.body.data.find(v => v.name === videoAttributes.name) |
837666fe | 545 | |
40930fda C |
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 | } | |
c7f36e4f | 557 | } |
40930fda C |
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 | |
c7f36e4f C |
566 | |
567 | { | |
40930fda | 568 | tempFixturePath = await generateHighBitrateVideo() |
837666fe | 569 | |
40930fda C |
570 | const bitrate = await getVideoFileBitrate(tempFixturePath) |
571 | expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS)) | |
d218e7de | 572 | } |
d218e7de | 573 | |
40930fda C |
574 | const videoAttributes = { |
575 | name: 'high bitrate video', | |
576 | description: 'high bitrate video', | |
577 | fixture: tempFixturePath | |
578 | } | |
d218e7de | 579 | |
40930fda | 580 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) |
d218e7de | 581 | |
40930fda | 582 | await waitJobs(servers) |
d218e7de | 583 | |
40930fda C |
584 | for (const server of servers) { |
585 | const res = await getVideosList(server.url) | |
d218e7de | 586 | |
40930fda | 587 | const video = res.body.data.find(v => v.name === videoAttributes.name) |
8319d6ae | 588 | |
40930fda C |
589 | for (const resolution of [ '240', '360', '480', '720', '1080' ]) { |
590 | const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4')) | |
8319d6ae | 591 | |
40930fda C |
592 | const bitrate = await getVideoFileBitrate(path) |
593 | const fps = await getVideoFileFPS(path) | |
594 | const resolution2 = await getVideoFileResolution(path) | |
8319d6ae | 595 | |
40930fda C |
596 | expect(resolution2.videoFileResolution.toString()).to.equal(resolution) |
597 | expect(bitrate).to.be.below(getMaxBitrate(resolution2.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)) | |
598 | } | |
7b81edc8 | 599 | } |
40930fda | 600 | }) |
8319d6ae | 601 | |
40930fda C |
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 | } | |
8319d6ae | 620 | } |
40930fda | 621 | await updateCustomSubConfig(servers[1].url, servers[1].accessToken, config) |
7b81edc8 | 622 | |
40930fda C |
623 | const videoAttributes = { |
624 | name: 'low bitrate', | |
625 | fixture: 'low-bitrate.mp4' | |
626 | } | |
8319d6ae | 627 | |
40930fda C |
628 | const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) |
629 | const videoUUID = resUpload.body.video.uuid | |
7b81edc8 | 630 | |
40930fda | 631 | await waitJobs(servers) |
8319d6ae | 632 | |
40930fda C |
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) | |
8319d6ae | 638 | } |
40930fda | 639 | }) |
8319d6ae RK |
640 | }) |
641 | ||
40930fda | 642 | describe('FFprobe', function () { |
f5961a8c | 643 | |
40930fda C |
644 | it('Should provide valid ffprobe data', async function () { |
645 | this.timeout(160_000) | |
f5961a8c | 646 | |
40930fda C |
647 | const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'ffprobe data' })).uuid |
648 | await waitJobs(servers) | |
f5961a8c | 649 | |
40930fda C |
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 | } | |
f5961a8c | 679 | |
40930fda C |
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 | }) | |
f5961a8c | 700 | |
40930fda C |
701 | it('Should correctly detect if quick transcode is possible', async function () { |
702 | this.timeout(10_000) | |
f5961a8c | 703 | |
40930fda C |
704 | expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.mp4'))).to.be.true |
705 | expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.webm'))).to.be.false | |
706 | }) | |
f5961a8c C |
707 | }) |
708 | ||
40930fda | 709 | describe('Transcoding job queue', function () { |
6939cbac | 710 | |
40930fda C |
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 | }) | |
6939cbac | 720 | |
40930fda | 721 | const jobs = res.body.data as Job[] |
6939cbac | 722 | |
40930fda | 723 | const transcodingJobs = jobs.filter(j => j.data.videoUUID === video4k) |
6939cbac | 724 | |
40930fda | 725 | expect(transcodingJobs).to.have.lengthOf(14) |
6939cbac | 726 | |
40930fda C |
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') | |
6939cbac | 730 | |
40930fda C |
731 | expect(hlsJobs).to.have.lengthOf(7) |
732 | expect(webtorrentJobs).to.have.lengthOf(6) | |
733 | expect(optimizeJobs).to.have.lengthOf(1) | |
6939cbac | 734 | |
a6e37eeb | 735 | for (const j of optimizeJobs.concat(hlsJobs.concat(webtorrentJobs))) { |
40930fda C |
736 | expect(j.priority).to.be.greaterThan(100) |
737 | expect(j.priority).to.be.lessThan(150) | |
738 | } | |
739 | }) | |
6939cbac C |
740 | }) |
741 | ||
7c3b7976 C |
742 | after(async function () { |
743 | await cleanupTests(servers) | |
0e1dc3e7 C |
744 | }) |
745 | }) |