google-app-engine - 使用 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
解决方案
感谢@iLoveReflection 提出的问题,我意识到应用程序的本地运行版本将调用该ffmpeg
命令,并期望它位于标准 $PATH 环境变量指向的位置。我原以为 App Engine 会识别调用ffmpeg
并使用它安装在自定义位置的可执行文件。
将ffmpeg
可执行文件移动到/usr/local/bin
,并确保 $PATH 包含该目录解决了该问题。
推荐阅读
- java - 使用 ThreadLocal.get() 获取不确定值
- jquery - 调用/显示html元素时如何从数据库中加载值
- vue.js - 将数据从组件发送到组件
- css - 使 div 容器调整为 svg 高度
- c++ - CUDA C++ 从主机读取图像并复制到设备
- c# - 更改项目以使用 DI 后的 EF Core 迁移
- reactjs - 即浏览器 iframe 有 src 源但 body 和 head 是空的
- mysql - 如何在 Mysql 中处理外键约束失败
- c++ - 从右到左 - 在链后递增作为回报
- opencv - EmguCV/OpenCV 图像融合和 GPU (CUDA)