Skip to content

Commit

Permalink
skip reencoding compatible video streams (stashapp#4783)
Browse files Browse the repository at this point in the history
* skip reencoding compatible video streams
* don't attempt copy on transcode with resize
  • Loading branch information
HookedBehemoth authored May 8, 2024
1 parent c5abe28 commit 9cc26f7
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions pkg/ffmpeg/stream_transcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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...)
Expand Down

0 comments on commit 9cc26f7

Please sign in to comment.