58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
)
|
|
|
|
// srs-ffmpeg-tools.exe --file_path=F:/go-workspace/mysql-backup-local/前任4.mp4 --stream_path=rtmp://192.168.1.254:1935/live/test
|
|
func main() {
|
|
|
|
var file_path string
|
|
var stream_path string
|
|
|
|
flag.StringVar(&file_path, "file_path", "", "将要播放的文件路径")
|
|
flag.StringVar(&stream_path, "stream_path", "", "推流地址")
|
|
flag.Parse()
|
|
|
|
if file_path == "" {
|
|
fmt.Println("***********************************************************************************************")
|
|
fmt.Println("******************* --file_path 播放的文件路径")
|
|
fmt.Println("******************* --stream_path 推流地址")
|
|
fmt.Println("******************* 默认地址:rtmp://192.168.1.254:1935/live/livestream")
|
|
fmt.Println("***********************************************************************************************")
|
|
return
|
|
}
|
|
|
|
if stream_path == "" {
|
|
stream_path = "rtmp://192.168.1.254:1935/live/livestream"
|
|
}
|
|
fmt.Println("推流地址:" + stream_path)
|
|
path, err2 := os.Executable()
|
|
|
|
if err2 != nil {
|
|
log.Fatal(err2)
|
|
}
|
|
path = filepath.Dir(path) // 获取当前文件的目录
|
|
|
|
path += "/ffmpeg-6.0-essentials_build/bin/ffmpeg.exe"
|
|
|
|
cmd := exec.Command(path, "-re", "-i", file_path, "-f", "flv", "-c:v", "copy", "-c:a", "copy", stream_path)
|
|
// 设置命令执行的环境变量(可选)
|
|
cmd.Env = os.Environ()
|
|
|
|
// 设置命令执行的输出和错误输出(可选)
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
|
|
// 执行命令
|
|
err := cmd.Run()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|