diff --git a/dsSupport/ConvertMovie/Convert.go b/dsSupport/ConvertMovie/Convert.go index 0594e73d..a206dc86 100644 --- a/dsSupport/ConvertMovie/Convert.go +++ b/dsSupport/ConvertMovie/Convert.go @@ -1,33 +1,24 @@ package main import ( - "dsSupport/Utils/ShellUtils" - "fmt" - "os" + "dsSupport/Utils/ConvertUtil" + "dsSupport/Utils/ShellUtil" "path/filepath" "strings" ) func main(){ - dir, _ := os.Getwd() + //源文件 + source:="B7318F5D-46B8-4AA1-8811-1A9D65528E19.wmv" - //1、视频文件名称 - movie:=dir+"/Source/1.wmv" - //2、输出的文件通配名称 - target:=dir+`/Target/piece_%03d.wmv` + //1、对视频文件进行切片 + ConvertUtil.Cut(source) - //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 - ShellUtils.ExecCommand(cmdLine) - fmt.Printf("切片成功完成!\n") - - //4、切片完成后,尝试进行转码 - //获取当前目录下的文件或目录名(包含路径) + //2、切片完成后,尝试进行转码 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) - ShellUtils.ExecCommand(cmdLine) - fmt.Printf("转码成功完成:"+filepathNames[i]+"\n") + ShellUtil.ExecCommand(cmdLine) } } diff --git a/dsSupport/Source/1.wmv b/dsSupport/Source/1.wmv deleted file mode 100644 index 7c18a2a3..00000000 Binary files a/dsSupport/Source/1.wmv and /dev/null differ diff --git a/dsSupport/Utils/ConvertUtil/ConvertUtil.go b/dsSupport/Utils/ConvertUtil/ConvertUtil.go new file mode 100644 index 00000000..49ce27fe --- /dev/null +++ b/dsSupport/Utils/ConvertUtil/ConvertUtil.go @@ -0,0 +1,31 @@ +package ConvertUtil + +import ( + "dsSupport/Utils/ShellUtil" + "os" + "path" +) + +//运行的目录 +var runDir string + +func init() { + runDir, _ = os.Getwd() +} + +/** +功能:对指定的视频文件进行切片 +作者:黄海 +时间:2020-07-08 + */ +func Cut(source string) { + //1、源视频文件 + sourcePath:=runDir+"/Source/"+source[0:2]+"/"+source + //2、获取文件后缀 + extension:= path.Ext(source) + //3、输出的文件通配名称 + targetPath:=runDir+`/Target/`+source[0:36]+`_%03d.`+extension + //4、切片 + cmdLine := runDir + `\ffmpeg\ffmpeg.exe -fflags +genpts -i ` + sourcePath + ` -acodec copy -vcodec copy -f segment -segment_time 300 -reset_timestamps 1 -map 0:0 -map 0:1 ` + targetPath + ShellUtil.ExecCommand(cmdLine) +} diff --git a/dsSupport/Utils/ShellUtils/ShellUtils.go b/dsSupport/Utils/ShellUtil/ShellUtil.go similarity index 92% rename from dsSupport/Utils/ShellUtils/ShellUtils.go rename to dsSupport/Utils/ShellUtil/ShellUtil.go index 0ed782f9..3e933216 100644 --- a/dsSupport/Utils/ShellUtils/ShellUtils.go +++ b/dsSupport/Utils/ShellUtil/ShellUtil.go @@ -1,4 +1,4 @@ -package ShellUtils +package ShellUtil import ( "fmt"