diff --git a/dsSupport/ConvertMovie/Convert.go b/dsSupport/ConvertMovie/Convert.go index d86235f0..0594e73d 100644 --- a/dsSupport/ConvertMovie/Convert.go +++ b/dsSupport/ConvertMovie/Convert.go @@ -1,9 +1,9 @@ package main import ( + "dsSupport/Utils/ShellUtils" "fmt" "os" - "os/exec" "path/filepath" "strings" ) @@ -18,18 +18,16 @@ func main(){ //3、对视频文件进行切片 cmdLine:=dir+`\ffmpeg\ffmpeg.exe -fflags +genpts -i `+movie+` -acodec copy -vcodec copy -f segment -segment_time 300 -reset_timestamps 1 -map 0:0 -map 0:1 `+target - cmd := exec.Command("cmd.exe", "/c", "start " + cmdLine) - err := cmd.Run() - fmt.Printf("%s, error:%v \n", cmdLine, err) + ShellUtils.ExecCommand(cmdLine) + fmt.Printf("切片成功完成!\n") //4、切片完成后,尝试进行转码 //获取当前目录下的文件或目录名(包含路径) filepathNames,_ := filepath.Glob(filepath.Join(dir+`/Target`,"*")) for i := range filepathNames { cmdLine=dir+`\ffmpeg\ffmpeg.exe -i `+filepathNames[i]+` -c:v libx264 -strict -2 `+strings.Replace(filepathNames[i],".wmv",".mp4",-1) - cmd = exec.Command("cmd.exe", "/c", "start " + cmdLine) - err = cmd.Run() - fmt.Printf("%s, error:%v \n", cmdLine, err) + ShellUtils.ExecCommand(cmdLine) + fmt.Printf("转码成功完成:"+filepathNames[i]+"\n") } } diff --git a/dsSupport/Utils/ShellUtils/ShellUtils.go b/dsSupport/Utils/ShellUtils/ShellUtils.go new file mode 100644 index 00000000..0ed782f9 --- /dev/null +++ b/dsSupport/Utils/ShellUtils/ShellUtils.go @@ -0,0 +1,15 @@ +package ShellUtils + +import ( + "fmt" + "os/exec" +) + +//封装一个函数来执行命令 +func ExecCommand(cmdLine string) { + cmd := exec.Command("cmd.exe", "/c", cmdLine) + err := cmd.Run() + cmd.Wait() + fmt.Printf("%s, error:%v \n", cmdLine, err) +} + diff --git a/dsSupport/go.mod b/dsSupport/go.mod new file mode 100644 index 00000000..945334c1 --- /dev/null +++ b/dsSupport/go.mod @@ -0,0 +1,3 @@ +module dsSupport + +go 1.14