1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-26 10:50:29 +02:00

fix(server): h264 and hevc not respecting max bitrate (#3052)

* added `-bufsize` flag

* updated test
This commit is contained in:
Mert 2023-06-30 21:48:05 -04:00 committed by GitHub
parent 615893be38
commit b1fcf02d13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -396,6 +396,7 @@ describe(MediaService.name, () => {
'-preset ultrafast', '-preset ultrafast',
'-crf 23', '-crf 23',
'-maxrate 4500k', '-maxrate 4500k',
'-bufsize 9000k',
], ],
twoPass: false, twoPass: false,
}, },

View File

@ -284,7 +284,14 @@ export class MediaService {
} else if (constrainMaximumBitrate || isVP9) { } else if (constrainMaximumBitrate || isVP9) {
// for vp9, these flags work for both one-pass and two-pass // for vp9, these flags work for both one-pass and two-pass
options.push(`-crf ${ffmpeg.crf}`); options.push(`-crf ${ffmpeg.crf}`);
options.push(`${isVP9 ? '-b:v' : '-maxrate'} ${maxBitrateValue}${bitrateUnit}`); if (isVP9) {
options.push(`-b:v ${maxBitrateValue}${bitrateUnit}`);
} else {
options.push(`-maxrate ${maxBitrateValue}${bitrateUnit}`);
// -bufsize is the peak possible bitrate at any moment, while -maxrate is the max rolling average bitrate
// needed for -maxrate to be enforced
options.push(`-bufsize ${maxBitrateValue * 2}${bitrateUnit}`);
}
} else { } else {
options.push(`-crf ${ffmpeg.crf}`); options.push(`-crf ${ffmpeg.crf}`);
} }