From 397570ad1a81afc7c691febeb47770108c61be94 Mon Sep 17 00:00:00 2001 From: Mert <101130780+mertalev@users.noreply.github.com> Date: Wed, 21 Feb 2024 00:25:30 -0500 Subject: [PATCH] chore(server): change transcode default to accept all supported audio codecs (#7283) * change transcode defaults * don't untick accepted audio codecs * no need to change the transcode policy * fix tests * remove log --- server/src/domain/media/media.service.spec.ts | 82 ++++++++++--------- .../system-config/system-config.core.ts | 2 +- .../system-config.service.spec.ts | 2 +- .../infra/entities/system-config.entity.ts | 2 +- .../settings/ffmpeg/ffmpeg-settings.svelte | 5 +- 5 files changed, 50 insertions(+), 43 deletions(-) diff --git a/server/src/domain/media/media.service.spec.ts b/server/src/domain/media/media.service.spec.ts index aa48568b90..f4c9aa53e7 100644 --- a/server/src/domain/media/media.service.spec.ts +++ b/server/src/domain/media/media.service.spec.ts @@ -1,5 +1,6 @@ import { AssetType, + AudioCodec, Colorspace, ExifEntity, SystemConfigKey, @@ -475,7 +476,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v h264', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -542,7 +543,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v h264', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -571,7 +572,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v h264', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -629,7 +630,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v h264', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -706,7 +707,10 @@ describe(MediaService.name, () => { it('should copy video stream when video matches target', async () => { mediaMock.probe.mockResolvedValue(probeStub.matroskaContainer); - configMock.load.mockResolvedValue([{ key: SystemConfigKey.FFMPEG_TARGET_VIDEO_CODEC, value: VideoCodec.HEVC }]); + configMock.load.mockResolvedValue([ + { key: SystemConfigKey.FFMPEG_TARGET_VIDEO_CODEC, value: VideoCodec.HEVC }, + { key: SystemConfigKey.FFMPEG_ACCEPTED_AUDIO_CODECS, value: [AudioCodec.AAC] }, + ]); assetMock.getByIds.mockResolvedValue([assetStub.video]); await sut.handleVideoConversion({ id: assetStub.video.id }); expect(mediaMock.transcode).toHaveBeenCalledWith( @@ -770,7 +774,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v h264', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -836,7 +840,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v h264', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -868,7 +872,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v h264', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -897,7 +901,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v h264', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -928,7 +932,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v vp9', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -962,7 +966,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v vp9', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -994,7 +998,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v vp9', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1026,7 +1030,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v vp9', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1057,7 +1061,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v vp9', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1087,7 +1091,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v h264', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1117,7 +1121,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v h264', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1147,7 +1151,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v hevc', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1181,7 +1185,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v hevc', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1248,7 +1252,7 @@ describe(MediaService.name, () => { '-rc-lookahead 20', '-i_qfactor 0.75', `-c:v h264_nvenc`, - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1286,7 +1290,7 @@ describe(MediaService.name, () => { '-rc-lookahead 20', '-i_qfactor 0.75', `-c:v h264_nvenc`, - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1320,7 +1324,7 @@ describe(MediaService.name, () => { '-rc-lookahead 20', '-i_qfactor 0.75', `-c:v h264_nvenc`, - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1355,7 +1359,7 @@ describe(MediaService.name, () => { '-rc-lookahead 20', '-i_qfactor 0.75', `-c:v h264_nvenc`, - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1386,7 +1390,7 @@ describe(MediaService.name, () => { '-rc-lookahead 20', '-i_qfactor 0.75', `-c:v h264_nvenc`, - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1418,7 +1422,7 @@ describe(MediaService.name, () => { inputOptions: ['-init_hw_device qsv=hw', '-filter_hw_device hw'], outputOptions: [ `-c:v h264_qsv`, - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1455,7 +1459,7 @@ describe(MediaService.name, () => { inputOptions: ['-init_hw_device qsv=hw,child_device=/dev/dri/renderD128', '-filter_hw_device hw'], outputOptions: [ `-c:v h264_qsv`, - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1491,7 +1495,7 @@ describe(MediaService.name, () => { inputOptions: ['-init_hw_device qsv=hw', '-filter_hw_device hw'], outputOptions: [ `-c:v h264_qsv`, - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1524,7 +1528,7 @@ describe(MediaService.name, () => { inputOptions: ['-init_hw_device qsv=hw', '-filter_hw_device hw'], outputOptions: [ `-c:v vp9_qsv`, - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1568,7 +1572,7 @@ describe(MediaService.name, () => { inputOptions: ['-init_hw_device vaapi=accel:/dev/dri/renderD128', '-filter_hw_device accel'], outputOptions: [ `-c:v h264_vaapi`, - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1600,7 +1604,7 @@ describe(MediaService.name, () => { inputOptions: ['-init_hw_device vaapi=accel:/dev/dri/renderD128', '-filter_hw_device accel'], outputOptions: [ `-c:v h264_vaapi`, - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1634,7 +1638,7 @@ describe(MediaService.name, () => { inputOptions: ['-init_hw_device vaapi=accel:/dev/dri/renderD128', '-filter_hw_device accel'], outputOptions: [ `-c:v h264_vaapi`, - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1664,7 +1668,7 @@ describe(MediaService.name, () => { inputOptions: ['-init_hw_device vaapi=accel:/dev/dri/card1', '-filter_hw_device accel'], outputOptions: [ `-c:v h264_vaapi`, - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1690,7 +1694,7 @@ describe(MediaService.name, () => { inputOptions: ['-init_hw_device vaapi=accel:/dev/dri/renderD129', '-filter_hw_device accel'], outputOptions: [ `-c:v h264_vaapi`, - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1724,7 +1728,7 @@ describe(MediaService.name, () => { inputOptions: ['-init_hw_device vaapi=accel:/dev/dri/renderD128', '-filter_hw_device accel'], outputOptions: [ `-c:v h264_vaapi`, - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1757,7 +1761,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v h264', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1798,7 +1802,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ `-c:v hevc_rkmpp_encoder`, - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1838,7 +1842,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ `-c:v h264_rkmpp_encoder`, - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1872,7 +1876,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v h264', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1899,7 +1903,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v h264', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', @@ -1926,7 +1930,7 @@ describe(MediaService.name, () => { inputOptions: [], outputOptions: [ '-c:v h264', - '-c:a aac', + '-c:a copy', '-movflags faststart', '-fps_mode passthrough', '-map 0:0', diff --git a/server/src/domain/system-config/system-config.core.ts b/server/src/domain/system-config/system-config.core.ts index 1591e87d63..eb661133b2 100644 --- a/server/src/domain/system-config/system-config.core.ts +++ b/server/src/domain/system-config/system-config.core.ts @@ -33,7 +33,7 @@ export const defaults = Object.freeze({ targetVideoCodec: VideoCodec.H264, acceptedVideoCodecs: [VideoCodec.H264], targetAudioCodec: AudioCodec.AAC, - acceptedAudioCodecs: [AudioCodec.AAC], + acceptedAudioCodecs: [AudioCodec.AAC, AudioCodec.MP3, AudioCodec.LIBOPUS], targetResolution: '720', maxBitrate: '0', bframes: -1, diff --git a/server/src/domain/system-config/system-config.service.spec.ts b/server/src/domain/system-config/system-config.service.spec.ts index 8addc63a0f..ec0b4b8f4f 100644 --- a/server/src/domain/system-config/system-config.service.spec.ts +++ b/server/src/domain/system-config/system-config.service.spec.ts @@ -43,7 +43,7 @@ const updatedConfig = Object.freeze({ threads: 0, preset: 'ultrafast', targetAudioCodec: AudioCodec.AAC, - acceptedAudioCodecs: [AudioCodec.AAC], + acceptedAudioCodecs: [AudioCodec.AAC, AudioCodec.MP3, AudioCodec.LIBOPUS], targetResolution: '720', targetVideoCodec: VideoCodec.H264, acceptedVideoCodecs: [VideoCodec.H264], diff --git a/server/src/infra/entities/system-config.entity.ts b/server/src/infra/entities/system-config.entity.ts index 1515630cea..8307a0328e 100644 --- a/server/src/infra/entities/system-config.entity.ts +++ b/server/src/infra/entities/system-config.entity.ts @@ -7,7 +7,7 @@ export class SystemConfigEntity { key!: SystemConfigKey; @Column({ type: 'varchar', nullable: true, transformer: { to: JSON.stringify, from: JSON.parse } }) - value!: T; + value!: T | T[]; } export type SystemConfigValue = string | number | boolean; diff --git a/web/src/lib/components/admin-page/settings/ffmpeg/ffmpeg-settings.svelte b/web/src/lib/components/admin-page/settings/ffmpeg/ffmpeg-settings.svelte index cd73b77f44..496d579cae 100644 --- a/web/src/lib/components/admin-page/settings/ffmpeg/ffmpeg-settings.svelte +++ b/web/src/lib/components/admin-page/settings/ffmpeg/ffmpeg-settings.svelte @@ -90,7 +90,10 @@ ]} name="acodec" isEdited={config.ffmpeg.targetAudioCodec !== savedConfig.ffmpeg.targetAudioCodec} - on:select={() => (config.ffmpeg.acceptedAudioCodecs = [config.ffmpeg.targetAudioCodec])} + on:select={() => + config.ffmpeg.acceptedAudioCodecs.includes(config.ffmpeg.targetAudioCodec) + ? null + : config.ffmpeg.acceptedAudioCodecs.push(config.ffmpeg.targetAudioCodec)} />