From 9f430a53be016f8db2736d5d8111282660b50f4c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 12 Oct 2021 09:18:54 +0200 Subject: 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]) } } -- cgit v1.2.3 From f7bb2bb5a753b3f1a37301dcff2d58e434ecd3af Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 12 Oct 2021 10:37:25 +0200 Subject: Don't use min FPS, throw instead Avoir creating a big output from a very low FPS input file --- server/helpers/ffprobe-utils.ts | 5 ++++- server/initializers/constants.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/server/helpers/ffprobe-utils.ts b/server/helpers/ffprobe-utils.ts index 8381dee84..767f37f9c 100644 --- a/server/helpers/ffprobe-utils.ts +++ b/server/helpers/ffprobe-utils.ts @@ -302,7 +302,10 @@ function computeFPS (fpsArg: number, resolution: VideoResolution) { // Hard FPS limits if (fps > VIDEO_TRANSCODING_FPS.MAX) fps = getClosestFramerateStandard(fps, 'HD_STANDARD') - else if (fps < VIDEO_TRANSCODING_FPS.MIN) fps = VIDEO_TRANSCODING_FPS.MIN + + if (fps < VIDEO_TRANSCODING_FPS.MIN) { + throw new Error(`Cannot compute FPS because ${fps} is lower than our minimum value ${VIDEO_TRANSCODING_FPS.MIN}`) + } return fps } diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 2fa0aa7bf..facd3b721 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -346,7 +346,7 @@ const VIEW_LIFETIME = { let CONTACT_FORM_LIFETIME = 60000 * 60 // 1 hour const VIDEO_TRANSCODING_FPS: VideoTranscodingFPS = { - MIN: 10, + MIN: 1, STANDARD: [ 24, 25, 30 ], HD_STANDARD: [ 50, 60 ], AVERAGE: 30, -- cgit v1.2.3 From 221d876fa7a9e92a5a6721b68c31d015b325393f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 12 Oct 2021 10:53:26 +0200 Subject: Fix upload can deactivate --- client/src/app/+videos/+video-edit/video-add.component.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/client/src/app/+videos/+video-edit/video-add.component.ts b/client/src/app/+videos/+video-edit/video-add.component.ts index bcb2fc4fa..25203de1b 100644 --- a/client/src/app/+videos/+video-edit/video-add.component.ts +++ b/client/src/app/+videos/+video-edit/video-add.component.ts @@ -144,6 +144,7 @@ export class VideoAddComponent implements OnInit, CanComponentDeactivate { } canDeactivate (): { canDeactivate: boolean, text?: string} { + if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate() if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate() if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate() if (this.secondStepType === 'go-live') return this.videoGoLive.canDeactivate() -- cgit v1.2.3 From 3c25d37aef66b125e8c66d38b04eb763f1b17bc6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 12 Oct 2021 13:30:41 +0200 Subject: Try to fix mock server ports --- shared/extra-utils/mock-servers/mock-instances-index.ts | 2 +- shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts | 2 +- shared/extra-utils/mock-servers/mock-object-storage.ts | 2 +- shared/extra-utils/mock-servers/mock-plugin-blocklist.ts | 2 +- shared/extra-utils/mock-servers/mock-proxy.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/shared/extra-utils/mock-servers/mock-instances-index.ts b/shared/extra-utils/mock-servers/mock-instances-index.ts index 2aabef9d2..5baec00de 100644 --- a/shared/extra-utils/mock-servers/mock-instances-index.ts +++ b/shared/extra-utils/mock-servers/mock-instances-index.ts @@ -29,7 +29,7 @@ export class MockInstancesIndex { }) }) - const port = 42101 + randomInt(1, 100) + const port = 42000 + randomInt(1, 1000) app.listen(port, () => res(port)) }) } diff --git a/shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts b/shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts index 5106fc66a..79be31f61 100644 --- a/shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts +++ b/shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts @@ -22,7 +22,7 @@ export class MockJoinPeerTubeVersions { }) }) - const port = 42201 + randomInt(1, 100) + const port = 43000 + randomInt(1, 1000) app.listen(port, () => res(port)) }) } diff --git a/shared/extra-utils/mock-servers/mock-object-storage.ts b/shared/extra-utils/mock-servers/mock-object-storage.ts index b6071b2f2..144f2819d 100644 --- a/shared/extra-utils/mock-servers/mock-object-storage.ts +++ b/shared/extra-utils/mock-servers/mock-object-storage.ts @@ -32,7 +32,7 @@ export class MockObjectStorage { ) }) - const port = 42301 + randomInt(1, 100) + const port = 44000 + randomInt(1, 1000) this.server = app.listen(port, () => res(port)) }) } diff --git a/shared/extra-utils/mock-servers/mock-plugin-blocklist.ts b/shared/extra-utils/mock-servers/mock-plugin-blocklist.ts index 6a71532b5..344d4bdbb 100644 --- a/shared/extra-utils/mock-servers/mock-plugin-blocklist.ts +++ b/shared/extra-utils/mock-servers/mock-plugin-blocklist.ts @@ -23,7 +23,7 @@ export class MockBlocklist { return res.json(this.body) }) - const port = 42201 + randomInt(1, 100) + const port = 45000 + randomInt(1, 1000) this.server = app.listen(port, () => res(port)) }) } diff --git a/shared/extra-utils/mock-servers/mock-proxy.ts b/shared/extra-utils/mock-servers/mock-proxy.ts index f955d3f9e..8583250f3 100644 --- a/shared/extra-utils/mock-servers/mock-proxy.ts +++ b/shared/extra-utils/mock-servers/mock-proxy.ts @@ -9,7 +9,7 @@ class MockProxy { initialize () { return new Promise(res => { - const port = 42501 + randomInt(1, 100) + const port = 46000 + randomInt(1, 1000) this.server = proxy(createServer()) this.server.listen(port, () => res(port)) -- cgit v1.2.3