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() fmt.Fprintf(w, "\tencode file\n\t from: '%s'\n\t to: '%s'\n", oldFile, newFile) 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 }