dss524049 2016-09-14 17:40
浏览 523

在Golang exec中使用管道运行命令

I am trying to get the example from here working to record a webpage with phantomjs and pipe the stdout, which are images, to the ffmpeg command to create the video. The command stated that you need to run is:

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

If I run a similar version of that command directly in the terminal, I can get it working just fine. The issue is that I need to run the above command through the Golang os/exec package. With the:

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

method, the first parameter is the base executable of the command being executed and it is not honoring the pipe. I would like to get this working in one command so I don't have to write all the images to files and then run a second ffmpeg command to read from all of those images. Any suggestions?

  • 写回答

1条回答 默认 最新

  • dsxi70423 2016-09-15 07:06
    关注

    I think this will help you.

         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))
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么