X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fvideos%2Fvideo-transcoder.ts;h=2b49176b2a39cc9c9bc30a4a67dead7f38702645;hb=41085b1583ade5ea1bb1d69965a62b98cf012209;hp=e4892bb24d03b34f38a64934134ee089a275f05e;hpb=c4fa01f7c45b66b112ebd08abce744b7c4041feb;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index e4892bb24..2b49176b2 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -3,7 +3,7 @@ import 'mocha' import * as chai from 'chai' import { omit } from 'lodash' -import { join } from 'path' +import { getMaxBitrate } from '@shared/core-utils' import { buildAbsoluteFixturePath, cleanupTests, @@ -11,14 +11,14 @@ import { doubleFollow, generateHighBitrateVideo, generateVideoWithFramerate, + getFileSize, makeGetRequest, PeerTubeServer, setAccessTokensToServers, waitJobs, webtorrentAdd } from '@shared/extra-utils' -import { getMaxBitrate, HttpStatusCode, VideoResolution, VideoState } from '@shared/models' -import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' +import { HttpStatusCode, VideoState } from '@shared/models' import { canDoQuickTranscode, getAudioStream, @@ -191,15 +191,6 @@ describe('Test video transcoding', function () { it('Should accept and transcode additional extensions', async function () { this.timeout(300_000) - let tempFixturePath: string - - { - tempFixturePath = await generateHighBitrateVideo() - - const bitrate = await getVideoFileBitrate(tempFixturePath) - expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS)) - } - for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) { const attributes = { name: fixture, @@ -271,7 +262,8 @@ describe('Test video transcoding', function () { expect(videoDetails.files).to.have.lengthOf(4) - const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4')) + const file = videoDetails.files.find(f => f.resolution.id === 240) + const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl) const probe = await getAudioStream(path) if (probe.audioStream) { @@ -300,8 +292,9 @@ describe('Test video transcoding', function () { const video = data.find(v => v.name === attributes.name) const videoDetails = await server.videos.get({ id: video.id }) - expect(videoDetails.files).to.have.lengthOf(4) - const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4')) + const file = videoDetails.files.find(f => f.resolution.id === 240) + const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl) + const probe = await getAudioStream(path) expect(probe).to.not.have.property('audioStream') } @@ -328,7 +321,9 @@ describe('Test video transcoding', function () { const fixturePath = buildAbsoluteFixturePath(attributes.fixture) const fixtureVideoProbe = await getAudioStream(fixturePath) - const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4')) + + const file = videoDetails.files.find(f => f.resolution.id === 240) + const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl) const videoProbe = await getAudioStream(path) @@ -485,14 +480,16 @@ describe('Test video transcoding', function () { expect(videoDetails.files[2].fps).to.be.below(31) expect(videoDetails.files[3].fps).to.be.below(31) - for (const resolution of [ '240', '360', '480' ]) { - const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) + for (const resolution of [ 240, 360, 480 ]) { + const file = videoDetails.files.find(f => f.resolution.id === resolution) + const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl) const fps = await getVideoFileFPS(path) expect(fps).to.be.below(31) } - const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-720.mp4')) + const file = videoDetails.files.find(f => f.resolution.id === 720) + const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl) const fps = await getVideoFileFPS(path) expect(fps).to.be.above(58).and.below(62) @@ -524,16 +521,19 @@ describe('Test video transcoding', function () { for (const server of servers) { const { data } = await server.videos.list() - const video = data.find(v => v.name === attributes.name) + const { id } = data.find(v => v.name === attributes.name) + const video = await server.videos.get({ id }) { - const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-240.mp4')) + const file = video.files.find(f => f.resolution.id === 240) + const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl) const fps = await getVideoFileFPS(path) expect(fps).to.be.equal(25) } { - const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-720.mp4')) + const file = video.files.find(f => f.resolution.id === 720) + const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl) const fps = await getVideoFileFPS(path) expect(fps).to.be.equal(59) } @@ -542,17 +542,11 @@ describe('Test video transcoding', function () { }) describe('Bitrate control', function () { + it('Should respect maximum bitrate values', async function () { this.timeout(160_000) - let tempFixturePath: string - - { - tempFixturePath = await generateHighBitrateVideo() - - const bitrate = await getVideoFileBitrate(tempFixturePath) - expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 25, VIDEO_TRANSCODING_FPS)) - } + const tempFixturePath = await generateHighBitrateVideo() const attributes = { name: 'high bitrate video', @@ -567,17 +561,21 @@ describe('Test video transcoding', function () { for (const server of servers) { const { data } = await server.videos.list() - const video = data.find(v => v.name === attributes.name) + const { id } = data.find(v => v.name === attributes.name) + const video = await server.videos.get({ id }) - for (const resolution of [ '240', '360', '480', '720', '1080' ]) { - const path = servers[1].servers.buildDirectory(join('videos', video.uuid + '-' + resolution + '.mp4')) + for (const resolution of [ 240, 360, 480, 720, 1080 ]) { + const file = video.files.find(f => f.resolution.id === resolution) + const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl) const bitrate = await getVideoFileBitrate(path) const fps = await getVideoFileFPS(path) - const resolution2 = await getVideoFileResolution(path) + const dataResolution = await getVideoFileResolution(path) + + expect(resolution).to.equal(resolution) - expect(resolution2.videoFileResolution.toString()).to.equal(resolution) - expect(bitrate).to.be.below(getMaxBitrate(resolution2.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)) + const maxBitrate = getMaxBitrate({ ...dataResolution, fps }) + expect(bitrate).to.be.below(maxBitrate) } } }) @@ -608,14 +606,18 @@ describe('Test video transcoding', function () { fixture: 'low-bitrate.mp4' } - const { uuid } = await servers[1].videos.upload({ attributes }) + const { id } = await servers[1].videos.upload({ attributes }) await waitJobs(servers) + const video = await servers[1].videos.get({ id }) + const resolutions = [ 240, 360, 480, 720, 1080 ] for (const r of resolutions) { - const path = `videos/${uuid}-${r}.mp4` - const size = await servers[1].servers.getServerFileSize(path) + const file = video.files.find(f => f.resolution.id === r) + + const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl) + const size = await getFileSize(path) expect(size, `${path} not below ${60_000}`).to.be.below(60_000) } }) @@ -630,7 +632,9 @@ describe('Test video transcoding', function () { await waitJobs(servers) { - const path = servers[1].servers.buildDirectory(join('videos', videoUUID + '-240.mp4')) + const video = await servers[1].videos.get({ id: videoUUID }) + const file = video.files.find(f => f.resolution.id === 240) + const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl) const metadata = await getMetadataFromFile(path) // expected format properties @@ -689,7 +693,7 @@ describe('Test video transcoding', function () { describe('Transcoding job queue', function () { it('Should have the appropriate priorities for transcoding jobs', async function () { - const body = await servers[1].jobs.getJobsList({ + const body = await servers[1].jobs.list({ start: 0, count: 100, sort: '-createdAt',