Fix custom transcode arguments (#3491)

This commit is contained in:
DingDongSoLong4 2023-02-27 23:15:52 +02:00 committed by GitHub
parent 967a25f64a
commit 445e0a7311
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 15 deletions

View file

@ -37,6 +37,8 @@ type StreamManager struct {
type StreamManagerConfig interface {
GetMaxStreamingTranscodeSize() models.StreamingResolutionEnum
GetLiveTranscodeInputArgs() []string
GetLiveTranscodeOutputArgs() []string
}
func NewStreamManager(cacheDir string, encoder FFMpeg, ffprobe FFProbe, config StreamManagerConfig, lockManager *fsutil.ReadLockManager) *StreamManager {

View file

@ -202,10 +202,15 @@ func (t StreamType) FileDir(hash string, maxTranscodeSize int) string {
}
}
func (s *runningStream) makeStreamArgs(segment int) Args {
func (s *runningStream) makeStreamArgs(sm *StreamManager, segment int) Args {
extraInputArgs := sm.config.GetLiveTranscodeInputArgs()
extraOutputArgs := sm.config.GetLiveTranscodeOutputArgs()
args := Args{"-hide_banner"}
args = args.LogLevel(LogLevelError)
args = append(args, extraInputArgs...)
if segment > 0 {
args = args.Seek(float64(segment * segmentLength))
}
@ -219,6 +224,8 @@ func (s *runningStream) makeStreamArgs(segment int) Args {
args = append(args, s.streamType.Args(segment, videoFilter, videoOnly, s.outputDir)...)
args = append(args, extraOutputArgs...)
return args
}
@ -441,7 +448,7 @@ func (sm *StreamManager) startTranscode(stream *runningStream, segment int, done
lockCtx := sm.lockManager.ReadLock(sm.context, stream.vf.Path)
args := stream.makeStreamArgs(segment)
args := stream.makeStreamArgs(sm, segment)
cmd := sm.encoder.Command(lockCtx, args)
stderr, err := cmd.StderrPipe()

View file

@ -89,23 +89,34 @@ type TranscodeOptions struct {
StartTime float64
}
func (o TranscodeOptions) makeStreamArgs(vf *file.VideoFile, maxScale int, startTime float64) Args {
func (o TranscodeOptions) makeStreamArgs(sm *StreamManager) Args {
maxTranscodeSize := sm.config.GetMaxStreamingTranscodeSize().GetMaxResolution()
if o.Resolution != "" {
maxTranscodeSize = models.StreamingResolutionEnum(o.Resolution).GetMaxResolution()
}
extraInputArgs := sm.config.GetLiveTranscodeInputArgs()
extraOutputArgs := sm.config.GetLiveTranscodeOutputArgs()
args := Args{"-hide_banner"}
args = args.LogLevel(LogLevelError)
if startTime != 0 {
args = args.Seek(startTime)
args = append(args, extraInputArgs...)
if o.StartTime != 0 {
args = args.Seek(o.StartTime)
}
args = args.Input(vf.Path)
args = args.Input(o.VideoFile.Path)
videoOnly := ProbeAudioCodec(vf.AudioCodec) == MissingUnsupported
videoOnly := ProbeAudioCodec(o.VideoFile.AudioCodec) == MissingUnsupported
var videoFilter VideoFilter
videoFilter = videoFilter.ScaleMax(vf.Width, vf.Height, maxScale)
videoFilter = videoFilter.ScaleMax(o.VideoFile.Width, o.VideoFile.Height, maxTranscodeSize)
args = append(args, o.StreamType.Args(videoFilter, videoOnly)...)
args = append(args, extraOutputArgs...)
args = args.Output("pipe:")
return args
@ -134,12 +145,7 @@ func (sm *StreamManager) ServeTranscode(w http.ResponseWriter, r *http.Request,
}
func (sm *StreamManager) getTranscodeStream(ctx *fsutil.LockContext, options TranscodeOptions) (http.HandlerFunc, error) {
maxTranscodeSize := sm.config.GetMaxStreamingTranscodeSize().GetMaxResolution()
if options.Resolution != "" {
maxTranscodeSize = models.StreamingResolutionEnum(options.Resolution).GetMaxResolution()
}
args := options.makeStreamArgs(options.VideoFile, maxTranscodeSize, options.StartTime)
args := options.makeStreamArgs(sm)
cmd := sm.encoder.Command(ctx, args)
stdout, err := cmd.StdoutPipe()

View file

@ -287,7 +287,7 @@
},
"live_transcode": {
"input_args": {
"heading": "FFmpeg LiveTranscode Input Args",
"heading": "FFmpeg Live Transcode Input Args",
"desc": "Advanced: Additional arguments to pass to ffmpeg before the input field when live transcoding video."
},
"output_args": {