From 7b38bc7c11ea077d05a727d20601f2327946295a Mon Sep 17 00:00:00 2001 From: huanghai <10402852@qq.com> Date: Thu, 9 Jul 2020 09:32:43 +0800 Subject: [PATCH] 'commit' --- dsSupport/ConvertMovie/Convert.go | 15 +++++++-------- dsSupport/Utils/CommonUtil/CommonUtil.go | 3 ++- dsSupport/Utils/ConvertUtil/ConvertUtil.go | 16 ++++++++-------- .../B7318F5D-46B8-4AA1-8811-1A9D65528E19.txt | 2 -- 4 files changed, 17 insertions(+), 19 deletions(-) delete mode 100644 dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Index/B7318F5D-46B8-4AA1-8811-1A9D65528E19.txt diff --git a/dsSupport/ConvertMovie/Convert.go b/dsSupport/ConvertMovie/Convert.go index 83691507..3fe5ca31 100644 --- a/dsSupport/ConvertMovie/Convert.go +++ b/dsSupport/ConvertMovie/Convert.go @@ -2,7 +2,6 @@ package main import ( "dsSupport/Utils/ConvertUtil" - "fmt" ) func main() { @@ -17,11 +16,11 @@ func main() { for i := range childMovie { ConvertUtil.ConvertToH264Mp4(childMovie[i]) } - //3、生成拼接的索引文件 - indexName := ConvertUtil.GenerateIndexTxt(source, childMovie) - fmt.Println(indexName) - //4、合成MP4 - ConvertUtil.Merge(source) - //5、清除垃圾 - ConvertUtil.ClearRubbish(source) + ////3、生成拼接的索引文件 + //indexName := ConvertUtil.GenerateIndexTxt(source, childMovie) + //fmt.Println(indexName) + ////4、合成MP4 + //ConvertUtil.Merge(source) + ////5、清除垃圾 + //ConvertUtil.ClearRubbish(source) } diff --git a/dsSupport/Utils/CommonUtil/CommonUtil.go b/dsSupport/Utils/CommonUtil/CommonUtil.go index d0455138..ab452135 100644 --- a/dsSupport/Utils/CommonUtil/CommonUtil.go +++ b/dsSupport/Utils/CommonUtil/CommonUtil.go @@ -13,10 +13,11 @@ import ( 作者:黄海 时间:2020-05-18 */ -func Exec(name string, args ...string) error { +func Exec(name string, dir string, args ...string) error { cmd := exec.Command(name, args...) stderr, _ := cmd.StderrPipe() stdout, _ := cmd.StdoutPipe() + cmd.Dir = dir if err := cmd.Start(); err != nil { log.Println("exec the cmd ", name, " failed") return err diff --git a/dsSupport/Utils/ConvertUtil/ConvertUtil.go b/dsSupport/Utils/ConvertUtil/ConvertUtil.go index 1068a355..22fe954d 100644 --- a/dsSupport/Utils/ConvertUtil/ConvertUtil.go +++ b/dsSupport/Utils/ConvertUtil/ConvertUtil.go @@ -1,8 +1,8 @@ package ConvertUtil import ( - "dsSupport/Utils/FileUtil" "dsSupport/Utils/CommonUtil" + "dsSupport/Utils/FileUtil" "fmt" "os" "path" @@ -62,7 +62,7 @@ func Cut(source string) { //3、输出的文件通配名称 targetPath := getPath(source, CutPath) + source[0:36] + `_%03d` + extension //4、切片 - CommonUtil.Exec(ffmpeg, `-fflags`, `+genpts`, `-i`, sourcePath, + CommonUtil.Exec(ffmpeg, runDir+"/Source/"+source[0:2]+"/", `-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) - CommonUtil.Exec(ffmpeg, `-i`, childMovie, `-c:v`, `libx264`, `-strict`, `-2`, + CommonUtil.Exec(ffmpeg, getPath(childMovieMp4, CutPath), `-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 := getPath(source,IndexPath) + source[0:36] + ".txt" + indexName := getPath(source, IndexPath) + source[0:36] + ".txt" FileUtil.WriteLines(content, indexName) return indexName } @@ -121,7 +121,7 @@ func GenerateIndexTxt(source string, childMovie []string) string { 时间:2020-07-08 */ func Merge(source string) { - indexName:=getPath(source,IndexPath)+source[0:36]+".txt" + indexName := getPath(source, IndexPath) + source[0:36] + ".txt" Target := runDir + `/Target/` + source[0:2] + "/" if !FileUtil.Exists(Target) { os.Mkdir(Target, os.ModePerm) @@ -130,12 +130,12 @@ func Merge(source string) { if !FileUtil.Exists(Target) { os.Mkdir(Target, os.ModePerm) } - if FileUtil.Exists(Target+"/"+source[0:36]+".mp4"){ + if FileUtil.Exists(Target + "/" + source[0:36] + ".mp4") { //删除 - os.Remove(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") + CommonUtil.Exec(ffmpeg,getPath(source,Mp4Path) ,`-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 deleted file mode 100644 index 386cbe2b..00000000 --- a/dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Index/B7318F5D-46B8-4AA1-8811-1A9D65528E19.txt +++ /dev/null @@ -1,2 +0,0 @@ -file 'B7318F5D-46B8-4AA1-8811-1A9D65528E19_000.mp4' -file 'B7318F5D-46B8-4AA1-8811-1A9D65528E19_001.mp4'