From 9cc26f7b759580c0b3c3b036bed4c1ec0ffb8500 Mon Sep 17 00:00:00 2001 From: HookedBehemoth Date: Wed, 8 May 2024 05:24:13 +0200 Subject: [PATCH] skip reencoding compatible video streams (#4783) * skip reencoding compatible video streams * don't attempt copy on transcode with resize --- pkg/ffmpeg/stream_transcode.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/pkg/ffmpeg/stream_transcode.go b/pkg/ffmpeg/stream_transcode.go index 8c19af3a606..503def59517 100644 --- a/pkg/ffmpeg/stream_transcode.go +++ b/pkg/ffmpeg/stream_transcode.go @@ -138,14 +138,30 @@ type TranscodeOptions struct { StartTime float64 } -func FileGetCodec(sm *StreamManager, mimetype string) (codec VideoCodec) { - switch mimetype { +func (o TranscodeOptions) FileGetCodec(sm *StreamManager, maxTranscodeSize int) (codec VideoCodec) { + 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: + if !needsResize && o.VideoFile.VideoCodec == H264 { + return VideoCodecCopy + } codec = VideoCodecLibX264 if hwcodec := sm.encoder.hwCodecMP4Compatible(); hwcodec != nil && sm.config.GetTranscodeHardwareAcceleration() { codec = *hwcodec } case MimeWebmVideo: + if !needsResize && (o.VideoFile.VideoCodec == Vp8 || o.VideoFile.VideoCodec == Vp9) { + return VideoCodecCopy + } codec = VideoCodecVP9 if hwcodec := sm.encoder.hwCodecWEBMCompatible(); hwcodec != nil && sm.config.GetTranscodeHardwareAcceleration() { codec = *hwcodec @@ -168,7 +184,7 @@ func (o TranscodeOptions) makeStreamArgs(sm *StreamManager) Args { args := Args{"-hide_banner"} args = args.LogLevel(LogLevelError) - codec := FileGetCodec(sm, o.StreamType.MimeType) + codec := o.FileGetCodec(sm, maxTranscodeSize) args = sm.encoder.hwDeviceInit(args, codec) args = append(args, extraInputArgs...)