first working version
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func ConvertVideo(path string) {
|
||||
out := path[:len(path)-len(filepath.Ext(path))] + ".mp4"
|
||||
|
||||
cmd := exec.Command("ffmpeg",
|
||||
"-i", "input.mp4",
|
||||
"-c:v", "libx264",
|
||||
"-crf", "23",
|
||||
"-preset", "medium",
|
||||
"-c:a", "aac",
|
||||
"-b:a", "128k",
|
||||
out,
|
||||
)
|
||||
|
||||
cmd.Stderr = cmd.Stdout
|
||||
|
||||
_, err := cmd.CombinedOutput()
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error converting %s: %v\n", path, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := os.Remove(path); err != nil {
|
||||
fmt.Printf("Converted %s -> %s, but failed to delete original: %v\n", path, out, err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("Converted %s -> %s (original deleted)\n", path, out)
|
||||
}
|
||||
Reference in New Issue
Block a user