Can now encode both mp4 and vp9 with most of the options I need.

master
Zed A. Shaw 1 month ago
parent 1b07c4be54
commit 2c90827345
  1. 1
      .gitignore
  2. 22
      config.json
  3. 4
      config/settings.go
  4. 35
      main.go

1
.gitignore vendored

@ -29,3 +29,4 @@ coverage/*
public
*.mp4
ffmpeg*
renders

@ -1,7 +1,6 @@
[
{
"Format": "mp4",
"Scale": "1280:720",
"VideoBitrate": 900,
"AudioBitrate": 192,
"Speed": "veryfast",
@ -9,22 +8,29 @@
"CRF": 20,
"FPS": 30,
"Tune": "animation",
"Input": "test*.mp4",
"Input": "*.mp4",
"OutDir": "renders",
"Passes": 3
"Passes": 3,
"Extras": [
"-movflags", "faststart",
"-tune", "animation"
]
},
{
"Format": "mp4",
"Scale": "1920:1080",
"VideoBitrate": 1200,
"Format": "webm",
"VideoBitrate": 600,
"VideoCodec": "libvpx-vp9",
"AudioBitrate": 192,
"AudioCodec": "libopus",
"Speed": "veryfast",
"CleanFilename": false,
"CRF": 20,
"FPS": 30,
"Tune": "animation",
"Input": "test*.mp4",
"Input": "*.mp4",
"OutDir": "renders",
"Passes": 2
"Passes": 2,
"Extras": [
]
}
]

@ -8,9 +8,12 @@ import (
)
type VideoOpts struct {
Format string
Scale string
VideoBitrate int
VideoCodec string
AudioBitrate int
AudioCodec string
Speed string
CleanFilename bool
CRF int
@ -21,6 +24,7 @@ type VideoOpts struct {
Test int
TestStart int
Passes int
Extras []string
}
type Settings struct {

@ -12,7 +12,7 @@ import (
"github.com/modfy/fluent-ffmpeg"
)
func ModFile(fname string, scale string) string {
func ModFile(fname string, encoding config.VideoOpts) string {
cleaned := filepath.Clean(fname)
dir, file := filepath.Split(cleaned)
ext := filepath.Ext(file)
@ -20,8 +20,8 @@ func ModFile(fname string, scale string) string {
base, found := strings.CutSuffix(file, ext)
if !found { panic("no extension found?!") }
dim := strings.Replace(scale, ":", ".", 1)
renamed := fmt.Sprint(base, ".", dim, ext)
dim := strings.Replace(encoding.Scale, ":", ".", 1)
renamed := fmt.Sprint(base, ".", dim, ".", encoding.Format)
return filepath.Join(dir, renamed)
}
@ -29,40 +29,43 @@ func ModFile(fname string, scale string) string {
func Run(encoding config.VideoOpts, pass int, pid int, input string, output string) {
encode := fluentffmpeg.NewCommand("")
mp4_encoding := []string{
"-vf", fmt.Sprintf("scale=%s:flags=lanczos", encoding.Scale),
"-aspect", encoding.Scale,
extras := []string{
"-pix_fmt", "yuv420p",
"-tune", encoding.Tune,
"-movflags", "faststart",
"-pass", fmt.Sprint(pass),
"-passlogfile", fmt.Sprintf("ffmpeg2pass-%x.log", pid),
"-preset", encoding.Speed,
}
if encoding.Scale != "" {
"-vf", fmt.Sprintf("scale=%s:flags=lanczos", encoding.Scale),
"-aspect", encoding.Scale,
}
extras = append(extras, encoding.Extras...)
if pass != encoding.Passes {
mp4_encoding = append(mp4_encoding, "-an")
extras = append(extras, "-an")
} else {
encode.AudioCodec("aac")
mp4_encoding = append(mp4_encoding,
encode.AudioCodec(encoding.AudioCodec)
extras = append(extras,
"-b:a", fmt.Sprint(encoding.AudioBitrate * 1024))
}
if encoding.Test > 0 {
encode.InputOptions(
"-ss", fmt.Sprintf("00:%d", encoding.TestStart))
mp4_encoding = append(mp4_encoding, "-t", fmt.Sprint(encoding.Test))
extras = append(extras, "-t", fmt.Sprint(encoding.Test))
}
encode.VideoCodec("libx264").
encode.VideoCodec(encoding.VideoCodec).
VideoBitRate(encoding.VideoBitrate * 1024).
FrameRate(encoding.FPS).
ConstantRateFactor(encoding.CRF)
encode.OutputOptions(mp4_encoding...)
encode.OutputOptions(extras...)
cmd := encode.InputPath(input).
OutputFormat("mp4").
OutputFormat(encoding.Format).
OutputPath(output).
Build()
@ -95,7 +98,7 @@ func RenderToDir(encoding config.VideoOpts) {
for _, path := range matches {
base := filepath.Base(path)
target := filepath.Join(encoding.OutDir, base)
target = ModFile(target, encoding.Scale)
target = ModFile(target, encoding)
_, err := os.Stat(target)

Loading…
Cancel
Save