【问题标题】:Running command with pipe in Golang exec在 Golang exec 中使用管道运行命令
【发布时间】:2017-01-22 14:55:25
【问题描述】:

我正在尝试从here 获取示例,该示例正在使用 phantomjs 记录网页并将标准输出(即图像)传送到 ffmpeg 命令以创建视频。声明你需要运行的命令是:

phantomjs runner.js | ffmpeg -y -c:v png -f image2pipe -r 25 -t 10  -i - -c:v libx264 -pix_fmt yuv420p -movflags +faststart dragon.mp4

如果我直接在终端中运行该命令的类似版本,我可以让它正常工作。问题是我需要通过 Golang os/exec 包运行上述命令。与:

cmd := exec.Command(parts[0], parts[1:]...)

方法,第一个参数是正在执行的命令的基本可执行文件,它不尊重管道。我想在一个命令中让它工作,这样我就不必将所有图像写入文件,然后运行第二个 ffmpeg 命令来读取所有这些图像。有什么建议?

【问题讨论】:

标签: go ffmpeg


【解决方案1】:

我想这会对你有所帮助。

     cmd := "phantomjs runner.js | ffmpeg -y -c:v png -f image2pipe -r 25 -t 10  -i - -c:v libx264 -pix_fmt yuv420p -movflags +faststart dragon.mp4"
     output, err := exec.Command("bash","-c",cmd).Output()
     if err != nil {
            return fmt.Sprintf("Failed to execute command: %s", cmd)
     }
     fmt.Println(string(output))

【讨论】:

    猜你喜欢
    • 2011-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-12
    相关资源
    最近更新 更多