|
|
|
|
@ -15,7 +15,6 @@ import ( |
|
|
|
|
"os/exec" |
|
|
|
|
"slices" |
|
|
|
|
"iter" |
|
|
|
|
"path" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func AudioOnly(codec config.CodecOpts) bool { |
|
|
|
|
@ -42,6 +41,7 @@ func ExtractBase(source_path string, outdir string) (string, string) { |
|
|
|
|
|
|
|
|
|
func SetCodecTarget(codec *config.CodecOpts, source_path string, encoding config.EncodeOpts) { |
|
|
|
|
dir, base := ExtractBase(source_path, encoding.OutDir) |
|
|
|
|
|
|
|
|
|
dot_or_dash := "."; if encoding.Dash { dot_or_dash = "/" } |
|
|
|
|
|
|
|
|
|
if AudioOnly(*codec) { |
|
|
|
|
@ -52,6 +52,8 @@ func SetCodecTarget(codec *config.CodecOpts, source_path string, encoding config |
|
|
|
|
renamed := fmt.Sprint(base, dot_or_dash, dim, ".", encoding.Format) |
|
|
|
|
codec.Target = filepath.Join(dir, renamed) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
codec.Target = filepath.ToSlash(codec.Target) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func Run(encoding config.EncodeOpts, codec config.CodecOpts, pass int, pid int, input string, output string) { |
|
|
|
|
@ -114,7 +116,7 @@ func Run(encoding config.EncodeOpts, codec config.CodecOpts, pass int, pid int, |
|
|
|
|
Overwrite(true). |
|
|
|
|
Build() |
|
|
|
|
|
|
|
|
|
fmt.Println(">", cmd.String()) |
|
|
|
|
fmt.Println("====== FFMPEG ======\n", cmd.String(), "\n============") |
|
|
|
|
|
|
|
|
|
err := cmd.Run() |
|
|
|
|
if err != nil { log.Fatalf("%v", err) } |
|
|
|
|
@ -128,6 +130,11 @@ func DevNull() string { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func FileExists(path string) bool { |
|
|
|
|
_, err := os.Stat(path) |
|
|
|
|
return err == nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func RenderFile(encoding config.EncodeOpts, pid int, source_path string, force bool) { |
|
|
|
|
for i := 0; i < len(encoding.Variants); i++ { |
|
|
|
|
codec := &encoding.Variants[i] |
|
|
|
|
@ -135,15 +142,16 @@ func RenderFile(encoding config.EncodeOpts, pid int, source_path string, force b |
|
|
|
|
SetCodecTarget(codec, source_path, encoding) |
|
|
|
|
|
|
|
|
|
// ensure the target directories exist
|
|
|
|
|
target_dir := path.Dir(codec.Target) |
|
|
|
|
err := os.MkdirAll(target_dir, 0750) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Fatal("failed to make target path: %s: %v", target_dir, err) |
|
|
|
|
} |
|
|
|
|
target_dir := filepath.Dir(codec.Target) |
|
|
|
|
|
|
|
|
|
_, err = os.Stat(codec.Target) |
|
|
|
|
if !FileExists(codec.Target) { |
|
|
|
|
err := os.MkdirAll(target_dir, 0750) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Fatal("failed to make target path: %s: %v", target_dir, err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if err == nil && !force { |
|
|
|
|
if FileExists(codec.Target) && !force { |
|
|
|
|
fmt.Println("^^^ SKIP", source_path, "->", codec.Target) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
@ -205,11 +213,11 @@ func SaveMPD(source_path string, encoding config.EncodeOpts) { |
|
|
|
|
args = append(args, adapt_set) |
|
|
|
|
|
|
|
|
|
dir, base := ExtractBase(source_path, encoding.OutDir) |
|
|
|
|
args = append(args, filepath.Join(dir, base, "manifest.mpd")) |
|
|
|
|
|
|
|
|
|
fmt.Println("\n\n\n\nARGS", args) |
|
|
|
|
mpd_path := filepath.ToSlash(filepath.Join(dir, base, "manifest.mpd")) |
|
|
|
|
args = append(args, mpd_path) |
|
|
|
|
|
|
|
|
|
ffmpeg := exec.Command("ffmpeg", args...) |
|
|
|
|
fmt.Println("==== MPD COMMAND ====\n", ffmpeg.String(), "\n==============") |
|
|
|
|
out, err := ffmpeg.CombinedOutput() |
|
|
|
|
|
|
|
|
|
os.Stdout.Write(out) |
|
|
|
|
@ -240,7 +248,6 @@ func main() { |
|
|
|
|
log.Fatal(http.ListenAndServe(settings.Port, nil)) |
|
|
|
|
} else { |
|
|
|
|
for i := 0; i < len(settings.Encodings); i++ { |
|
|
|
|
fmt.Println("LOOP", i) |
|
|
|
|
encoding := &settings.Encodings[i]; |
|
|
|
|
|
|
|
|
|
if encoding.OutDir != "" { |
|
|
|
|
|