From 679c12e69c9f3a2d003ee3abe8b8da49f25b2bd3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 6 Aug 2021 13:35:25 +0200 Subject: Improve target bitrate calculation --- server/tests/cli/optimize-old-videos.ts | 20 +++++++------------- server/tests/cli/print-transcode-command.ts | 10 +++++----- 2 files changed, 12 insertions(+), 18 deletions(-) (limited to 'server/tests/cli') diff --git a/server/tests/cli/optimize-old-videos.ts b/server/tests/cli/optimize-old-videos.ts index 579b2e7d8..9b75ae164 100644 --- a/server/tests/cli/optimize-old-videos.ts +++ b/server/tests/cli/optimize-old-videos.ts @@ -2,6 +2,7 @@ import 'mocha' import * as chai from 'chai' +import { getMaxBitrate } from '@shared/core-utils' import { cleanupTests, createMultipleServers, @@ -12,9 +13,7 @@ import { wait, waitJobs } from '@shared/extra-utils' -import { getMaxBitrate, VideoResolution } from '@shared/models' import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../helpers/ffprobe-utils' -import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants' const expect = chai.expect @@ -30,14 +29,7 @@ describe('Test optimize old videos', function () { await doubleFollow(servers[0], servers[1]) - 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() // Upload two videos for our needs await servers[0].videos.upload({ attributes: { name: 'video1', fixture: tempFixturePath } }) @@ -88,10 +80,12 @@ describe('Test optimize old videos', function () { const path = servers[0].servers.buildWebTorrentFilePath(file.fileUrl) const bitrate = await getVideoFileBitrate(path) const fps = await getVideoFileFPS(path) - const resolution = await getVideoFileResolution(path) + const data = await getVideoFileResolution(path) + + expect(data.resolution).to.equal(file.resolution.id) - expect(resolution.videoFileResolution).to.equal(file.resolution.id) - expect(bitrate).to.be.below(getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)) + const maxBitrate = getMaxBitrate({ ...data, fps }) + expect(bitrate).to.be.below(maxBitrate) } } }) diff --git a/server/tests/cli/print-transcode-command.ts b/server/tests/cli/print-transcode-command.ts index 3a7969e68..e328a6072 100644 --- a/server/tests/cli/print-transcode-command.ts +++ b/server/tests/cli/print-transcode-command.ts @@ -3,16 +3,16 @@ import 'mocha' import * as chai from 'chai' import { getVideoFileBitrate, getVideoFileFPS } from '@server/helpers/ffprobe-utils' -import { CLICommand } from '@shared/extra-utils' -import { getTargetBitrate, VideoResolution } from '../../../shared/models/videos' -import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants' +import { getMaxBitrate } from '@shared/core-utils' +import { buildAbsoluteFixturePath, CLICommand } from '@shared/extra-utils' +import { VideoResolution } from '../../../shared/models/videos' const expect = chai.expect describe('Test create transcoding jobs', function () { it('Should print the correct command for each resolution', async function () { - const fixturePath = 'server/tests/fixtures/video_short.webm' + const fixturePath = buildAbsoluteFixturePath('video_short.webm') const fps = await getVideoFileFPS(fixturePath) const bitrate = await getVideoFileBitrate(fixturePath) @@ -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(getTargetBitrate(resolution, fps, VIDEO_TRANSCODING_FPS), bitrate) + const targetBitrate = Math.min(getMaxBitrate({ resolution, fps, ratio: 16 / 9 }), bitrate) expect(command).to.includes(`-vf scale=w=-2:h=${resolution}`) expect(command).to.includes(`-y -acodec aac -vcodec libx264`) -- cgit v1.2.3