initial commit
This commit is contained in:
43
encode_video.go
Normal file
43
encode_video.go
Normal file
@ -0,0 +1,43 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user