1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| package main
import ( "fmt" "os" "os/exec" "path/filepath" "strings" )
func main() {
rootDir := "./" err := filepath.Walk(rootDir, func(path string, info os.FileInfo, err error) error { if err != nil { fmt.Printf("Error accessing path %s: %v\n", path, err) return nil }
if !info.IsDir() && strings.HasSuffix(info.Name(), ".mp4") { inputFilePath := path outputFilePath := strings.TrimSuffix(path, ".mp4") + "_cut.mp4" err := cutVideo(inputFilePath, outputFilePath) if err != nil { fmt.Printf("Error cutting video %s: %v\n", inputFilePath, err) } else { fmt.Printf("Video %s cut successfully\n", inputFilePath) } } return nil })
if err != nil { fmt.Printf("Error walking directory: %v\n", err) } fmt.Println("exit...") }
func cutVideo(inputFilePath, outputFilePath string) error { cmd := exec.Command("ffmpeg", "-hwaccel", "cuda", "-i", inputFilePath, "-ss", "00:00:00", "-t", "00:00:10", "-c:v", "h264_nvenc", "-c:a", "aac", outputFilePath) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr return cmd.Run() }
|