You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
)
func main(){
dir, _ := os.Getwd()
//1、视频文件名称
movie:=dir+"/Source/1.wmv"
//2、输出的文件通配名称
target:=dir+`/Target/piece_%03d.wmv`
//3、对视频文件进行切片
cmdLine:=dir+`\ffmpeg\ffmpeg.exe -fflags +genpts -i `+movie+` -acodec copy -vcodec copy -f segment -segment_time 300 -reset_timestamps 1 -map 0:0 -map 0:1 `+target
cmd := exec.Command("cmd.exe", "/c", "start " + cmdLine)
err := cmd.Run()
fmt.Printf("%s, error:%v \n", cmdLine, err)
//4、切片完成后尝试进行转码
//获取当前目录下的文件或目录名(包含路径)
filepathNames,_ := filepath.Glob(filepath.Join(dir+`/Target`,"*"))
for i := range filepathNames {
cmdLine=dir+`\ffmpeg\ffmpeg.exe -i `+filepathNames[i]+` -c:v libx264 -strict -2 `+strings.Replace(filepathNames[i],".wmv",".mp4",-1)
cmd = exec.Command("cmd.exe", "/c", "start " + cmdLine)
err = cmd.Run()
fmt.Printf("%s, error:%v \n", cmdLine, err)
}
}