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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 19 additions and 3 deletions

View File

@ -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...)