diff options
Diffstat (limited to 'server/tests/api/videos/video-transcoder.ts')
-rw-r--r-- | server/tests/api/videos/video-transcoder.ts | 89 |
1 files changed, 78 insertions, 11 deletions
diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index 3cd43e99b..90ade1652 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts | |||
@@ -4,24 +4,25 @@ import * as chai from 'chai' | |||
4 | import 'mocha' | 4 | import 'mocha' |
5 | import { omit } from 'lodash' | 5 | import { omit } from 'lodash' |
6 | import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos' | 6 | import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos' |
7 | import { audio, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' | 7 | import { audio, canDoQuickTranscode, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' |
8 | import { | 8 | import { |
9 | buildAbsoluteFixturePath, cleanupTests, | 9 | buildAbsoluteFixturePath, |
10 | cleanupTests, | ||
10 | doubleFollow, | 11 | doubleFollow, |
11 | flushAndRunMultipleServers, | 12 | flushAndRunMultipleServers, |
12 | generateHighBitrateVideo, | 13 | generateHighBitrateVideo, |
13 | getMyVideos, | 14 | getMyVideos, |
14 | getVideo, | 15 | getVideo, |
15 | getVideosList, | 16 | getVideosList, |
16 | killallServers, | 17 | makeGetRequest, |
17 | root, | 18 | root, |
18 | ServerInfo, | 19 | ServerInfo, |
19 | setAccessTokensToServers, | 20 | setAccessTokensToServers, |
20 | uploadVideo, | 21 | uploadVideo, |
22 | waitJobs, | ||
21 | webtorrentAdd | 23 | webtorrentAdd |
22 | } from '../../../../shared/extra-utils' | 24 | } from '../../../../shared/extra-utils' |
23 | import { extname, join } from 'path' | 25 | import { join } from 'path' |
24 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | ||
25 | import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' | 26 | import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' |
26 | 27 | ||
27 | const expect = chai.expect | 28 | const expect = chai.expect |
@@ -121,7 +122,7 @@ describe('Test video transcoding', function () { | |||
121 | 122 | ||
122 | expect(videoDetails.files).to.have.lengthOf(4) | 123 | expect(videoDetails.files).to.have.lengthOf(4) |
123 | 124 | ||
124 | const path = join(root(), 'test2', 'videos', video.uuid + '-240.mp4') | 125 | const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-240.mp4') |
125 | const probe = await audio.get(path) | 126 | const probe = await audio.get(path) |
126 | 127 | ||
127 | if (probe.audioStream) { | 128 | if (probe.audioStream) { |
@@ -152,7 +153,7 @@ describe('Test video transcoding', function () { | |||
152 | const videoDetails: VideoDetails = res2.body | 153 | const videoDetails: VideoDetails = res2.body |
153 | 154 | ||
154 | expect(videoDetails.files).to.have.lengthOf(4) | 155 | expect(videoDetails.files).to.have.lengthOf(4) |
155 | const path = join(root(), 'test2', 'videos', video.uuid + '-240.mp4') | 156 | const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-240.mp4') |
156 | const probe = await audio.get(path) | 157 | const probe = await audio.get(path) |
157 | expect(probe).to.not.have.property('audioStream') | 158 | expect(probe).to.not.have.property('audioStream') |
158 | } | 159 | } |
@@ -179,7 +180,7 @@ describe('Test video transcoding', function () { | |||
179 | expect(videoDetails.files).to.have.lengthOf(4) | 180 | expect(videoDetails.files).to.have.lengthOf(4) |
180 | const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) | 181 | const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) |
181 | const fixtureVideoProbe = await audio.get(fixturePath) | 182 | const fixtureVideoProbe = await audio.get(fixturePath) |
182 | const path = join(root(), 'test2', 'videos', video.uuid + '-240.mp4') | 183 | const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-240.mp4') |
183 | const videoProbe = await audio.get(path) | 184 | const videoProbe = await audio.get(path) |
184 | if (videoProbe.audioStream && fixtureVideoProbe.audioStream) { | 185 | if (videoProbe.audioStream && fixtureVideoProbe.audioStream) { |
185 | const toOmit = [ 'max_bit_rate', 'duration', 'duration_ts', 'nb_frames', 'start_time', 'start_pts' ] | 186 | const toOmit = [ 'max_bit_rate', 'duration', 'duration_ts', 'nb_frames', 'start_time', 'start_pts' ] |
@@ -216,13 +217,13 @@ describe('Test video transcoding', function () { | |||
216 | expect(videoDetails.files[ 3 ].fps).to.be.below(31) | 217 | expect(videoDetails.files[ 3 ].fps).to.be.below(31) |
217 | 218 | ||
218 | for (const resolution of [ '240', '360', '480' ]) { | 219 | for (const resolution of [ '240', '360', '480' ]) { |
219 | const path = join(root(), 'test2', 'videos', video.uuid + '-' + resolution + '.mp4') | 220 | const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-' + resolution + '.mp4') |
220 | const fps = await getVideoFileFPS(path) | 221 | const fps = await getVideoFileFPS(path) |
221 | 222 | ||
222 | expect(fps).to.be.below(31) | 223 | expect(fps).to.be.below(31) |
223 | } | 224 | } |
224 | 225 | ||
225 | const path = join(root(), 'test2', 'videos', video.uuid + '-720.mp4') | 226 | const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-720.mp4') |
226 | const fps = await getVideoFileFPS(path) | 227 | const fps = await getVideoFileFPS(path) |
227 | 228 | ||
228 | expect(fps).to.be.above(58).and.below(62) | 229 | expect(fps).to.be.above(58).and.below(62) |
@@ -310,7 +311,7 @@ describe('Test video transcoding', function () { | |||
310 | const video = res.body.data.find(v => v.name === videoAttributes.name) | 311 | const video = res.body.data.find(v => v.name === videoAttributes.name) |
311 | 312 | ||
312 | for (const resolution of ['240', '360', '480', '720', '1080']) { | 313 | for (const resolution of ['240', '360', '480', '720', '1080']) { |
313 | const path = join(root(), 'test2', 'videos', video.uuid + '-' + resolution + '.mp4') | 314 | const path = join(root(), 'test' + servers[1].internalServerNumber, 'videos', video.uuid + '-' + resolution + '.mp4') |
314 | const bitrate = await getVideoFileBitrate(path) | 315 | const bitrate = await getVideoFileBitrate(path) |
315 | const fps = await getVideoFileFPS(path) | 316 | const fps = await getVideoFileFPS(path) |
316 | const resolution2 = await getVideoFileResolution(path) | 317 | const resolution2 = await getVideoFileResolution(path) |
@@ -324,6 +325,15 @@ describe('Test video transcoding', function () { | |||
324 | it('Should accept and transcode additional extensions', async function () { | 325 | it('Should accept and transcode additional extensions', async function () { |
325 | this.timeout(300000) | 326 | this.timeout(300000) |
326 | 327 | ||
328 | let tempFixturePath: string | ||
329 | |||
330 | { | ||
331 | tempFixturePath = await generateHighBitrateVideo() | ||
332 | |||
333 | const bitrate = await getVideoFileBitrate(tempFixturePath) | ||
334 | expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 60, VIDEO_TRANSCODING_FPS)) | ||
335 | } | ||
336 | |||
327 | for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) { | 337 | for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) { |
328 | const videoAttributes = { | 338 | const videoAttributes = { |
329 | name: fixture, | 339 | name: fixture, |
@@ -349,6 +359,63 @@ describe('Test video transcoding', function () { | |||
349 | } | 359 | } |
350 | }) | 360 | }) |
351 | 361 | ||
362 | it('Should correctly detect if quick transcode is possible', async function () { | ||
363 | this.timeout(10000) | ||
364 | |||
365 | expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.mp4'))).to.be.true | ||
366 | expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.webm'))).to.be.false | ||
367 | }) | ||
368 | |||
369 | it('Should merge an audio file with the preview file', async function () { | ||
370 | this.timeout(60000) | ||
371 | |||
372 | const videoAttributesArg = { name: 'audio_with_preview', previewfile: 'preview.jpg', fixture: 'sample.ogg' } | ||
373 | await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, videoAttributesArg) | ||
374 | |||
375 | await waitJobs(servers) | ||
376 | |||
377 | for (const server of servers) { | ||
378 | const res = await getVideosList(server.url) | ||
379 | |||
380 | const video = res.body.data.find(v => v.name === 'audio_with_preview') | ||
381 | const res2 = await getVideo(server.url, video.id) | ||
382 | const videoDetails: VideoDetails = res2.body | ||
383 | |||
384 | expect(videoDetails.files).to.have.lengthOf(1) | ||
385 | |||
386 | await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: 200 }) | ||
387 | await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: 200 }) | ||
388 | |||
389 | const magnetUri = videoDetails.files[ 0 ].magnetUri | ||
390 | expect(magnetUri).to.contain('.mp4') | ||
391 | } | ||
392 | }) | ||
393 | |||
394 | it('Should upload an audio file and choose a default background image', async function () { | ||
395 | this.timeout(60000) | ||
396 | |||
397 | const videoAttributesArg = { name: 'audio_without_preview', fixture: 'sample.ogg' } | ||
398 | await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, videoAttributesArg) | ||
399 | |||
400 | await waitJobs(servers) | ||
401 | |||
402 | for (const server of servers) { | ||
403 | const res = await getVideosList(server.url) | ||
404 | |||
405 | const video = res.body.data.find(v => v.name === 'audio_without_preview') | ||
406 | const res2 = await getVideo(server.url, video.id) | ||
407 | const videoDetails = res2.body | ||
408 | |||
409 | expect(videoDetails.files).to.have.lengthOf(1) | ||
410 | |||
411 | await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: 200 }) | ||
412 | await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: 200 }) | ||
413 | |||
414 | const magnetUri = videoDetails.files[ 0 ].magnetUri | ||
415 | expect(magnetUri).to.contain('.mp4') | ||
416 | } | ||
417 | }) | ||
418 | |||
352 | after(async function () { | 419 | after(async function () { |
353 | await cleanupTests(servers) | 420 | await cleanupTests(servers) |
354 | }) | 421 | }) |