|
|
|
|
@ -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) |
|
|
|
|
|
|
|
|
|
|