From c8b33c00ecd0a3fc15d3f6938734ae6bcc06da3f Mon Sep 17 00:00:00 2001 From: Mert <101130780+mertalev@users.noreply.github.com> Date: Sat, 20 Jan 2024 15:05:08 -0500 Subject: [PATCH] fix(server): use crf-based two pass for vp9 if max bitrate is disabled (#6535) use crf-based two pass for vp9 if max bitrate is disabled --- server/src/domain/media/media.service.spec.ts | 33 +++++++++++++++++++ server/src/domain/media/media.util.ts | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/server/src/domain/media/media.service.spec.ts b/server/src/domain/media/media.service.spec.ts index 258cf395e2..7f56501011 100644 --- a/server/src/domain/media/media.service.spec.ts +++ b/server/src/domain/media/media.service.spec.ts @@ -888,6 +888,39 @@ describe(MediaService.name, () => { ); }); + it('should transcode by crf in two passes for vp9 when two pass mode is enabled and max bitrate is disabled', async () => { + mediaMock.probe.mockResolvedValue(probeStub.matroskaContainer); + configMock.load.mockResolvedValue([ + { key: SystemConfigKey.FFMPEG_MAX_BITRATE, value: '0' }, + { key: SystemConfigKey.FFMPEG_TWO_PASS, value: true }, + { key: SystemConfigKey.FFMPEG_TARGET_VIDEO_CODEC, value: VideoCodec.VP9 }, + ]); + assetMock.getByIds.mockResolvedValue([assetStub.video]); + await sut.handleVideoConversion({ id: assetStub.video.id }); + expect(mediaMock.transcode).toHaveBeenCalledWith( + '/original/path.ext', + 'upload/encoded-video/user-id/as/se/asset-id.mp4', + { + inputOptions: [], + outputOptions: [ + '-c:v vp9', + '-c:a aac', + '-movflags faststart', + '-fps_mode passthrough', + '-map 0:0', + '-map 0:1', + '-v verbose', + '-vf scale=-2:720,format=yuv420p', + '-cpu-used 5', + '-row-mt 1', + '-crf 23', + '-b:v 0', + ], + twoPass: true, + }, + ); + }); + it('should configure preset for vp9', async () => { mediaMock.probe.mockResolvedValue(probeStub.matroskaContainer); configMock.load.mockResolvedValue([ diff --git a/server/src/domain/media/media.util.ts b/server/src/domain/media/media.util.ts index 4b6b417286..606cb3f1a1 100644 --- a/server/src/domain/media/media.util.ts +++ b/server/src/domain/media/media.util.ts @@ -356,7 +356,7 @@ export class VP9Config extends BaseConfig { getBitrateOptions() { const bitrates = this.getBitrateDistribution(); - if (this.eligibleForTwoPass()) { + if (bitrates.max > 0 && this.eligibleForTwoPass()) { return [ `-b:v ${bitrates.target}${bitrates.unit}`, `-minrate ${bitrates.min}${bitrates.unit}`,