master
huanghai 5 years ago
parent 7b38bc7c11
commit d12aed627d

@ -2,6 +2,7 @@ package main
import ( import (
"dsSupport/Utils/ConvertUtil" "dsSupport/Utils/ConvertUtil"
"fmt"
) )
func main() { func main() {
@ -17,10 +18,10 @@ func main() {
ConvertUtil.ConvertToH264Mp4(childMovie[i]) ConvertUtil.ConvertToH264Mp4(childMovie[i])
} }
////3、生成拼接的索引文件 ////3、生成拼接的索引文件
//indexName := ConvertUtil.GenerateIndexTxt(source, childMovie) indexName := ConvertUtil.GenerateIndexTxt(source, childMovie)
//fmt.Println(indexName) fmt.Println(indexName)
////4、合成MP4 //4、合成MP4
//ConvertUtil.Merge(source) ConvertUtil.Merge(source)
////5、清除垃圾 //5、清除垃圾
//ConvertUtil.ClearRubbish(source) ConvertUtil.ClearRubbish(source)
} }

@ -23,7 +23,6 @@ func init() {
const CutPath = "Cut/" const CutPath = "Cut/"
const Mp4Path = "Mp4/" const Mp4Path = "Mp4/"
const IndexPath = "Index/"
const AllPath = "/" const AllPath = "/"
/** /**
@ -46,7 +45,6 @@ func InitDir(source string) {
//2、创建新目录 //2、创建新目录
os.MkdirAll(getPath(source, CutPath), os.ModePerm) os.MkdirAll(getPath(source, CutPath), os.ModePerm)
os.Mkdir(getPath(source, Mp4Path), 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+`'`) 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) FileUtil.WriteLines(content, indexName)
return indexName return indexName
} }
@ -121,7 +119,6 @@ func GenerateIndexTxt(source string, childMovie []string) string {
2020-07-08 2020-07-08
*/ */
func Merge(source string) { func Merge(source string) {
indexName := getPath(source, IndexPath) + source[0:36] + ".txt"
Target := runDir + `/Target/` + source[0:2] + "/" Target := runDir + `/Target/` + source[0:2] + "/"
if !FileUtil.Exists(Target) { if !FileUtil.Exists(Target) {
os.Mkdir(Target, os.ModePerm) os.Mkdir(Target, os.ModePerm)
@ -135,7 +132,7 @@ func Merge(source string) {
os.Remove(Target + "/" + source[0:36] + ".mp4") 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 2020-07-08
*/ */
func ClearRubbish(source string) { func ClearRubbish(source string) {
var deletePath = []string{"Working", "Target"} var deletePath = []string{"Working"}
for i := range deletePath { for i := range deletePath {
//删除目录 //删除目录
os.RemoveAll(runDir + `/` + deletePath[i] + `/` + source[0:2] + "/" + source[0:36]) os.RemoveAll(runDir + `/` + deletePath[i] + `/` + source[0:2] + "/" + source[0:36])

@ -3,6 +3,7 @@ package FileUtil
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"io"
"os" "os"
) )
@ -56,3 +57,22 @@ func WriteLines(lines []string, path string) error {
return w.Flush() 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)
}
Loading…
Cancel
Save