organizer/encode_video.go

44 lines
869 B
Go
Raw Permalink Normal View History

2023-01-16 00:00:40 +01:00
package main
import (
"fmt"
"io"
"os"
"os/exec"
"strings"
"time"
)
func EncodeVideo(w io.Writer, encArgs, oldFile, newFile string) error {
if encArgs == "" {
fmt.Fprintf(w, "\trename file\n\t from: '%s'\n\t to: '%s'\n", oldFile, newFile)
return os.Rename(oldFile, newFile)
}
start := time.Now()
2023-01-16 00:23:27 +01:00
fmt.Fprintf(w, "\tencode file\n\t from: '%s'\n\t to: '%s'\n", oldFile, newFile)
2023-01-16 00:00:40 +01:00
fullArgs := []string{"-y", "-i", oldFile}
fullArgs = append(fullArgs, strings.Split(encArgs, " ")...)
fullArgs = append(fullArgs, newFile)
cmd := exec.Command("ffmpeg", fullArgs...)
if err := cmd.Start(); err != nil {
return err
}
if err := cmd.Wait(); err != nil {
return err
}
if err := os.Remove(oldFile); err != nil {
return err
}
fmt.Fprintf(w, "\t done (took %s)\n", time.Since(start).Truncate(100*time.Millisecond))
return nil
}