diff --git a/dsSupport/ConvertMovie/Convert.go b/dsSupport/ConvertMovie/Convert.go index cf2852d9..83691507 100644 --- a/dsSupport/ConvertMovie/Convert.go +++ b/dsSupport/ConvertMovie/Convert.go @@ -2,6 +2,7 @@ package main import ( "dsSupport/Utils/ConvertUtil" + "fmt" ) func main() { @@ -16,10 +17,11 @@ func main() { for i := range childMovie { ConvertUtil.ConvertToH264Mp4(childMovie[i]) } - ////3、生成拼接的索引文件 - //indexName := ConvertUtil.GenerateIndexTxt(source, childMovie) - ////4、合成MP4 - //ConvertUtil.Merge(source, indexName) + //3、生成拼接的索引文件 + indexName := ConvertUtil.GenerateIndexTxt(source, childMovie) + fmt.Println(indexName) + //4、合成MP4 + ConvertUtil.Merge(source) //5、清除垃圾 - //ConvertUtil.ClearRubbish(source) + ConvertUtil.ClearRubbish(source) } diff --git a/dsSupport/Utils/ShellUtil/ShellUtil.go b/dsSupport/Utils/CommonUtil/CommonUtil.go similarity index 64% rename from dsSupport/Utils/ShellUtil/ShellUtil.go rename to dsSupport/Utils/CommonUtil/CommonUtil.go index 4c2f2847..d0455138 100644 --- a/dsSupport/Utils/ShellUtil/ShellUtil.go +++ b/dsSupport/Utils/CommonUtil/CommonUtil.go @@ -1,4 +1,4 @@ -package ShellUtil +package CommonUtil import ( "bufio" @@ -8,26 +8,6 @@ import ( "os/exec" ) -// -////封装一个函数来执行命令 -//func ExecCommand(cmdLine string) { -// cmd := exec.Command("cmd.exe", "/c", cmdLine) -// err := cmd.Run() -// -// var out bytes.Buffer -// var stderr bytes.Buffer -// cmd.Stdout = &out -// cmd.Stderr = &stderr -// if err := cmd.Run(); err != nil { -// fmt.Println(fmt.Sprint(err) + ": " + stderr.String()) -// } -// fmt.Println("Result: " + out.String()) -// -// cmd.Wait() -// fmt.Printf("%s, error:%v \n", cmdLine, err) -//} - - /** 功能:带回显的执行DOS命令 作者:黄海 diff --git a/dsSupport/Utils/ConvertUtil/ConvertUtil.go b/dsSupport/Utils/ConvertUtil/ConvertUtil.go index 1b2d3cfe..1068a355 100644 --- a/dsSupport/Utils/ConvertUtil/ConvertUtil.go +++ b/dsSupport/Utils/ConvertUtil/ConvertUtil.go @@ -2,7 +2,7 @@ package ConvertUtil import ( "dsSupport/Utils/FileUtil" - "dsSupport/Utils/ShellUtil" + "dsSupport/Utils/CommonUtil" "fmt" "os" "path" @@ -62,7 +62,7 @@ func Cut(source string) { //3、输出的文件通配名称 targetPath := getPath(source, CutPath) + source[0:36] + `_%03d` + extension //4、切片 - ShellUtil.Exec(ffmpeg, `-fflags`, `+genpts`, `-i`, sourcePath, + CommonUtil.Exec(ffmpeg, `-fflags`, `+genpts`, `-i`, sourcePath, `-acodec`, `copy`, `-vcodec`, `copy`, `-f`, `segment`, `-segment_time`, `300`, `-reset_timestamps`, `1`, `-map`, `0:0`, `-map`, `0:1`, targetPath) } @@ -92,7 +92,7 @@ func GetAllCutChild(source string) []string { func ConvertToH264Mp4(childMovie string) { extension := path.Ext(childMovie) childMovieMp4 := strings.Replace(filepath.Base(childMovie), extension, ".mp4", -1) - ShellUtil.Exec(ffmpeg, `-i`, childMovie, `-c:v`, `libx264`, `-strict`, `-2`, + CommonUtil.Exec(ffmpeg, `-i`, childMovie, `-c:v`, `libx264`, `-strict`, `-2`, getPath(childMovieMp4, Mp4Path)+childMovieMp4) } @@ -110,7 +110,7 @@ func GenerateIndexTxt(source string, childMovie []string) string { content = append(content, `file '`+filenameWithSuffix+`'`) } //文件位置 - indexName := runDir + `/Working/` + source[0:2] + "/" + source[0:36] + "/" + source[0:36] + ".txt" + indexName := getPath(source,IndexPath) + source[0:36] + ".txt" FileUtil.WriteLines(content, indexName) return indexName } @@ -120,7 +120,8 @@ func GenerateIndexTxt(source string, childMovie []string) string { 作者:黄海 时间:2020-07-08 */ -func Merge(source string, indexName string) { +func Merge(source string) { + indexName:=getPath(source,IndexPath)+source[0:36]+".txt" Target := runDir + `/Target/` + source[0:2] + "/" if !FileUtil.Exists(Target) { os.Mkdir(Target, os.ModePerm) @@ -129,7 +130,12 @@ func Merge(source string, indexName string) { if !FileUtil.Exists(Target) { os.Mkdir(Target, os.ModePerm) } - ShellUtil.Exec(ffmpeg, `-f`, `concat`, `-i`, indexName, `-c`, `copy`, Target+"/"+source[0:36]+".mp4") + if FileUtil.Exists(Target+"/"+source[0:36]+".mp4"){ + //删除 + os.Remove(Target+"/"+source[0:36]+".mp4") + } + //合并 + CommonUtil.Exec(ffmpeg, `-f`, `concat`, `-i`, indexName, `-c`, `copy`, Target+"/"+source[0:36]+".mp4") } /** diff --git a/dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Index/B7318F5D-46B8-4AA1-8811-1A9D65528E19.txt b/dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Index/B7318F5D-46B8-4AA1-8811-1A9D65528E19.txt new file mode 100644 index 00000000..386cbe2b --- /dev/null +++ b/dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Index/B7318F5D-46B8-4AA1-8811-1A9D65528E19.txt @@ -0,0 +1,2 @@ +file 'B7318F5D-46B8-4AA1-8811-1A9D65528E19_000.mp4' +file 'B7318F5D-46B8-4AA1-8811-1A9D65528E19_001.mp4' diff --git a/dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Mp4/B7318F5D-46B8-4AA1-8811-1A9D65528E19_000.mp4 b/dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Mp4/B7318F5D-46B8-4AA1-8811-1A9D65528E19_000.mp4 index 2f1ed376..e90d1f06 100644 Binary files a/dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Mp4/B7318F5D-46B8-4AA1-8811-1A9D65528E19_000.mp4 and b/dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Mp4/B7318F5D-46B8-4AA1-8811-1A9D65528E19_000.mp4 differ diff --git a/dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Mp4/B7318F5D-46B8-4AA1-8811-1A9D65528E19_001.mp4 b/dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Mp4/B7318F5D-46B8-4AA1-8811-1A9D65528E19_001.mp4 new file mode 100644 index 00000000..6ca91b8b Binary files /dev/null and b/dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Mp4/B7318F5D-46B8-4AA1-8811-1A9D65528E19_001.mp4 differ