mirror of
https://github.com/navidrome/navidrome.git
synced 2026-05-03 06:51:16 +00:00
refactor(ffmpeg): consolidate dynamic audio flag injection into a single function
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
27209ed26a
commit
501c6eaf8f
@ -387,18 +387,7 @@ func buildDynamicArgs(opts TranscodeOptions) []string {
|
|||||||
if opts.BitRate > 0 {
|
if opts.BitRate > 0 {
|
||||||
args = append(args, "-b:a", strconv.Itoa(opts.BitRate)+"k")
|
args = append(args, "-b:a", strconv.Itoa(opts.BitRate)+"k")
|
||||||
}
|
}
|
||||||
if opts.SampleRate > 0 {
|
args = injectDynamicAudioFlags(args, opts)
|
||||||
args = append(args, "-ar", strconv.Itoa(opts.SampleRate))
|
|
||||||
}
|
|
||||||
if opts.Channels > 0 {
|
|
||||||
args = append(args, "-ac", strconv.Itoa(opts.Channels))
|
|
||||||
}
|
|
||||||
// Only pass -sample_fmt for lossless output formats where bit depth matters.
|
|
||||||
// Lossy codecs (mp3, aac, opus) handle sample format conversion internally,
|
|
||||||
// and passing interleaved formats like "s16" causes silent failures.
|
|
||||||
if opts.BitDepth >= 16 && isLosslessOutputFormat(opts.Format) {
|
|
||||||
args = append(args, "-sample_fmt", bitDepthToSampleFmt(opts.BitDepth))
|
|
||||||
}
|
|
||||||
|
|
||||||
args = append(args, "-v", "0")
|
args = append(args, "-v", "0")
|
||||||
|
|
||||||
@ -417,8 +406,14 @@ func buildDynamicArgs(opts TranscodeOptions) []string {
|
|||||||
// ffmpeg honors the last occurrence of a duplicate flag.
|
// ffmpeg honors the last occurrence of a duplicate flag.
|
||||||
func buildTemplateArgs(opts TranscodeOptions) []string {
|
func buildTemplateArgs(opts TranscodeOptions) []string {
|
||||||
args := createFFmpegCommand(opts.Command, opts.FilePath, opts.BitRate, opts.Offset)
|
args := createFFmpegCommand(opts.Command, opts.FilePath, opts.BitRate, opts.Offset)
|
||||||
|
return injectDynamicAudioFlags(args, opts)
|
||||||
|
}
|
||||||
|
|
||||||
// Dynamically inject -ar, -ac, and -sample_fmt before the output target
|
// injectDynamicAudioFlags appends -ar, -ac, and -sample_fmt flags based on opts.
|
||||||
|
// Only passes -sample_fmt for lossless output formats where bit depth matters:
|
||||||
|
// lossy codecs (mp3, aac, opus) handle sample format conversion internally, and
|
||||||
|
// passing interleaved formats like "s16" causes silent failures.
|
||||||
|
func injectDynamicAudioFlags(args []string, opts TranscodeOptions) []string {
|
||||||
if opts.SampleRate > 0 {
|
if opts.SampleRate > 0 {
|
||||||
args = injectBeforeOutput(args, "-ar", strconv.Itoa(opts.SampleRate))
|
args = injectBeforeOutput(args, "-ar", strconv.Itoa(opts.SampleRate))
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user