diff --git a/server/src/domain/media/media.service.spec.ts b/server/src/domain/media/media.service.spec.ts index dc5934e7b1..0944016379 100644 --- a/server/src/domain/media/media.service.spec.ts +++ b/server/src/domain/media/media.service.spec.ts @@ -1799,7 +1799,7 @@ describe(MediaService.name, () => { '/original/path.ext', 'upload/encoded-video/user-id/as/se/asset-id.mp4', { - inputOptions: [], + inputOptions: ['-hwaccel rkmpp', '-hwaccel_output_format drm_prime', '-afbc rga'], outputOptions: [ `-c:v hevc_rkmpp`, '-c:a copy', @@ -1810,9 +1810,9 @@ describe(MediaService.name, () => { '-g 256', '-tag:v hvc1', '-v verbose', - '-vf scale=-2:720,format=yuv420p', + '-vf scale_rkrga=-2:720:format=nv12:afbc=1', '-level 153', - '-rc_mode 3', + '-rc_mode AVBR', '-b:v 10000k', ], twoPass: false, @@ -1834,7 +1834,7 @@ describe(MediaService.name, () => { '/original/path.ext', 'upload/encoded-video/user-id/as/se/asset-id.mp4', { - inputOptions: [], + inputOptions: ['-hwaccel rkmpp', '-hwaccel_output_format drm_prime', '-afbc rga'], outputOptions: [ `-c:v h264_rkmpp`, '-c:a copy', @@ -1844,9 +1844,9 @@ describe(MediaService.name, () => { '-map 0:1', '-g 256', '-v verbose', - '-vf scale=-2:720,format=yuv420p', + '-vf scale_rkrga=-2:720:format=nv12:afbc=1', '-level 51', - '-rc_mode 2', + '-rc_mode CQP', '-qp_init 30', ], twoPass: false, diff --git a/server/src/domain/media/media.util.ts b/server/src/domain/media/media.util.ts index e5890bdd03..d5f08ab0de 100644 --- a/server/src/domain/media/media.util.ts +++ b/server/src/domain/media/media.util.ts @@ -14,7 +14,7 @@ class BaseConfig implements VideoCodecSWConfig { getOptions(target: TranscodeTarget, videoStream: VideoStreamInfo, audioStream?: AudioStreamInfo) { const options = { - inputOptions: this.getBaseInputOptions(), + inputOptions: this.getBaseInputOptions(videoStream), outputOptions: [...this.getBaseOutputOptions(target, videoStream, audioStream), '-v verbose'], twoPass: this.eligibleForTwoPass(), } as TranscodeOptions; @@ -30,7 +30,8 @@ class BaseConfig implements VideoCodecSWConfig { return options; } - getBaseInputOptions(): string[] { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + getBaseInputOptions(videoStream: VideoStreamInfo): string[] { return []; } @@ -611,10 +612,25 @@ export class RKMPPConfig extends BaseHWConfig { return false; } - getBaseInputOptions() { + getBaseInputOptions(videoStream: VideoStreamInfo) { if (this.devices.length === 0) { throw new Error('No RKMPP device found'); } + if (this.shouldToneMap(videoStream)) { + // disable hardware decoding + return []; + } + return ['-hwaccel rkmpp', '-hwaccel_output_format drm_prime', '-afbc rga']; + } + + getFilterOptions(videoStream: VideoStreamInfo) { + if (this.shouldToneMap(videoStream)) { + // use software filter options + return super.getFilterOptions(videoStream); + } + if (this.shouldScale(videoStream)) { + return [`scale_rkrga=${this.getScaling(videoStream)}:format=nv12:afbc=1`]; + } return []; } @@ -638,10 +654,10 @@ export class RKMPPConfig extends BaseHWConfig { const bitrate = this.getMaxBitrateValue(); if (bitrate > 0) { // -b:v specifies max bitrate, average bitrate is derived automatically... - return ['-rc_mode 3', `-b:v ${bitrate}${this.getBitrateUnit()}`]; + return ['-rc_mode AVBR', `-b:v ${bitrate}${this.getBitrateUnit()}`]; } // use CRF value as QP value - return ['-rc_mode 2', `-qp_init ${this.config.crf}`]; + return ['-rc_mode CQP', `-qp_init ${this.config.crf}`]; } getSupportedCodecs() {