Skip to content

Commit

Permalink
fix(export): define height and width
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikvedvik committed Nov 17, 2023
1 parent 7406201 commit 0810386
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion services/ffmpeg/progress.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package ffmpeg

import (
"github.com/samber/lo"
"strconv"
"strings"
"time"

"github.com/samber/lo"
)

type ProgressCallback func(Progress)
Expand All @@ -26,6 +27,8 @@ type StreamInfo struct {
TotalFrames int
TotalSeconds float64
FrameRate int
Height int
Width int
}

func ProbeResultToInfo(info *FFProbeResult) StreamInfo {
Expand All @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion services/transcode/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0810386

Please sign in to comment.