首页 > 解决方案 > 使用 Go on App Engine Standard 调用系统包

问题描述

我正在尝试在Google App Engine Standard上运行的Go应用程序中使用FFmpeg。当我使用 exec.Command() 指向 FFmpeg 二进制文件的本地实例时,我可以让它在本地运行

cmd := exec.Command(
    "/Users/justin/Desktop/conversion/ffmpeg", // this won't work on a remote server
    "-i", "pipe:0",
    "-ac", "1",
    "-codec:a", "libmp3lame",
    "-b:a", "48k",
    "-ar", "24000",
    "-f", "mp3",
    "pipe:1",
  )

  cmd.Stdin = bytes.NewReader(synthResp.AudioContent)

  var output bytes.Buffer
  cmd.Stdout = &output
  err = cmd.Run()

显然,这在我部署应用程序时不起作用,因此我需要一种方法来指向 FFmpeg 二进制文件的托管版本。它似乎ffmpeg是 go1.11 App Engine 标准环境的系统包

什么是“系统包”以及如何使用它们? 当我查找文档时,我发现很多关于 的文档apt-get,但没有关于如何使用它们的文档,App Engine 或其他。我是否需要安装它,或者它应该已经是 App Engine 正在运行的容器(?)的一部分?

我是否像调用其他可执行文件一样调用它?如果是这样,我希望这会起作用,但事实并非如此

cmd := exec.Command(
    "ffmpeg", // <------ what should this be?
    "-i", "pipe:0",
    "-ac", "1",
    "-codec:a", "libmp3lame",
    "-b:a", "48k",
    "-ar", "24000",
    "-f", "mp3",
    "pipe:1",
  )

  cmd.Stdin = bytes.NewReader(synthResp.AudioContent)

  var output bytes.Buffer
  cmd.Stdout = &output
  err = cmd.Run()

记录错误,我明白了exec: "ffmpeg": executable file not found in $PATH

标签: google-app-enginegoffmpeg

解决方案


感谢@iLoveReflection 提出的问题,我意识到应用程序的本地运行版本将调用该ffmpeg命令,并期望它位于标准 $PATH 环境变量指向的位置。我原以为 App Engine 会识别调用ffmpeg并使用它安装在自定义位置的可执行文件。

ffmpeg可执行文件移动到/usr/local/bin,并确保 $PATH 包含该目录解决了该问题。


推荐阅读