Skip to content

High performance self-hosted photo and video management solution.

fix(server): use crf-based two pass for vp9 if max bitrate is disabled (#6535)

Mertc8b33c00ecd0
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}`,