aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/tests/api/live/live.ts17
-rw-r--r--server/tests/api/videos/video-transcoder.ts5
-rw-r--r--server/tests/cli/print-transcode-command.ts4
-rw-r--r--shared/core-utils/videos/bitrate.ts2
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 () {
517 517
518 await waitUntilLivePublishedOnAllServers(servers, liveVideoId) 518 await waitUntilLivePublishedOnAllServers(servers, liveVideoId)
519 519
520 const bitrateLimits = { 520 const maxBitrateLimits = {
521 720: 5000 * 1000, // 60FPS 521 720: 6500 * 1000, // 60FPS
522 360: 1100 * 1000, 522 360: 1250 * 1000,
523 240: 600 * 1000 523 240: 700 * 1000
524 }
525
526 const minBitrateLimits = {
527 720: 5500 * 1000,
528 360: 1000 * 1000,
529 240: 550 * 1000
524 } 530 }
525 531
526 for (const server of servers) { 532 for (const server of servers) {
@@ -560,7 +566,8 @@ describe('Test live', function () {
560 const probe = await ffprobePromise(segmentPath) 566 const probe = await ffprobePromise(segmentPath)
561 const videoStream = await getVideoStreamFromFile(segmentPath, probe) 567 const videoStream = await getVideoStreamFromFile(segmentPath, probe)
562 568
563 expect(probe.format.bit_rate).to.be.below(bitrateLimits[videoStream.height]) 569 expect(probe.format.bit_rate).to.be.below(maxBitrateLimits[videoStream.height])
570 expect(probe.format.bit_rate).to.be.at.least(minBitrateLimits[videoStream.height])
564 571
565 await makeRawRequest(file.torrentUrl, HttpStatusCode.OK_200) 572 await makeRawRequest(file.torrentUrl, HttpStatusCode.OK_200)
566 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200) 573 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 {
11 doubleFollow, 11 doubleFollow,
12 generateHighBitrateVideo, 12 generateHighBitrateVideo,
13 generateVideoWithFramerate, 13 generateVideoWithFramerate,
14 getFileSize,
15 makeGetRequest, 14 makeGetRequest,
16 PeerTubeServer, 15 PeerTubeServer,
17 setAccessTokensToServers, 16 setAccessTokensToServers,
@@ -617,8 +616,8 @@ describe('Test video transcoding', function () {
617 const file = video.files.find(f => f.resolution.id === r) 616 const file = video.files.find(f => f.resolution.id === r)
618 617
619 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl) 618 const path = servers[1].servers.buildWebTorrentFilePath(file.fileUrl)
620 const size = await getFileSize(path) 619 const bitrate = await getVideoFileBitrate(path)
621 expect(size, `${path} not below ${60_000}`).to.be.below(60_000) 620 expect(bitrate, `${path} not below ${60_000}`).to.be.below(60_000)
622 } 621 }
623 }) 622 })
624 }) 623 })
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'
9 9
10const expect = chai.expect 10const expect = chai.expect
11 11
12describe('Test create transcoding jobs', function () { 12describe('Test print transcode jobs', function () {
13 13
14 it('Should print the correct command for each resolution', async function () { 14 it('Should print the correct command for each resolution', async function () {
15 const fixturePath = buildAbsoluteFixturePath('video_short.webm') 15 const fixturePath = buildAbsoluteFixturePath('video_short.webm')
@@ -21,7 +21,7 @@ describe('Test create transcoding jobs', function () {
21 VideoResolution.H_1080P 21 VideoResolution.H_1080P
22 ]) { 22 ]) {
23 const command = await CLICommand.exec(`npm run print-transcode-command -- ${fixturePath} -r ${resolution}`) 23 const command = await CLICommand.exec(`npm run print-transcode-command -- ${fixturePath} -r ${resolution}`)
24 const targetBitrate = Math.min(getMaxBitrate({ resolution, fps, ratio: 16 / 9 }), bitrate) 24 const targetBitrate = Math.min(getMaxBitrate({ resolution, fps, ratio: 16 / 9 }), bitrate + (bitrate * 0.3))
25 25
26 expect(command).to.includes(`-vf scale=w=-2:h=${resolution}`) 26 expect(command).to.includes(`-vf scale=w=-2:h=${resolution}`)
27 expect(command).to.includes(`-y -acodec aac -vcodec libx264`) 27 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: {
78 78
79 for (const toTestResolution of resolutionsOrder) { 79 for (const toTestResolution of resolutionsOrder) {
80 if (toTestResolution <= resolution) { 80 if (toTestResolution <= resolution) {
81 return resolution * resolution * ratio * fps * bitPerPixel[toTestResolution] 81 return Math.floor(resolution * resolution * ratio * fps * bitPerPixel[toTestResolution])
82 } 82 }
83 } 83 }
84 84