|
|
@ -2,12 +2,16 @@ package main |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
|
|
|
|
"log" |
|
|
|
"lcthw.dev/vidcrunch/config" |
|
|
|
"lcthw.dev/vidcrunch/config" |
|
|
|
"github.com/modfy/fluent-ffmpeg" |
|
|
|
"github.com/modfy/fluent-ffmpeg" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func Run(pass string) { |
|
|
|
const DevNull = "NUL" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func Run(pass int, output string) { |
|
|
|
pid := 1 |
|
|
|
pid := 1 |
|
|
|
|
|
|
|
|
|
|
|
encode := fluentffmpeg.NewCommand("") |
|
|
|
encode := fluentffmpeg.NewCommand("") |
|
|
|
|
|
|
|
|
|
|
|
mp4_opts := []string{ |
|
|
|
mp4_opts := []string{ |
|
|
@ -16,29 +20,48 @@ func Run(pass string) { |
|
|
|
"-pix_fmt", "yuv420p", |
|
|
|
"-pix_fmt", "yuv420p", |
|
|
|
"-tune", config.Settings.Tune, |
|
|
|
"-tune", config.Settings.Tune, |
|
|
|
"-movflags", "faststart", |
|
|
|
"-movflags", "faststart", |
|
|
|
"-pass", pass, |
|
|
|
"-pass", fmt.Sprint(pass), |
|
|
|
"-passlogfile", fmt.Sprintf("ffmpeg2pass-%d.log", pid), |
|
|
|
"-passlogfile", fmt.Sprintf("ffmpeg2pass-%d.log", pid), |
|
|
|
"-preset", config.Settings.Speed, |
|
|
|
"-preset", config.Settings.Speed, |
|
|
|
"-filter:v", fmt.Sprintf("fps=%d", config.Settings.FPS), |
|
|
|
|
|
|
|
"-crf", fmt.Sprint(config.Settings.CRF), |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
encode.Options(mp4_opts...) |
|
|
|
if pass != 3 { |
|
|
|
|
|
|
|
mp4_opts = append(mp4_opts, "-an") |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
encode.AudioCodec("aac") |
|
|
|
|
|
|
|
mp4_opts = append(mp4_opts, |
|
|
|
|
|
|
|
"-b:a", fmt.Sprint(config.Settings.AudioBitrate * 1024)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if config.Settings.Test > 0 { |
|
|
|
|
|
|
|
encode.InputOptions( |
|
|
|
|
|
|
|
"-ss", fmt.Sprintf("00:%d", config.Settings.TestStart)) |
|
|
|
|
|
|
|
mp4_opts = append(mp4_opts, "-t", fmt.Sprint(config.Settings.Test)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
encode.VideoCodec("libx264"). |
|
|
|
|
|
|
|
VideoBitRate(config.Settings.VideoBitrate * 1024). |
|
|
|
|
|
|
|
FrameRate(config.Settings.FPS). |
|
|
|
|
|
|
|
ConstantRateFactor(config.Settings.CRF) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
encode.OutputOptions(mp4_opts...) |
|
|
|
|
|
|
|
|
|
|
|
cmd := encode.InputPath(config.Settings.Input). |
|
|
|
cmd := encode.InputPath(config.Settings.Input). |
|
|
|
OutputFormat("mp4"). |
|
|
|
OutputFormat("mp4"). |
|
|
|
OutputPath(config.Settings.Output). |
|
|
|
OutputPath(output). |
|
|
|
Build() |
|
|
|
Build() |
|
|
|
|
|
|
|
|
|
|
|
fmt.Println("COMMAND", cmd.String()) |
|
|
|
fmt.Println("COMMAND", cmd.String()) |
|
|
|
|
|
|
|
|
|
|
|
err := cmd.Run() |
|
|
|
err := cmd.Run() |
|
|
|
if err != nil { panic("fail") } |
|
|
|
if err != nil { log.Fatalf("%v", err) } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
func main() { |
|
|
|
config.Load() |
|
|
|
config.Load() |
|
|
|
fmt.Println(config.Settings) |
|
|
|
fmt.Println(config.Settings) |
|
|
|
|
|
|
|
|
|
|
|
Run("1") |
|
|
|
Run(1, DevNull) |
|
|
|
|
|
|
|
Run(2, DevNull) |
|
|
|
|
|
|
|
Run(3, config.Settings.Output) |
|
|
|
} |
|
|
|
} |
|
|
|