diff --git a/services/ffmpeg/progress.go b/services/ffmpeg/progress.go index cccdc973..5cf1018c 100644 --- a/services/ffmpeg/progress.go +++ b/services/ffmpeg/progress.go @@ -1,10 +1,11 @@ package ffmpeg import ( - "github.com/samber/lo" "strconv" "strings" "time" + + "github.com/samber/lo" ) type ProgressCallback func(Progress) @@ -26,6 +27,8 @@ type StreamInfo struct { TotalFrames int TotalSeconds float64 FrameRate int + Height int + Width int } func ProbeResultToInfo(info *FFProbeResult) StreamInfo { @@ -44,6 +47,10 @@ func ProbeResultToInfo(info *FFProbeResult) StreamInfo { if !found { stream = info.Streams[0] } + if streamInfo.HasVideo { + streamInfo.Height = stream.Height + streamInfo.Width = stream.Width + } if info != nil { frames, _ := strconv.ParseInt(stream.NbFrames, 10, 64) streamInfo.TotalFrames = int(frames) diff --git a/services/transcode/video.go b/services/transcode/video.go index 8bbf42b1..8122b6ba 100644 --- a/services/transcode/video.go +++ b/services/transcode/video.go @@ -65,7 +65,15 @@ func VideoH264(input common.VideoInput, cb ffmpeg.ProgressCallback) (*common.Vid filterComplex += "[0:0]copy[main];" } - filterComplex += fmt.Sprintf("[main]scale=-1:%d:force_original_aspect_ratio=decrease[out]", input.Height) + height := input.Height + width := -1 + if info.Height != 0 && info.Width != 0 && info.Height > info.Width { + // portrait video + height = -1 + width = input.Height + } + + filterComplex += fmt.Sprintf("[main]scale=%[1]d:%[2]d:force_original_aspect_ratio=decrease[out]", width, height) params = append(params, "-filter_complex", filterComplex,