master
huanghai 5 years ago
parent d81f71b112
commit 79683bedbd

@ -14,5 +14,9 @@ func main(){
for i := range childMovie {
ConvertUtil.ConvertToH264Mp4(childMovie[i])
}
//3、生成拼接的索引文件
indexName:=ConvertUtil.GenerateIndexTxt(source,childMovie)
//4、合成MP4
ConvertUtil.Merge(source,indexName)
}

@ -13,8 +13,13 @@ import (
//运行的目录
var runDir string
// ffmpeg 的命令行位置
var ffmpeg string
func init() {
runDir, _ = os.Getwd()
ffmpeg=runDir + `\ffmpeg\ffmpeg.exe`
}
/**
@ -50,7 +55,7 @@ func Cut(source string) {
i++
}
//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
cmdLine := ffmpeg + ` -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)
}
@ -79,6 +84,48 @@ func ConvertToH264Mp4(childMovie string) {
if FileUtil.Exists(childMovieMp4) {
os.Remove(childMovieMp4)
}
cmdLine := runDir + `\ffmpeg\ffmpeg.exe -i ` + childMovie + ` -c:v libx264 -strict -2 ` + childMovieMp4
cmdLine := ffmpeg + ` -i ` + childMovie + ` -c:v libx264 -strict -2 ` + childMovieMp4
ShellUtil.ExecCommand(cmdLine)
}
/**
2020-07-08
*/
func GenerateIndexTxt(source string,childMovie []string)string{
content:=make([]string,0)
for i := range childMovie {
extension := path.Ext(childMovie[i])
content= append(content, `file '`+strings.Replace(childMovie[i],extension,".mp4",-1)+`'`)
}
//文件位置
indexName:=runDir+`/Working/`+source[0:2]+"/"+source[0:36]+"/"+source[0:36]+".txt"
FileUtil.WriteLines(content,indexName)
return indexName
}
/**
2020-07-08
*/
func Merge(source string,indexName string){
Target := runDir + `/Target/` + source[0:2] + "/"
if !FileUtil.Exists(Target) {
os.Mkdir(Target, os.ModePerm)
}
Target = Target + source[0:36] + "/"
if !FileUtil.Exists(Target) {
os.Mkdir(Target, os.ModePerm)
}
cmdLine:=ffmpeg+` -f concat -i `+indexName+` -c copy `+Target+"/"+source[0:36]+".mp4"
ShellUtil.ExecCommand(cmdLine)
}
/**
2020-07-08
*/
func ClearRubbish(source string){
}

@ -1,6 +1,10 @@
package FileUtil
import "os"
import (
"bufio"
"fmt"
"os"
)
// 判断所给路径文件/文件夹是否存在
func Exists(path string) bool {
@ -13,3 +17,41 @@ func Exists(path string) bool {
}
return true
}
/**
2020-07-08
*/
func ReadLines(path string) ([]string, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
var lines []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
return lines, scanner.Err()
}
/**
2020-07-08
*/
func WriteLines(lines []string, path string) error {
file, err := os.Create(path)
if err != nil {
return err
}
defer file.Close()
w := bufio.NewWriter(file)
for _, line := range lines {
fmt.Fprintln(w, line)
}
return w.Flush()
}

@ -0,0 +1,4 @@
file 'E:\Work\dsMin\dsSupport\Working\B7\B7318F5D-46B8-4AA1-8811-1A9D65528E19\B7318F5D-46B8-4AA1-8811-1A9D65528E19_000.mp4'
file 'E:\Work\dsMin\dsSupport\Working\B7\B7318F5D-46B8-4AA1-8811-1A9D65528E19\B7318F5D-46B8-4AA1-8811-1A9D65528E19_000.mp4'
file 'E:\Work\dsMin\dsSupport\Working\B7\B7318F5D-46B8-4AA1-8811-1A9D65528E19\B7318F5D-46B8-4AA1-8811-1A9D65528E19_001.mp4'
file 'E:\Work\dsMin\dsSupport\Working\B7\B7318F5D-46B8-4AA1-8811-1A9D65528E19\B7318F5D-46B8-4AA1-8811-1A9D65528E19_001.mp4'
Loading…
Cancel
Save