Use hw decoding, sw tone-mapping on HDR files using RKMPP w/o OpenCL

This commit is contained in:
San 2024-11-01 15:35:46 +08:00
parent e46db37e44
commit e851a9b099
2 changed files with 12 additions and 7 deletions

View File

@ -2260,7 +2260,7 @@ describe(MediaService.name, () => {
); );
}); });
it('should use software decoding and tone-mapping if opencl is not available', async () => { it('should use software tone-mapping if opencl is not available', async () => {
storageMock.readdir.mockResolvedValue(['renderD128']); storageMock.readdir.mockResolvedValue(['renderD128']);
storageMock.stat.mockResolvedValue({ isFile: () => false, isCharacterDevice: () => false } as Stats); storageMock.stat.mockResolvedValue({ isFile: () => false, isCharacterDevice: () => false } as Stats);
mediaMock.probe.mockResolvedValue(probeStub.videoStreamHDR); mediaMock.probe.mockResolvedValue(probeStub.videoStreamHDR);
@ -2273,10 +2273,10 @@ describe(MediaService.name, () => {
'/original/path.ext', '/original/path.ext',
'upload/encoded-video/user-id/as/se/asset-id.mp4', 'upload/encoded-video/user-id/as/se/asset-id.mp4',
expect.objectContaining({ expect.objectContaining({
inputOptions: [], inputOptions: expect.any(Array),
outputOptions: expect.arrayContaining([ outputOptions: expect.arrayContaining([
expect.stringContaining( expect.stringContaining(
'tonemapx=tonemap=hable:desat=0:p=bt709:t=bt709:m=bt709:r=pc:peak=100:format=yuv420p', 'tonemapx=tonemap=hable:desat=0:p=bt709:t=bt709:m=bt709:r=pc:peak=100:format=',
), ),
]), ]),
twoPass: false, twoPass: false,

View File

@ -987,18 +987,23 @@ export class RkmppHwDecodeConfig extends RkmppSwDecodeConfig {
getFilterOptions(videoStream: VideoStreamInfo) { getFilterOptions(videoStream: VideoStreamInfo) {
if (this.shouldToneMap(videoStream)) { if (this.shouldToneMap(videoStream)) {
const { primaries, transfer, matrix } = this.getColors();
if (this.hasMaliOpenCL) { if (this.hasMaliOpenCL) {
const { primaries, transfer, matrix } = this.getColors(); return [ // use RKMPP for scaling, OpenCL for tone mapping
return [
`scale_rkrga=${this.getScaling(videoStream)}:format=p010:afbc=1`, `scale_rkrga=${this.getScaling(videoStream)}:format=p010:afbc=1`,
'hwmap=derive_device=opencl:mode=read', 'hwmap=derive_device=opencl:mode=read',
`tonemap_opencl=format=nv12:r=pc:p=${primaries}:t=${transfer}:m=${matrix}:tonemap=${this.config.tonemap}:desat=0:tonemap_mode=lum:peak=100`, `tonemap_opencl=format=nv12:r=pc:p=${primaries}:t=${transfer}:m=${matrix}:tonemap=${this.config.tonemap}:desat=0:tonemap_mode=lum:peak=100`,
'hwmap=derive_device=rkmpp:mode=write:reverse=1', 'hwmap=derive_device=rkmpp:mode=write:reverse=1',
'format=drm_prime', 'format=drm_prime',
]; ];
} else {
return super.getFilterOptions(videoStream);
} }
return [ // use RKMPP for scaling, CPU for tone mapping
`scale_rkrga=${this.getScaling(videoStream)}:format=nv12`,
'hwdownload',
'format=nv12',
`tonemapx=tonemap=${this.config.tonemap}:desat=0:p=${primaries}:t=${transfer}:m=${matrix}:r=pc:peak=100:format=nv12`,
'hwupload',
];
} else if (this.shouldScale(videoStream)) { } else if (this.shouldScale(videoStream)) {
return [`scale_rkrga=${this.getScaling(videoStream)}:format=nv12:afbc=1`]; return [`scale_rkrga=${this.getScaling(videoStream)}:format=nv12:afbc=1`];
} }