]>
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, |
2186386c | 19 | getMyVideos, |
d218e7de | 20 | getServerFileSize, |
2186386c | 21 | getVideo, |
8319d6ae | 22 | getVideoFileMetadataUrl, |
2186386c | 23 | getVideosList, |
b345a804 | 24 | makeGetRequest, |
2186386c C |
25 | ServerInfo, |
26 | setAccessTokensToServers, | |
d218e7de | 27 | updateCustomSubConfig, |
daf6e480 C |
28 | uploadVideo, |
29 | uploadVideoAndGetId, | |
1600235a | 30 | waitJobs, |
d175a6f7 | 31 | webtorrentAdd |
94565d52 | 32 | } from '../../../../shared/extra-utils' |
daf6e480 C |
33 | import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos' |
34 | import { | |
35 | canDoQuickTranscode, | |
36 | getAudioStream, | |
37 | getMetadataFromFile, | |
38 | getVideoFileBitrate, | |
39 | getVideoFileFPS, | |
40 | getVideoFileResolution | |
41 | } from '../../../helpers/ffprobe-utils' | |
a7ba16b6 C |
42 | |
43 | const expect = chai.expect | |
0e1dc3e7 | 44 | |
40930fda C |
45 | function updateConfigForTranscoding (server: ServerInfo) { |
46 | return updateCustomSubConfig(server.url, server.accessToken, { | |
47 | transcoding: { | |
48 | enabled: true, | |
49 | allowAdditionalExtensions: true, | |
50 | allowAudioFiles: true, | |
51 | hls: { enabled: true }, | |
52 | webtorrent: { enabled: true }, | |
53 | resolutions: { | |
54 | '0p': false, | |
55 | '240p': true, | |
56 | '360p': true, | |
57 | '480p': true, | |
58 | '720p': true, | |
59 | '1080p': true, | |
60 | '1440p': true, | |
61 | '2160p': true | |
62 | } | |
63 | } | |
64 | }) | |
65 | } | |
66 | ||
0e1dc3e7 C |
67 | describe('Test video transcoding', function () { |
68 | let servers: ServerInfo[] = [] | |
6939cbac | 69 | let video4k: string |
0e1dc3e7 C |
70 | |
71 | before(async function () { | |
454c20fa | 72 | this.timeout(30_000) |
0e1dc3e7 C |
73 | |
74 | // Run servers | |
75 | servers = await flushAndRunMultipleServers(2) | |
76 | ||
77 | await setAccessTokensToServers(servers) | |
b2977eec C |
78 | |
79 | await doubleFollow(servers[0], servers[1]) | |
40930fda C |
80 | |
81 | await updateConfigForTranscoding(servers[1]) | |
0e1dc3e7 C |
82 | }) |
83 | ||
40930fda | 84 | describe('Basic transcoding (or not)', function () { |
0e1dc3e7 | 85 | |
40930fda C |
86 | it('Should not transcode video on server 1', async function () { |
87 | this.timeout(60_000) | |
0e1dc3e7 | 88 | |
40930fda C |
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) | |
0e1dc3e7 | 95 | |
40930fda | 96 | await waitJobs(servers) |
40298b02 | 97 | |
40930fda C |
98 | for (const server of servers) { |
99 | const res = await getVideosList(server.url) | |
100 | const video = res.body.data[0] | |
5f04dd2f | 101 | |
40930fda C |
102 | const res2 = await getVideo(server.url, video.id) |
103 | const videoDetails = res2.body | |
104 | expect(videoDetails.files).to.have.lengthOf(1) | |
0e1dc3e7 | 105 | |
40930fda C |
106 | const magnetUri = videoDetails.files[0].magnetUri |
107 | expect(magnetUri).to.match(/\.webm/) | |
0e1dc3e7 | 108 | |
40930fda C |
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 | }) | |
0e1dc3e7 | 115 | |
40930fda C |
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) | |
0e1dc3e7 | 130 | |
40930fda C |
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 | |
0e1dc3e7 | 134 | |
40930fda | 135 | expect(videoDetails.files).to.have.lengthOf(4) |
0e1dc3e7 | 136 | |
40930fda C |
137 | const magnetUri = videoDetails.files[0].magnetUri |
138 | expect(magnetUri).to.match(/\.mp4/) | |
5f04dd2f | 139 | |
40930fda C |
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 | }) | |
40298b02 | 146 | |
40930fda C |
147 | it('Should wait for transcoding before publishing the video', async function () { |
148 | this.timeout(160_000) | |
0e1dc3e7 | 149 | |
40930fda C |
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 | } | |
0e1dc3e7 | 183 | |
40930fda | 184 | await waitJobs(servers) |
7160878c | 185 | |
40930fda C |
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 | |
7160878c | 190 | |
40930fda C |
191 | const res2 = await getVideo(server.url, videoToFind.id) |
192 | const videoDetails: VideoDetails = res2.body | |
7160878c | 193 | |
40930fda C |
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 | }) | |
7160878c | 199 | |
40930fda C |
200 | it('Should accept and transcode additional extensions', async function () { |
201 | this.timeout(300_000) | |
7160878c | 202 | |
40930fda | 203 | let tempFixturePath: string |
7160878c | 204 | |
40930fda C |
205 | { |
206 | tempFixturePath = await generateHighBitrateVideo() | |
7160878c | 207 | |
40930fda C |
208 | const bitrate = await getVideoFileBitrate(tempFixturePath) |
209 | expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS)) | |
b2977eec | 210 | } |
7160878c | 211 | |
40930fda C |
212 | for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) { |
213 | const videoAttributes = { | |
214 | name: fixture, | |
215 | fixture | |
216 | } | |
7160878c | 217 | |
40930fda | 218 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) |
7160878c | 219 | |
40930fda | 220 | await waitJobs(servers) |
7160878c | 221 | |
40930fda C |
222 | for (const server of servers) { |
223 | const res = await getVideosList(server.url) | |
7160878c | 224 | |
40930fda C |
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 | |
7160878c | 228 | |
40930fda | 229 | expect(videoDetails.files).to.have.lengthOf(4) |
7160878c | 230 | |
40930fda C |
231 | const magnetUri = videoDetails.files[0].magnetUri |
232 | expect(magnetUri).to.contain('.mp4') | |
233 | } | |
234 | } | |
235 | }) | |
7160878c | 236 | |
40930fda C |
237 | it('Should transcode a 4k video', async function () { |
238 | this.timeout(200_000) | |
7160878c | 239 | |
40930fda C |
240 | const videoAttributes = { |
241 | name: '4k video', | |
242 | fixture: 'video_short_4k.mp4' | |
243 | } | |
7160878c | 244 | |
40930fda C |
245 | const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) |
246 | video4k = resUpload.body.video.uuid | |
b2977eec | 247 | |
40930fda | 248 | await waitJobs(servers) |
b2977eec | 249 | |
40930fda | 250 | const resolutions = [ 240, 360, 480, 720, 1080, 1440, 2160 ] |
ca5c612b | 251 | |
40930fda C |
252 | for (const server of servers) { |
253 | const res = await getVideo(server.url, video4k) | |
254 | const videoDetails: VideoDetails = res.body | |
ca5c612b | 255 | |
40930fda | 256 | expect(videoDetails.files).to.have.lengthOf(resolutions.length) |
ca5c612b | 257 | |
40930fda C |
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 | } | |
b2977eec | 262 | } |
40930fda | 263 | }) |
7160878c RK |
264 | }) |
265 | ||
40930fda | 266 | describe('Audio transcoding', function () { |
73c69591 | 267 | |
40930fda C |
268 | it('Should transcode high bit rate mp3 to proper bit rate', async function () { |
269 | this.timeout(60_000) | |
73c69591 | 270 | |
40930fda C |
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) | |
73c69591 | 276 | |
40930fda | 277 | await waitJobs(servers) |
73c69591 | 278 | |
40930fda C |
279 | for (const server of servers) { |
280 | const res = await getVideosList(server.url) | |
73c69591 | 281 | |
40930fda C |
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 | |
73c69591 | 285 | |
40930fda | 286 | expect(videoDetails.files).to.have.lengthOf(4) |
73c69591 | 287 | |
40930fda C |
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 | } | |
b2977eec | 297 | } |
40930fda | 298 | }) |
3a6f351b | 299 | |
40930fda C |
300 | it('Should transcode video with no audio and have no audio itself', async function () { |
301 | this.timeout(60_000) | |
2186386c | 302 | |
2186386c | 303 | const videoAttributes = { |
40930fda C |
304 | name: 'no_audio', |
305 | fixture: 'video_short_no_audio.mp4' | |
306 | } | |
307 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
2186386c | 308 | |
40930fda | 309 | await waitJobs(servers) |
2186386c | 310 | |
40930fda C |
311 | for (const server of servers) { |
312 | const res = await getVideosList(server.url) | |
2186386c | 313 | |
40930fda C |
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 | |
2186386c | 317 | |
40930fda C |
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 | }) | |
2186386c | 324 | |
40930fda C |
325 | it('Should leave the audio untouched, but properly transcode the video', async function () { |
326 | this.timeout(60_000) | |
edb4ffc7 | 327 | |
40930fda C |
328 | const videoAttributes = { |
329 | name: 'untouched_audio', | |
330 | fixture: 'video_short.mp4' | |
331 | } | |
332 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
74cd011b | 333 | |
40930fda | 334 | await waitJobs(servers) |
edb4ffc7 | 335 | |
40930fda C |
336 | for (const server of servers) { |
337 | const res = await getVideosList(server.url) | |
edb4ffc7 | 338 | |
40930fda C |
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 | |
edb4ffc7 | 342 | |
40930fda | 343 | expect(videoDetails.files).to.have.lengthOf(4) |
edb4ffc7 | 344 | |
40930fda C |
345 | const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) |
346 | const fixtureVideoProbe = await getAudioStream(fixturePath) | |
347 | const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) | |
edb4ffc7 | 348 | |
40930fda | 349 | const videoProbe = await getAudioStream(path) |
edb4ffc7 | 350 | |
40930fda C |
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 | }) | |
edb4ffc7 | 360 | |
40930fda C |
361 | describe('Audio upload', function () { |
362 | ||
f6d6e7f8 | 363 | function runSuite (mode: 'legacy' | 'resumable') { |
364 | ||
365 | before(async function () { | |
366 | await updateCustomSubConfig(servers[1].url, servers[1].accessToken, { | |
367 | transcoding: { | |
368 | hls: { enabled: true }, | |
369 | webtorrent: { enabled: true }, | |
370 | resolutions: { | |
371 | '0p': false, | |
372 | '240p': false, | |
373 | '360p': false, | |
374 | '480p': false, | |
375 | '720p': false, | |
376 | '1080p': false, | |
377 | '1440p': false, | |
378 | '2160p': false | |
379 | } | |
40930fda | 380 | } |
f6d6e7f8 | 381 | }) |
40930fda | 382 | }) |
edb4ffc7 | 383 | |
f6d6e7f8 | 384 | it('Should merge an audio file with the preview file', async function () { |
385 | this.timeout(60_000) | |
edb4ffc7 | 386 | |
f6d6e7f8 | 387 | const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } |
388 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) | |
14e2014a | 389 | |
f6d6e7f8 | 390 | await waitJobs(servers) |
7ed2c1a4 | 391 | |
f6d6e7f8 | 392 | for (const server of servers) { |
393 | const res = await getVideosList(server.url) | |
7ed2c1a4 | 394 | |
f6d6e7f8 | 395 | const video = res.body.data.find(v => v.name === 'audio_with_preview') |
396 | const res2 = await getVideo(server.url, video.id) | |
397 | const videoDetails: VideoDetails = res2.body | |
7ed2c1a4 | 398 | |
f6d6e7f8 | 399 | expect(videoDetails.files).to.have.lengthOf(1) |
14e2014a | 400 | |
f6d6e7f8 | 401 | await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 }) |
402 | await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 }) | |
40930fda | 403 | |
f6d6e7f8 | 404 | const magnetUri = videoDetails.files[0].magnetUri |
405 | expect(magnetUri).to.contain('.mp4') | |
406 | } | |
407 | }) | |
14e2014a | 408 | |
f6d6e7f8 | 409 | it('Should upload an audio file and choose a default background image', async function () { |
410 | this.timeout(60_000) | |
14e2014a | 411 | |
f6d6e7f8 | 412 | const videoAttributesArg = { name: 'audio_without_preview', fixture: 'sample.ogg' } |
413 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) | |
14e2014a | 414 | |
f6d6e7f8 | 415 | await waitJobs(servers) |
14e2014a | 416 | |
f6d6e7f8 | 417 | for (const server of servers) { |
418 | const res = await getVideosList(server.url) | |
40930fda | 419 | |
f6d6e7f8 | 420 | const video = res.body.data.find(v => v.name === 'audio_without_preview') |
421 | const res2 = await getVideo(server.url, video.id) | |
422 | const videoDetails = res2.body | |
14e2014a | 423 | |
f6d6e7f8 | 424 | expect(videoDetails.files).to.have.lengthOf(1) |
14e2014a | 425 | |
f6d6e7f8 | 426 | await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 }) |
427 | await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 }) | |
7ed2c1a4 | 428 | |
f6d6e7f8 | 429 | const magnetUri = videoDetails.files[0].magnetUri |
430 | expect(magnetUri).to.contain('.mp4') | |
40930fda C |
431 | } |
432 | }) | |
7ed2c1a4 | 433 | |
f6d6e7f8 | 434 | it('Should upload an audio file and create an audio version only', async function () { |
435 | this.timeout(60_000) | |
436 | ||
437 | await updateCustomSubConfig(servers[1].url, servers[1].accessToken, { | |
438 | transcoding: { | |
439 | hls: { enabled: true }, | |
440 | webtorrent: { enabled: true }, | |
441 | resolutions: { | |
442 | '0p': true, | |
443 | '240p': false, | |
444 | '360p': false | |
445 | } | |
446 | } | |
447 | }) | |
b345a804 | 448 | |
f6d6e7f8 | 449 | const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } |
450 | const resVideo = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributesArg, HttpStatusCode.OK_200, mode) | |
b345a804 | 451 | |
f6d6e7f8 | 452 | await waitJobs(servers) |
b345a804 | 453 | |
f6d6e7f8 | 454 | for (const server of servers) { |
455 | const res2 = await getVideo(server.url, resVideo.body.video.id) | |
456 | const videoDetails: VideoDetails = res2.body | |
457 | ||
458 | for (const files of [ videoDetails.files, videoDetails.streamingPlaylists[0].files ]) { | |
459 | expect(files).to.have.lengthOf(2) | |
460 | expect(files.find(f => f.resolution.id === 0)).to.not.be.undefined | |
461 | } | |
40930fda | 462 | } |
b345a804 | 463 | |
f6d6e7f8 | 464 | await updateConfigForTranscoding(servers[1]) |
465 | }) | |
466 | } | |
467 | ||
468 | describe('Legacy upload', function () { | |
469 | runSuite('legacy') | |
470 | }) | |
471 | ||
472 | describe('Resumable upload', function () { | |
473 | runSuite('resumable') | |
40930fda C |
474 | }) |
475 | }) | |
b345a804 | 476 | |
40930fda | 477 | describe('Framerate', function () { |
b345a804 | 478 | |
40930fda C |
479 | it('Should transcode a 60 FPS video', async function () { |
480 | this.timeout(60_000) | |
b345a804 | 481 | |
40930fda C |
482 | const videoAttributes = { |
483 | name: 'my super 30fps name for server 2', | |
484 | description: 'my super 30fps description for server 2', | |
485 | fixture: '60fps_720p_small.mp4' | |
486 | } | |
487 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | |
b345a804 | 488 | |
40930fda | 489 | await waitJobs(servers) |
b345a804 | 490 | |
40930fda C |
491 | for (const server of servers) { |
492 | const res = await getVideosList(server.url) | |
b345a804 | 493 | |
40930fda C |
494 | const video = res.body.data.find(v => v.name === videoAttributes.name) |
495 | const res2 = await getVideo(server.url, video.id) | |
496 | const videoDetails: VideoDetails = res2.body | |
b345a804 | 497 | |
40930fda C |
498 | expect(videoDetails.files).to.have.lengthOf(4) |
499 | expect(videoDetails.files[0].fps).to.be.above(58).and.below(62) | |
500 | expect(videoDetails.files[1].fps).to.be.below(31) | |
501 | expect(videoDetails.files[2].fps).to.be.below(31) | |
502 | expect(videoDetails.files[3].fps).to.be.below(31) | |
b345a804 | 503 | |
40930fda C |
504 | for (const resolution of [ '240', '360', '480' ]) { |
505 | const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4')) | |
506 | const fps = await getVideoFileFPS(path) | |
b345a804 | 507 | |
40930fda C |
508 | expect(fps).to.be.below(31) |
509 | } | |
b345a804 | 510 | |
40930fda C |
511 | const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4')) |
512 | const fps = await getVideoFileFPS(path) | |
b345a804 | 513 | |
40930fda C |
514 | expect(fps).to.be.above(58).and.below(62) |
515 | } | |
516 | }) | |
b345a804 | 517 | |
40930fda C |
518 | it('Should downscale to the closest divisor standard framerate', async function () { |
519 | this.timeout(200_000) | |
837666fe | 520 | |
40930fda | 521 | let tempFixturePath: string |
837666fe | 522 | |
40930fda C |
523 | { |
524 | tempFixturePath = await generateVideoWithFramerate(59) | |
837666fe | 525 | |
40930fda C |
526 | const fps = await getVideoFileFPS(tempFixturePath) |
527 | expect(fps).to.be.equal(59) | |
528 | } | |
837666fe | 529 | |
40930fda C |
530 | const videoAttributes = { |
531 | name: '59fps video', | |
532 | description: '59fps video', | |
533 | fixture: tempFixturePath | |
534 | } | |
837666fe | 535 | |
40930fda | 536 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) |
837666fe | 537 | |
40930fda | 538 | await waitJobs(servers) |
837666fe | 539 | |
40930fda C |
540 | for (const server of servers) { |
541 | const res = await getVideosList(server.url) | |
837666fe | 542 | |
40930fda | 543 | const video = res.body.data.find(v => v.name === videoAttributes.name) |
837666fe | 544 | |
40930fda C |
545 | { |
546 | const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-240.mp4')) | |
547 | const fps = await getVideoFileFPS(path) | |
548 | expect(fps).to.be.equal(25) | |
549 | } | |
550 | ||
551 | { | |
552 | const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-720.mp4')) | |
553 | const fps = await getVideoFileFPS(path) | |
554 | expect(fps).to.be.equal(59) | |
555 | } | |
c7f36e4f | 556 | } |
40930fda C |
557 | }) |
558 | }) | |
559 | ||
560 | describe('Bitrate control', function () { | |
561 | it('Should respect maximum bitrate values', async function () { | |
562 | this.timeout(160_000) | |
563 | ||
564 | let tempFixturePath: string | |
c7f36e4f C |
565 | |
566 | { | |
40930fda | 567 | tempFixturePath = await generateHighBitrateVideo() |
837666fe | 568 | |
40930fda C |
569 | const bitrate = await getVideoFileBitrate(tempFixturePath) |
570 | expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS)) | |
d218e7de | 571 | } |
d218e7de | 572 | |
40930fda C |
573 | const videoAttributes = { |
574 | name: 'high bitrate video', | |
575 | description: 'high bitrate video', | |
576 | fixture: tempFixturePath | |
577 | } | |
d218e7de | 578 | |
40930fda | 579 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) |
d218e7de | 580 | |
40930fda | 581 | await waitJobs(servers) |
d218e7de | 582 | |
40930fda C |
583 | for (const server of servers) { |
584 | const res = await getVideosList(server.url) | |
d218e7de | 585 | |
40930fda | 586 | const video = res.body.data.find(v => v.name === videoAttributes.name) |
8319d6ae | 587 | |
40930fda C |
588 | for (const resolution of [ '240', '360', '480', '720', '1080' ]) { |
589 | const path = buildServerDirectory(servers[1], join('videos', video.uuid + '-' + resolution + '.mp4')) | |
8319d6ae | 590 | |
40930fda C |
591 | const bitrate = await getVideoFileBitrate(path) |
592 | const fps = await getVideoFileFPS(path) | |
593 | const resolution2 = await getVideoFileResolution(path) | |
8319d6ae | 594 | |
40930fda C |
595 | expect(resolution2.videoFileResolution.toString()).to.equal(resolution) |
596 | expect(bitrate).to.be.below(getMaxBitrate(resolution2.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)) | |
597 | } | |
7b81edc8 | 598 | } |
40930fda | 599 | }) |
8319d6ae | 600 | |
40930fda C |
601 | it('Should not transcode to an higher bitrate than the original file', async function () { |
602 | this.timeout(160_000) | |
603 | ||
604 | const config = { | |
605 | transcoding: { | |
606 | enabled: true, | |
607 | resolutions: { | |
608 | '240p': true, | |
609 | '360p': true, | |
610 | '480p': true, | |
611 | '720p': true, | |
612 | '1080p': true, | |
613 | '1440p': true, | |
614 | '2160p': true | |
615 | }, | |
616 | webtorrent: { enabled: true }, | |
617 | hls: { enabled: true } | |
618 | } | |
8319d6ae | 619 | } |
40930fda | 620 | await updateCustomSubConfig(servers[1].url, servers[1].accessToken, config) |
7b81edc8 | 621 | |
40930fda C |
622 | const videoAttributes = { |
623 | name: 'low bitrate', | |
624 | fixture: 'low-bitrate.mp4' | |
625 | } | |
8319d6ae | 626 | |
40930fda C |
627 | const resUpload = await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) |
628 | const videoUUID = resUpload.body.video.uuid | |
7b81edc8 | 629 | |
40930fda | 630 | await waitJobs(servers) |
8319d6ae | 631 | |
40930fda C |
632 | const resolutions = [ 240, 360, 480, 720, 1080 ] |
633 | for (const r of resolutions) { | |
634 | const path = `videos/${videoUUID}-${r}.mp4` | |
635 | const size = await getServerFileSize(servers[1], path) | |
636 | expect(size, `${path} not below ${60_000}`).to.be.below(60_000) | |
8319d6ae | 637 | } |
40930fda | 638 | }) |
8319d6ae RK |
639 | }) |
640 | ||
40930fda | 641 | describe('FFprobe', function () { |
f5961a8c | 642 | |
40930fda C |
643 | it('Should provide valid ffprobe data', async function () { |
644 | this.timeout(160_000) | |
f5961a8c | 645 | |
40930fda C |
646 | const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'ffprobe data' })).uuid |
647 | await waitJobs(servers) | |
f5961a8c | 648 | |
40930fda C |
649 | { |
650 | const path = buildServerDirectory(servers[1], join('videos', videoUUID + '-240.mp4')) | |
651 | const metadata = await getMetadataFromFile(path) | |
652 | ||
653 | // expected format properties | |
654 | for (const p of [ | |
655 | 'tags.encoder', | |
656 | 'format_long_name', | |
657 | 'size', | |
658 | 'bit_rate' | |
659 | ]) { | |
660 | expect(metadata.format).to.have.nested.property(p) | |
661 | } | |
662 | ||
663 | // expected stream properties | |
664 | for (const p of [ | |
665 | 'codec_long_name', | |
666 | 'profile', | |
667 | 'width', | |
668 | 'height', | |
669 | 'display_aspect_ratio', | |
670 | 'avg_frame_rate', | |
671 | 'pix_fmt' | |
672 | ]) { | |
673 | expect(metadata.streams[0]).to.have.nested.property(p) | |
674 | } | |
675 | ||
676 | expect(metadata).to.not.have.nested.property('format.filename') | |
677 | } | |
f5961a8c | 678 | |
40930fda C |
679 | for (const server of servers) { |
680 | const res2 = await getVideo(server.url, videoUUID) | |
681 | const videoDetails: VideoDetails = res2.body | |
682 | ||
683 | const videoFiles = videoDetails.files | |
684 | .concat(videoDetails.streamingPlaylists[0].files) | |
685 | expect(videoFiles).to.have.lengthOf(8) | |
686 | ||
687 | for (const file of videoFiles) { | |
688 | expect(file.metadata).to.be.undefined | |
689 | expect(file.metadataUrl).to.exist | |
690 | expect(file.metadataUrl).to.contain(servers[1].url) | |
691 | expect(file.metadataUrl).to.contain(videoUUID) | |
692 | ||
693 | const res3 = await getVideoFileMetadataUrl(file.metadataUrl) | |
694 | const metadata: FfprobeData = res3.body | |
695 | expect(metadata).to.have.nested.property('format.size') | |
696 | } | |
697 | } | |
698 | }) | |
f5961a8c | 699 | |
40930fda C |
700 | it('Should correctly detect if quick transcode is possible', async function () { |
701 | this.timeout(10_000) | |
f5961a8c | 702 | |
40930fda C |
703 | expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.mp4'))).to.be.true |
704 | expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.webm'))).to.be.false | |
705 | }) | |
f5961a8c C |
706 | }) |
707 | ||
40930fda | 708 | describe('Transcoding job queue', function () { |
6939cbac | 709 | |
40930fda | 710 | it('Should have the appropriate priorities for transcoding jobs', async function () { |
9c6327f8 | 711 | const body = await servers[1].jobsCommand.getJobsList({ |
40930fda C |
712 | start: 0, |
713 | count: 100, | |
714 | sort: '-createdAt', | |
715 | jobType: 'video-transcoding' | |
716 | }) | |
6939cbac | 717 | |
9c6327f8 | 718 | const jobs = body.data |
40930fda | 719 | const transcodingJobs = jobs.filter(j => j.data.videoUUID === video4k) |
6939cbac | 720 | |
40930fda | 721 | expect(transcodingJobs).to.have.lengthOf(14) |
6939cbac | 722 | |
40930fda C |
723 | const hlsJobs = transcodingJobs.filter(j => j.data.type === 'new-resolution-to-hls') |
724 | const webtorrentJobs = transcodingJobs.filter(j => j.data.type === 'new-resolution-to-webtorrent') | |
725 | const optimizeJobs = transcodingJobs.filter(j => j.data.type === 'optimize-to-webtorrent') | |
6939cbac | 726 | |
40930fda C |
727 | expect(hlsJobs).to.have.lengthOf(7) |
728 | expect(webtorrentJobs).to.have.lengthOf(6) | |
729 | expect(optimizeJobs).to.have.lengthOf(1) | |
6939cbac | 730 | |
a6e37eeb | 731 | for (const j of optimizeJobs.concat(hlsJobs.concat(webtorrentJobs))) { |
40930fda C |
732 | expect(j.priority).to.be.greaterThan(100) |
733 | expect(j.priority).to.be.lessThan(150) | |
734 | } | |
735 | }) | |
6939cbac C |
736 | }) |
737 | ||
7c3b7976 C |
738 | after(async function () { |
739 | await cleanupTests(servers) | |
0e1dc3e7 C |
740 | }) |
741 | }) |