FFmpeg: Refactor internal/ffmpeg/transcode_cmd.go #4604

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer
2025-01-09 10:38:56 +01:00
parent 2e175e3ed3
commit 9d1c97425c

View File

@@ -21,15 +21,15 @@ func TranscodeCmd(srcName, destName string, opt encode.Options) (cmd *exec.Cmd,
return nil, false, fmt.Errorf("empty destination filename")
}
// Don't transcode more than one video at the same time.
// Prevents multiple videos from being transcoded at the same time.
useMutex = true
// Use default FFmpeg command name.
// Use the default binary name if no name is specified.
if opt.Bin == "" {
opt.Bin = DefaultBin
}
// Don't use hardware transcoding for animated images.
// Always use software encoder for transcoding animated pictures into videos.
if fs.TypeAnimated[fs.FileType(srcName)] != "" {
cmd = exec.Command(
opt.Bin,
@@ -46,27 +46,23 @@ func TranscodeCmd(srcName, destName string, opt encode.Options) (cmd *exec.Cmd,
return cmd, useMutex, nil
}
// Display encoder info.
// Log encoder name if it is not the default.
if opt.Encoder != encode.SoftwareAvc {
log.Infof("convert: ffmpeg encoder %s selected", opt.Encoder.String())
}
// Transcode video with selected encoder.
switch opt.Encoder {
case encode.IntelAvc:
cmd = intel.TranscodeToAvcCmd(srcName, destName, opt)
case encode.AppleAvc:
cmd = apple.TranscodeToAvcCmd(srcName, destName, opt)
case encode.VaapiAvc:
cmd = vaapi.TranscodeToAvcCmd(srcName, destName, opt)
case encode.NvidiaAvc:
cmd = nvidia.TranscodeToAvcCmd(srcName, destName, opt)
case encode.V4LAvc:
cmd = v4l.TranscodeToAvcCmd(srcName, destName, opt)
default:
cmd = encode.TranscodeToAvcCmd(srcName, destName, opt)
}