diff --git a/dsSupport/ConvertMovie/Convert.go b/dsSupport/ConvertMovie/Convert.go index 3fe5ca31..c39cee09 100644 --- a/dsSupport/ConvertMovie/Convert.go +++ b/dsSupport/ConvertMovie/Convert.go @@ -2,6 +2,7 @@ package main import ( "dsSupport/Utils/ConvertUtil" + "fmt" ) func main() { @@ -17,10 +18,10 @@ func main() { ConvertUtil.ConvertToH264Mp4(childMovie[i]) } ////3、生成拼接的索引文件 - //indexName := ConvertUtil.GenerateIndexTxt(source, childMovie) - //fmt.Println(indexName) - ////4、合成MP4 - //ConvertUtil.Merge(source) - ////5、清除垃圾 - //ConvertUtil.ClearRubbish(source) + indexName := ConvertUtil.GenerateIndexTxt(source, childMovie) + fmt.Println(indexName) + //4、合成MP4 + ConvertUtil.Merge(source) + //5、清除垃圾 + ConvertUtil.ClearRubbish(source) } diff --git a/dsSupport/Utils/ConvertUtil/ConvertUtil.go b/dsSupport/Utils/ConvertUtil/ConvertUtil.go index 22fe954d..6387359c 100644 --- a/dsSupport/Utils/ConvertUtil/ConvertUtil.go +++ b/dsSupport/Utils/ConvertUtil/ConvertUtil.go @@ -23,7 +23,6 @@ func init() { const CutPath = "Cut/" const Mp4Path = "Mp4/" -const IndexPath = "Index/" const AllPath = "/" /** @@ -46,7 +45,6 @@ func InitDir(source string) { //2、创建新目录 os.MkdirAll(getPath(source, CutPath), os.ModePerm) os.Mkdir(getPath(source, Mp4Path), os.ModePerm) - os.Mkdir(getPath(source, IndexPath), os.ModePerm) } /** @@ -110,7 +108,7 @@ func GenerateIndexTxt(source string, childMovie []string) string { content = append(content, `file '`+filenameWithSuffix+`'`) } //文件位置 - indexName := getPath(source, IndexPath) + source[0:36] + ".txt" + indexName := getPath(source, Mp4Path) + source[0:36] + ".txt" FileUtil.WriteLines(content, indexName) return indexName } @@ -121,7 +119,6 @@ func GenerateIndexTxt(source string, childMovie []string) string { 时间:2020-07-08 */ 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) @@ -135,7 +132,7 @@ func Merge(source string) { os.Remove(Target + "/" + source[0:36] + ".mp4") } //合并 - CommonUtil.Exec(ffmpeg,getPath(source,Mp4Path) ,`-f`, `concat`, `-i`, indexName, `-c`, `copy`, Target+"/"+source[0:36]+".mp4") + CommonUtil.Exec(ffmpeg,getPath(source,Mp4Path) ,`-f`, `concat`, `-i`, source[0:36] + ".txt", `-c`, `copy`, Target+"/"+source[0:36]+".mp4") } /** @@ -144,7 +141,7 @@ func Merge(source string) { 时间:2020-07-08 */ func ClearRubbish(source string) { - var deletePath = []string{"Working", "Target"} + var deletePath = []string{"Working"} for i := range deletePath { //删除目录 os.RemoveAll(runDir + `/` + deletePath[i] + `/` + source[0:2] + "/" + source[0:36]) diff --git a/dsSupport/Utils/FileUtil/FileUtil.go b/dsSupport/Utils/FileUtil/FileUtil.go index 49d9c658..1fd11310 100644 --- a/dsSupport/Utils/FileUtil/FileUtil.go +++ b/dsSupport/Utils/FileUtil/FileUtil.go @@ -3,6 +3,7 @@ package FileUtil import ( "bufio" "fmt" + "io" "os" ) @@ -56,3 +57,22 @@ func WriteLines(lines []string, path string) error { return w.Flush() } + + +func CopyFile (dstFilePath string,srcFilePath string)(written int64, err error){ + srcFile,err := os.Open(srcFilePath) + if err != nil{ + fmt.Printf("打开源文件错误,错误信息=%v\n",err) + } + defer srcFile.Close() + reader := bufio.NewReader(srcFile) + + dstFile,err := os.OpenFile(dstFilePath,os.O_WRONLY | os.O_CREATE,0777) + if err != nil{ + fmt.Printf("打开目标文件错误,错误信息=%v\n",err) + return + } + writer := bufio.NewWriter(dstFile) + defer dstFile.Close() + return io.Copy(writer,reader) +} \ No newline at end of file diff --git a/dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Cut/B7318F5D-46B8-4AA1-8811-1A9D65528E19_000.wmv b/dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Cut/B7318F5D-46B8-4AA1-8811-1A9D65528E19_000.wmv deleted file mode 100644 index 78a14553..00000000 Binary files a/dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Cut/B7318F5D-46B8-4AA1-8811-1A9D65528E19_000.wmv and /dev/null differ diff --git a/dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Cut/B7318F5D-46B8-4AA1-8811-1A9D65528E19_001.wmv b/dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Cut/B7318F5D-46B8-4AA1-8811-1A9D65528E19_001.wmv deleted file mode 100644 index 8be82fda..00000000 Binary files a/dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Cut/B7318F5D-46B8-4AA1-8811-1A9D65528E19_001.wmv and /dev/null differ 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 deleted file mode 100644 index e90d1f06..00000000 Binary files a/dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Mp4/B7318F5D-46B8-4AA1-8811-1A9D65528E19_000.mp4 and /dev/null 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 deleted file mode 100644 index 6ca91b8b..00000000 Binary files a/dsSupport/Working/B7/B7318F5D-46B8-4AA1-8811-1A9D65528E19/Mp4/B7318F5D-46B8-4AA1-8811-1A9D65528E19_001.mp4 and /dev/null differ