|
|
|
|
@ -15,6 +15,7 @@ import ( |
|
|
|
|
"os/exec" |
|
|
|
|
"slices" |
|
|
|
|
"iter" |
|
|
|
|
"path" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func AudioOnly(codec config.CodecOpts) bool { |
|
|
|
|
@ -25,13 +26,9 @@ func VideoOnly(codec config.CodecOpts) bool { |
|
|
|
|
return codec.AudioCodec == "none" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func SetDashTarget(codec *config.CodecOpts, path string, encoding config.EncodeOpts) { |
|
|
|
|
SetCodecTarget(codec, path, encoding) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func SetCodecTarget(codec *config.CodecOpts, path string, encoding config.EncodeOpts) { |
|
|
|
|
base := filepath.Base(path) |
|
|
|
|
target := filepath.Join(encoding.OutDir, base) |
|
|
|
|
func ExtractBase(source_path string, outdir string) (string, string) { |
|
|
|
|
base := filepath.Base(source_path) |
|
|
|
|
target := filepath.Join(outdir, base) |
|
|
|
|
|
|
|
|
|
cleaned := filepath.Clean(target) |
|
|
|
|
dir, file := filepath.Split(cleaned) |
|
|
|
|
@ -40,12 +37,19 @@ func SetCodecTarget(codec *config.CodecOpts, path string, encoding config.Encode |
|
|
|
|
base, found := strings.CutSuffix(file, ext) |
|
|
|
|
if !found { panic("no extension found?!") } |
|
|
|
|
|
|
|
|
|
return dir, base |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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) { |
|
|
|
|
renamed := fmt.Sprint(base, ".audio.", encoding.Format) |
|
|
|
|
renamed := fmt.Sprint(base, dot_or_dash, "audio.", encoding.Format) |
|
|
|
|
codec.Target = filepath.Join(dir, renamed) |
|
|
|
|
} else { |
|
|
|
|
dim := strings.Replace(codec.Scale, ":", ".", 1) |
|
|
|
|
renamed := fmt.Sprint(base, ".", dim, ".", encoding.Format) |
|
|
|
|
renamed := fmt.Sprint(base, dot_or_dash, dim, ".", encoding.Format) |
|
|
|
|
codec.Target = filepath.Join(dir, renamed) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -124,32 +128,35 @@ func DevNull() string { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func RenderFile(encoding config.EncodeOpts, pid int, path string, force bool) { |
|
|
|
|
func RenderFile(encoding config.EncodeOpts, pid int, source_path string, force bool) { |
|
|
|
|
for i := 0; i < len(encoding.Variants); i++ { |
|
|
|
|
codec := &encoding.Variants[i] |
|
|
|
|
|
|
|
|
|
if encoding.Dash { |
|
|
|
|
SetDashTarget(codec, path, encoding) |
|
|
|
|
} else { |
|
|
|
|
SetCodecTarget(codec, path, encoding) |
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_, err := os.Stat(codec.Target) |
|
|
|
|
_, err = os.Stat(codec.Target) |
|
|
|
|
|
|
|
|
|
if err == nil && !force { |
|
|
|
|
fmt.Println("^^^ SKIP", path, "->", codec.Target) |
|
|
|
|
fmt.Println("^^^ SKIP", source_path, "->", codec.Target) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fmt.Println("--- PATH", path, "->", codec.Target) |
|
|
|
|
fmt.Println("--- PATH", source_path, "->", codec.Target) |
|
|
|
|
for i := 1; i < encoding.Passes; i++ { |
|
|
|
|
Run(encoding, *codec, i, pid, path, DevNull()) |
|
|
|
|
Run(encoding, *codec, i, pid, source_path, DevNull()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Run(encoding, *codec, encoding.Passes, pid, path, codec.Target) |
|
|
|
|
Run(encoding, *codec, encoding.Passes, pid, source_path, codec.Target) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
SaveMPD(encoding) |
|
|
|
|
SaveMPD(source_path, encoding) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func StrSeq(up_to int) iter.Seq[string] { |
|
|
|
|
@ -160,7 +167,7 @@ func StrSeq(up_to int) iter.Seq[string] { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func SaveMPD(encoding config.EncodeOpts) { |
|
|
|
|
func SaveMPD(source_path string, encoding config.EncodeOpts) { |
|
|
|
|
args := make([]string, 0, 10) |
|
|
|
|
var the_audio string |
|
|
|
|
|
|
|
|
|
@ -196,7 +203,9 @@ func SaveMPD(encoding config.EncodeOpts) { |
|
|
|
|
video_set, len(encoding.Variants) - 1) |
|
|
|
|
|
|
|
|
|
args = append(args, adapt_set) |
|
|
|
|
args = append(args, filepath.Join(encoding.OutDir, "manifest.mpd")) |
|
|
|
|
|
|
|
|
|
dir, base := ExtractBase(source_path, encoding.OutDir) |
|
|
|
|
args = append(args, filepath.Join(dir, base, "manifest.mpd")) |
|
|
|
|
|
|
|
|
|
fmt.Println("\n\n\n\nARGS", args) |
|
|
|
|
|
|
|
|
|
@ -212,8 +221,8 @@ func RenderToDir(encoding config.EncodeOpts, force bool) { |
|
|
|
|
|
|
|
|
|
if err != nil { log.Fatalf("%v", err) } |
|
|
|
|
|
|
|
|
|
for _, path := range matches { |
|
|
|
|
RenderFile(encoding, rand.Int(), path, force) |
|
|
|
|
for _, source_path := range matches { |
|
|
|
|
RenderFile(encoding, rand.Int(), source_path, force) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|