1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-29 15:11:58 +00:00

use vbr for qsv if maxrate is set

This commit is contained in:
mertalev 2024-08-03 11:37:08 -04:00
parent 3968d76a57
commit 2997d3128b
No known key found for this signature in database
GPG key ID: 9181CD92C0A1C5E3

View file

@ -167,7 +167,7 @@ export class BaseConfig implements VideoCodecSWConfig {
return [ return [
`-${this.useCQP() ? 'q:v' : 'crf'} ${this.config.crf}`, `-${this.useCQP() ? 'q:v' : 'crf'} ${this.config.crf}`,
`-maxrate ${bitrates.max}${bitrates.unit}`, `-maxrate ${bitrates.max}${bitrates.unit}`,
`-bufsize ${bitrates.max * 2}${bitrates.unit}`, `-bufsize ${bitrates.max * 4}${bitrates.unit}`,
]; ];
} else { } else {
return [`-${this.useCQP() ? 'q:v' : 'crf'} ${this.config.crf}`]; return [`-${this.useCQP() ? 'q:v' : 'crf'} ${this.config.crf}`];
@ -255,7 +255,7 @@ export class BaseConfig implements VideoCodecSWConfig {
getBitrateUnit() { getBitrateUnit() {
const maxBitrate = this.getMaxBitrateValue(); const maxBitrate = this.getMaxBitrateValue();
return this.config.maxBitrate.trim().slice(maxBitrate.toString().length); // use inputted unit if provided return this.config.maxBitrate.trim().slice(maxBitrate.toString().length) || 'k'; // use inputted unit if provided
} }
getMaxBitrateValue() { getMaxBitrateValue() {
@ -575,14 +575,14 @@ export class NvencSwDecodeConfig extends BaseHWConfig {
return [ return [
`-b:v ${bitrates.target}${bitrates.unit}`, `-b:v ${bitrates.target}${bitrates.unit}`,
`-maxrate ${bitrates.max}${bitrates.unit}`, `-maxrate ${bitrates.max}${bitrates.unit}`,
`-bufsize ${bitrates.target}${bitrates.unit}`, `-bufsize ${bitrates.max * 4}${bitrates.unit}`,
'-multipass 2', '-multipass 2',
]; ];
} else if (bitrates.max > 0) { } else if (bitrates.max > 0) {
return [ return [
`-cq:v ${this.config.crf}`, `-cq:v ${this.config.crf}`,
`-maxrate ${bitrates.max}${bitrates.unit}`, `-maxrate ${bitrates.max}${bitrates.unit}`,
`-bufsize ${bitrates.target}${bitrates.unit}`, `-bufsize ${bitrates.max * 4}${bitrates.unit}`,
]; ];
} else { } else {
return [`-cq:v ${this.config.crf}`]; return [`-cq:v ${this.config.crf}`];
@ -689,13 +689,16 @@ export class QsvSwDecodeConfig extends BaseHWConfig {
} }
getBitrateOptions() { getBitrateOptions() {
const options = []; const { max, min, unit, target } = this.getBitrateDistribution();
options.push(`-${this.useCQP() ? 'q:v' : 'global_quality:v'} ${this.config.crf}`); return max > 0
const bitrates = this.getBitrateDistribution(); ? [
if (bitrates.max > 0) { `-b:v ${target}${unit}`,
options.push(`-maxrate ${bitrates.max}${bitrates.unit}`, `-bufsize ${bitrates.max * 2}${bitrates.unit}`); `-maxrate ${max}${unit}`,
} `-minrate ${min}${unit}`,
return options; `-bufsize ${max * 4}${unit}`,
'-rc_mode 3',
] // QVBR is buggy, so use VBR instead
: [`-${this.useCQP() ? 'q:v' : 'global_quality:v'} ${this.config.crf}`];
} }
getSupportedCodecs() { getSupportedCodecs() {
@ -823,7 +826,7 @@ export class VAAPIConfig extends BaseHWConfig {
} }
getBitrateOptions() { getBitrateOptions() {
const bitrates = this.getBitrateDistribution(); const { max, min, unit, target } = this.getBitrateDistribution();
const options = []; const options = [];
if (this.config.targetVideoCodec === VideoCodec.VP9) { if (this.config.targetVideoCodec === VideoCodec.VP9) {
@ -831,11 +834,12 @@ export class VAAPIConfig extends BaseHWConfig {
} }
// VAAPI doesn't allow setting both quality and max bitrate // VAAPI doesn't allow setting both quality and max bitrate
if (bitrates.max > 0) { if (max > 0) {
options.push( options.push(
`-b:v ${bitrates.target}${bitrates.unit}`, `-b:v ${target}${unit}`,
`-maxrate ${bitrates.max}${bitrates.unit}`, `-maxrate ${max}${unit}`,
`-minrate ${bitrates.min}${bitrates.unit}`, `-minrate ${min}${unit}`,
`-bufsize ${max * 4}${unit}`,
'-rc_mode 3', '-rc_mode 3',
); // variable bitrate ); // variable bitrate
} else if (this.useCQP()) { } else if (this.useCQP()) {