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