From 9f430a53be016f8db2736d5d8111282660b50f4c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 12 Oct 2021 09:18:54 +0200 Subject: [PATCH] Fix bitrate tests --- server/tests/api/live/live.ts | 17 ++++++++++++----- server/tests/api/videos/video-transcoder.ts | 5 ++--- server/tests/cli/print-transcode-command.ts | 4 ++-- shared/core-utils/videos/bitrate.ts | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index 5cac3bc4e..0b405dd94 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -517,10 +517,16 @@ describe('Test live', function () { await waitUntilLivePublishedOnAllServers(servers, liveVideoId) - const bitrateLimits = { - 720: 5000 * 1000, // 60FPS - 360: 1100 * 1000, - 240: 600 * 1000 + const maxBitrateLimits = { + 720: 6500 * 1000, // 60FPS + 360: 1250 * 1000, + 240: 700 * 1000 + } + + const minBitrateLimits = { + 720: 5500 * 1000, + 360: 1000 * 1000, + 240: 550 * 1000 } for (const server of servers) { @@ -560,7 +566,8 @@ describe('Test live', function () { const probe = await ffprobePromise(segmentPath) const videoStream = await getVideoStreamFromFile(segmentPath, probe) - expect(probe.format.bit_rate).to.be.below(bitrateLimits[videoStream.height]) + expect(probe.format.bit_rate).to.be.below(maxBitrateLimits[videoStream.height]) + expect(probe.format.bit_rate).to.be.at.least(minBitrateLimits[videoStream.height]) await makeRawRequest(file.torrentUrl, HttpStatusCode.OK_200) await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200) diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index 2b49176b2..21609fd82 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -11,7 +11,6 @@ import { doubleFollow, generateHighBitrateVideo, generateVideoWithFramerate, - getFileSize, makeGetRequest, PeerTubeServer, setAccessTokensToServers, @@ -617,8 +616,8 @@ describe('Test video transcoding', function () { 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) + const bitrate = await getVideoFileBitrate(path) + expect(bitrate, `${path} not below ${60_000}`).to.be.below(60_000) } }) }) diff --git a/server/tests/cli/print-transcode-command.ts b/server/tests/cli/print-transcode-command.ts index e328a6072..e2cca17f9 100644 --- a/server/tests/cli/print-transcode-command.ts +++ b/server/tests/cli/print-transcode-command.ts @@ -9,7 +9,7 @@ import { VideoResolution } from '../../../shared/models/videos' const expect = chai.expect -describe('Test create transcoding jobs', function () { +describe('Test print transcode jobs', function () { it('Should print the correct command for each resolution', async function () { const fixturePath = buildAbsoluteFixturePath('video_short.webm') @@ -21,7 +21,7 @@ describe('Test create transcoding jobs', function () { VideoResolution.H_1080P ]) { const command = await CLICommand.exec(`npm run print-transcode-command -- ${fixturePath} -r ${resolution}`) - const targetBitrate = Math.min(getMaxBitrate({ resolution, fps, ratio: 16 / 9 }), bitrate) + const targetBitrate = Math.min(getMaxBitrate({ resolution, fps, ratio: 16 / 9 }), bitrate + (bitrate * 0.3)) expect(command).to.includes(`-vf scale=w=-2:h=${resolution}`) expect(command).to.includes(`-y -acodec aac -vcodec libx264`) diff --git a/shared/core-utils/videos/bitrate.ts b/shared/core-utils/videos/bitrate.ts index 3d4e47906..a6712f8a4 100644 --- a/shared/core-utils/videos/bitrate.ts +++ b/shared/core-utils/videos/bitrate.ts @@ -78,7 +78,7 @@ function calculateBitrate (options: { for (const toTestResolution of resolutionsOrder) { if (toTestResolution <= resolution) { - return resolution * resolution * ratio * fps * bitPerPixel[toTestResolution] + return Math.floor(resolution * resolution * ratio * fps * bitPerPixel[toTestResolution]) } } -- 2.41.0