12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package main
- import (
- "bytes"
- "fmt"
- "os/exec"
- "strings"
- )
- const (
- CMD = `ffmpeg`
- FileName = `./ffmpeg/mp4/wph.mp4`
- TEMPDir = `./ffmpeg/output/`
- AudioPickUpArgs = `-i %s -y -vn -acodec copy %s` // 音频提取
- VideoPickUpArgs = `-i %s -y -an -vcodec copy %s` // 视频提取
- SRTPickUpArgs = `-i %s -map 0:s:0 %s` // 文本字幕提取 or `-i %s -an -vn -bsf:s mov2textsub -scodec copy -f rawvideo %s` or `-i %s -an -vn -c:s copy -f rawvideo -map 0:s %s`
- ASSPickUpArgs = `-i %s -an -vn -scodec copy %s` // ASS字幕提取
- VideoAndAudioMergeArgs = `-i %s -i %s -y -vcodec copy -acodec copy %s` // 音视频混编
- SRTMapArgs = `-i %s -i %s -c copy -c:s mov_text %s` // 增加SRT字幕
- ASSMapArgs = `-i %s -i %s -map 0:0 -map 0:1 -map 1 -c:a copy -c:v copy -c:s copy %s` // 增加ASS字幕
- PushFlv = `-re -i %s -c copy -f flv %s` // 推Flv流
- )
- func main() {
- //_ = os.RemoveAll(TEMPDir)
- //_ = os.Mkdir(TEMPDir, os.ModePerm)
- //runCmd(CMD, strings.Split(fmt.Sprintf(AudioPickUpArgs, FileName, TEMPDir+`wph.aac`), " "))
- //runCmd(CMD, strings.Split(fmt.Sprintf(VideoPickUpArgs, FileName, TEMPDir+`wph.mp4`), " "))
- //if path.Ext(FileName) == "mkv" { // mkv文件才能提取出字幕流,mp4通常会报错
- // runCmd(CMD, strings.Split(fmt.Sprintf(SRTPickUpArgs, FileName, TEMPDir+`wph.txt`), " "))
- //}
- //runCmd(CMD, strings.Split(fmt.Sprintf(VideoAndAudioMergeArgs, TEMPDir+`wph.mp4`, TEMPDir+`wph.aac`, TEMPDir+`wph1.mp4`), " "))
- runCmd(CMD, strings.Split(fmt.Sprintf(PushFlv, FileName, `rtmp://localhost:1935/live/test`), ` `))
- }
- func runCmd(name string, args []string) {
- cmd := exec.Command(name, args...)
- buf := new(bytes.Buffer)
- cmd.Stdout = buf
- err := cmd.Run()
- if nil != err {
- panic(err.Error())
- } else {
- println(buf.String())
- }
- }
|