From 18b93ddc73151d546ef676148ddfc91bad4307f2 Mon Sep 17 00:00:00 2001 From: San Date: Mon, 4 Nov 2024 15:20:15 +0800 Subject: [PATCH] if hw decoding failed with hw dec config enabled, try sw dec+hw enc first, then full sw dec+enc --- server/src/services/media.service.ts | 24 ++++++++++++++++++++---- server/src/utils/media.ts | 20 ++++++++++---------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/server/src/services/media.service.ts b/server/src/services/media.service.ts index 4ef5b74676..e2a31caef6 100644 --- a/server/src/services/media.service.ts +++ b/server/src/services/media.service.ts @@ -341,10 +341,26 @@ export class MediaService extends BaseService { if (ffmpeg.accel === TranscodeHWAccel.DISABLED) { return JobStatus.FAILED; } - this.logger.error(`Retrying with ${ffmpeg.accel.toUpperCase()} acceleration disabled`); - const config = BaseConfig.create({ ...ffmpeg, accel: TranscodeHWAccel.DISABLED }); - command = config.getCommand(target, mainVideoStream, mainAudioStream); - await this.mediaRepository.transcode(input, output, command); + + let partialFallbackSuccess = false; + if (ffmpeg.accelDecode) { + try { + this.logger.error(`Retrying with ${ffmpeg.accel.toUpperCase()} acceleration but software decoding`); + const config = BaseConfig.create({...ffmpeg, accelDecode: false}); + command = config.getCommand(target, mainVideoStream, mainAudioStream); + await this.mediaRepository.transcode(input, output, command); + partialFallbackSuccess = true; + } catch (error: any) { + this.logger.error(`Error occurred during transcoding: ${error.message}`); + } + } + + if (!partialFallbackSuccess) { + this.logger.error(`Retrying with ${ffmpeg.accel.toUpperCase()} acceleration disabled`); + const config = BaseConfig.create({...ffmpeg, accel: TranscodeHWAccel.DISABLED}); + command = config.getCommand(target, mainVideoStream, mainAudioStream); + await this.mediaRepository.transcode(input, output, command); + } } this.logger.log(`Successfully encoded ${asset.id}`); diff --git a/server/src/utils/media.ts b/server/src/utils/media.ts index b242be8507..a4f70ebd8b 100644 --- a/server/src/utils/media.ts +++ b/server/src/utils/media.ts @@ -924,8 +924,7 @@ export class RkmppSwDecodeConfig extends BaseHWConfig { return false; } - // eslint-disable-next-line @typescript-eslint/no-unused-vars - getBaseInputOptions(videoStream: VideoStreamInfo): string[] { + getBaseInputOptions(): string[] { if (this.devices.length === 0) { throw new Error('No RKMPP device found'); } @@ -978,16 +977,12 @@ export class RkmppHwDecodeConfig extends RkmppSwDecodeConfig { this.hasMaliOpenCL = hasMaliOpenCL; } - getBaseInputOptions(videoStream: VideoStreamInfo) { + getBaseInputOptions() { if (this.devices.length === 0) { throw new Error('No RKMPP device found'); } - if (!this.shouldToneMap(videoStream) || (this.shouldToneMap(videoStream) && this.hasMaliOpenCL)) { - return ['-hwaccel rkmpp', '-hwaccel_output_format drm_prime', '-afbc rga', '-noautorotate']; - } - - return []; + return ['-hwaccel rkmpp', '-hwaccel_output_format drm_prime', '-afbc rga', '-noautorotate']; } getFilterOptions(videoStream: VideoStreamInfo) { @@ -1002,8 +997,13 @@ export class RkmppHwDecodeConfig extends RkmppSwDecodeConfig { 'format=drm_prime', ]; } - // use CPU for scaling & tone mapping - return super.getFilterOptions(videoStream); + return [ // use RKMPP for scaling, CPU for tone mapping (only works on RK3588 which support 10bit output) + `scale_rkrga=${this.getScaling(videoStream)}:format=p010`, + 'hwdownload', + 'format=yuv420p10le', + `tonemapx=tonemap=${this.config.tonemap}:desat=0:p=${primaries}:t=${transfer}:m=${matrix}:r=pc:peak=100:format=yuv420p`, + 'hwupload', + ]; } else if (this.shouldScale(videoStream)) { return [`scale_rkrga=${this.getScaling(videoStream)}:format=nv12:afbc=1`]; }