skip reencoding compatible video streams (#4783)

* skip reencoding compatible video streams
* don't attempt copy on transcode with resize
This commit is contained in:
HookedBehemoth
2024-05-08 05:24:13 +02:00
committed by GitHub
parent c5abe28375
commit 9cc26f7b75

View File

@@ -138,14 +138,30 @@ type TranscodeOptions struct {
StartTime float64 StartTime float64
} }
func FileGetCodec(sm *StreamManager, mimetype string) (codec VideoCodec) { func (o TranscodeOptions) FileGetCodec(sm *StreamManager, maxTranscodeSize int) (codec VideoCodec) {
switch mimetype { needsResize := false
if maxTranscodeSize != 0 {
if o.VideoFile.Width > o.VideoFile.Height {
needsResize = o.VideoFile.Width > maxTranscodeSize
} else {
needsResize = o.VideoFile.Height > maxTranscodeSize
}
}
switch o.StreamType.MimeType {
case MimeMp4Video: case MimeMp4Video:
if !needsResize && o.VideoFile.VideoCodec == H264 {
return VideoCodecCopy
}
codec = VideoCodecLibX264 codec = VideoCodecLibX264
if hwcodec := sm.encoder.hwCodecMP4Compatible(); hwcodec != nil && sm.config.GetTranscodeHardwareAcceleration() { if hwcodec := sm.encoder.hwCodecMP4Compatible(); hwcodec != nil && sm.config.GetTranscodeHardwareAcceleration() {
codec = *hwcodec codec = *hwcodec
} }
case MimeWebmVideo: case MimeWebmVideo:
if !needsResize && (o.VideoFile.VideoCodec == Vp8 || o.VideoFile.VideoCodec == Vp9) {
return VideoCodecCopy
}
codec = VideoCodecVP9 codec = VideoCodecVP9
if hwcodec := sm.encoder.hwCodecWEBMCompatible(); hwcodec != nil && sm.config.GetTranscodeHardwareAcceleration() { if hwcodec := sm.encoder.hwCodecWEBMCompatible(); hwcodec != nil && sm.config.GetTranscodeHardwareAcceleration() {
codec = *hwcodec codec = *hwcodec
@@ -168,7 +184,7 @@ func (o TranscodeOptions) makeStreamArgs(sm *StreamManager) Args {
args := Args{"-hide_banner"} args := Args{"-hide_banner"}
args = args.LogLevel(LogLevelError) args = args.LogLevel(LogLevelError)
codec := FileGetCodec(sm, o.StreamType.MimeType) codec := o.FileGetCodec(sm, maxTranscodeSize)
args = sm.encoder.hwDeviceInit(args, codec) args = sm.encoder.hwDeviceInit(args, codec)
args = append(args, extraInputArgs...) args = append(args, extraInputArgs...)