diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
commit | 88108880bbdba473cfe36ecbebc1c3c4f972e102 (patch) | |
tree | b242efb3b4f0d7e49d88f2d1f2063b5b3b0489c0 /server/tests/api/videos/video-transcoder.ts | |
parent | 53a94c7cfa8368da4cd248d65df8346905938f0c (diff) | |
parent | 9b712a2017e4ab3cf12cd6bd58278905520159d0 (diff) | |
download | PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.gz PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.zst PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.zip |
Merge branch 'develop' into pr/1217
Diffstat (limited to 'server/tests/api/videos/video-transcoder.ts')
-rw-r--r-- | server/tests/api/videos/video-transcoder.ts | 90 |
1 files changed, 79 insertions, 11 deletions
diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index 0f83d4d57..eefd32ef8 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts | |||
@@ -3,13 +3,13 @@ | |||
3 | import * as chai from 'chai' | 3 | import * as chai from 'chai' |
4 | import 'mocha' | 4 | import 'mocha' |
5 | import { omit } from 'lodash' | 5 | import { omit } from 'lodash' |
6 | import * as ffmpeg from 'fluent-ffmpeg' | 6 | import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos' |
7 | import { VideoDetails, VideoState } from '../../../../shared/models/videos' | 7 | import { audio, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' |
8 | import { getVideoFileFPS, audio } from '../../../helpers/ffmpeg-utils' | ||
9 | import { | 8 | import { |
10 | buildAbsoluteFixturePath, | 9 | buildAbsoluteFixturePath, |
11 | doubleFollow, | 10 | doubleFollow, |
12 | flushAndRunMultipleServers, | 11 | flushAndRunMultipleServers, |
12 | generateHighBitrateVideo, | ||
13 | getMyVideos, | 13 | getMyVideos, |
14 | getVideo, | 14 | getVideo, |
15 | getVideosList, | 15 | getVideosList, |
@@ -19,9 +19,10 @@ import { | |||
19 | setAccessTokensToServers, | 19 | setAccessTokensToServers, |
20 | uploadVideo, | 20 | uploadVideo, |
21 | webtorrentAdd | 21 | webtorrentAdd |
22 | } from '../../utils' | 22 | } from '../../../../shared/utils' |
23 | import { join } from 'path' | 23 | import { extname, join } from 'path' |
24 | import { waitJobs } from '../../utils/server/jobs' | 24 | import { waitJobs } from '../../../../shared/utils/server/jobs' |
25 | import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' | ||
25 | 26 | ||
26 | const expect = chai.expect | 27 | const expect = chai.expect |
27 | 28 | ||
@@ -121,7 +122,7 @@ describe('Test video transcoding', function () { | |||
121 | expect(videoDetails.files).to.have.lengthOf(4) | 122 | expect(videoDetails.files).to.have.lengthOf(4) |
122 | 123 | ||
123 | const path = join(root(), 'test2', 'videos', video.uuid + '-240.mp4') | 124 | const path = join(root(), 'test2', 'videos', video.uuid + '-240.mp4') |
124 | const probe = await audio.get(ffmpeg, path) | 125 | const probe = await audio.get(path) |
125 | 126 | ||
126 | if (probe.audioStream) { | 127 | if (probe.audioStream) { |
127 | expect(probe.audioStream[ 'codec_name' ]).to.be.equal('aac') | 128 | expect(probe.audioStream[ 'codec_name' ]).to.be.equal('aac') |
@@ -152,7 +153,7 @@ describe('Test video transcoding', function () { | |||
152 | 153 | ||
153 | expect(videoDetails.files).to.have.lengthOf(4) | 154 | expect(videoDetails.files).to.have.lengthOf(4) |
154 | const path = join(root(), 'test2', 'videos', video.uuid + '-240.mp4') | 155 | const path = join(root(), 'test2', 'videos', video.uuid + '-240.mp4') |
155 | const probe = await audio.get(ffmpeg, path) | 156 | const probe = await audio.get(path) |
156 | expect(probe).to.not.have.property('audioStream') | 157 | expect(probe).to.not.have.property('audioStream') |
157 | } | 158 | } |
158 | }) | 159 | }) |
@@ -177,9 +178,9 @@ describe('Test video transcoding', function () { | |||
177 | 178 | ||
178 | expect(videoDetails.files).to.have.lengthOf(4) | 179 | expect(videoDetails.files).to.have.lengthOf(4) |
179 | const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) | 180 | const fixturePath = buildAbsoluteFixturePath(videoAttributes.fixture) |
180 | const fixtureVideoProbe = await audio.get(ffmpeg, fixturePath) | 181 | const fixtureVideoProbe = await audio.get(fixturePath) |
181 | const path = join(root(), 'test2', 'videos', video.uuid + '-240.mp4') | 182 | const path = join(root(), 'test2', 'videos', video.uuid + '-240.mp4') |
182 | const videoProbe = await audio.get(ffmpeg, path) | 183 | const videoProbe = await audio.get(path) |
183 | if (videoProbe.audioStream && fixtureVideoProbe.audioStream) { | 184 | if (videoProbe.audioStream && fixtureVideoProbe.audioStream) { |
184 | const toOmit = [ 'max_bit_rate', 'duration', 'duration_ts', 'nb_frames', 'start_time', 'start_pts' ] | 185 | const toOmit = [ 'max_bit_rate', 'duration', 'duration_ts', 'nb_frames', 'start_time', 'start_pts' ] |
185 | expect(omit(videoProbe.audioStream, toOmit)).to.be.deep.equal(omit(fixtureVideoProbe.audioStream, toOmit)) | 186 | expect(omit(videoProbe.audioStream, toOmit)).to.be.deep.equal(omit(fixtureVideoProbe.audioStream, toOmit)) |
@@ -228,7 +229,7 @@ describe('Test video transcoding', function () { | |||
228 | } | 229 | } |
229 | }) | 230 | }) |
230 | 231 | ||
231 | it('Should wait transcoding before publishing the video', async function () { | 232 | it('Should wait for transcoding before publishing the video', async function () { |
232 | this.timeout(80000) | 233 | this.timeout(80000) |
233 | 234 | ||
234 | { | 235 | { |
@@ -281,6 +282,73 @@ describe('Test video transcoding', function () { | |||
281 | } | 282 | } |
282 | }) | 283 | }) |
283 | 284 | ||
285 | it('Should respect maximum bitrate values', async function () { | ||
286 | this.timeout(160000) | ||
287 | |||
288 | let tempFixturePath: string | ||
289 | |||
290 | { | ||
291 | tempFixturePath = await generateHighBitrateVideo() | ||
292 | |||
293 | const bitrate = await getVideoFileBitrate(tempFixturePath) | ||
294 | expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 60, VIDEO_TRANSCODING_FPS)) | ||
295 | } | ||
296 | |||
297 | const videoAttributes = { | ||
298 | name: 'high bitrate video', | ||
299 | description: 'high bitrate video', | ||
300 | fixture: tempFixturePath | ||
301 | } | ||
302 | |||
303 | await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) | ||
304 | |||
305 | await waitJobs(servers) | ||
306 | |||
307 | for (const server of servers) { | ||
308 | const res = await getVideosList(server.url) | ||
309 | |||
310 | const video = res.body.data.find(v => v.name === videoAttributes.name) | ||
311 | |||
312 | for (const resolution of ['240', '360', '480', '720', '1080']) { | ||
313 | const path = join(root(), 'test2', 'videos', video.uuid + '-' + resolution + '.mp4') | ||
314 | const bitrate = await getVideoFileBitrate(path) | ||
315 | const fps = await getVideoFileFPS(path) | ||
316 | const resolution2 = await getVideoFileResolution(path) | ||
317 | |||
318 | expect(resolution2.videoFileResolution.toString()).to.equal(resolution) | ||
319 | expect(bitrate).to.be.below(getMaxBitrate(resolution2.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)) | ||
320 | } | ||
321 | } | ||
322 | }) | ||
323 | |||
324 | it('Should accept and transcode additional extensions', async function () { | ||
325 | this.timeout(300000) | ||
326 | |||
327 | for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) { | ||
328 | const videoAttributes = { | ||
329 | name: fixture, | ||
330 | fixture | ||
331 | } | ||
332 | |||
333 | await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, videoAttributes) | ||
334 | |||
335 | await waitJobs(servers) | ||
336 | |||
337 | for (const server of servers) { | ||
338 | const res = await getVideosList(server.url) | ||
339 | |||
340 | const video = res.body.data.find(v => v.name === videoAttributes.name) | ||
341 | const res2 = await getVideo(server.url, video.id) | ||
342 | const videoDetails = res2.body | ||
343 | |||
344 | expect(videoDetails.files).to.have.lengthOf(4) | ||
345 | |||
346 | const magnetUri = videoDetails.files[ 0 ].magnetUri | ||
347 | expect(magnetUri).to.contain('.mp4') | ||
348 | } | ||
349 | } | ||
350 | }) | ||
351 | |||
284 | after(async function () { | 352 | after(async function () { |
285 | killallServers(servers) | 353 | killallServers(servers) |
286 | }) | 354 | }) |