简体   繁体   English

在谷歌云平台上使用 FFMPEG

[英]Using FFMPEG on Google Cloud Platform

I'm storing audio files on Google Cloud Storage (through Firebase storage).我将音频文件存储在 Google Cloud Storage 上(通过 Firebase 存储)。

I need to use FFMPEG to convert the audio file from stereo (two channels) to mono (one channel).我需要使用 FFMPEG 将音频文件从立体声(两个通道)转换为单声道(一个通道)。

How can I perform the above conversion on Google Cloud Platform?如何在谷歌云平台上执行上述转换?

Update: I suspect one possibility is to use Google Compute Engine to create a virtual machine, install ffmpeg, and somehow gain access to the audio files.更新:我怀疑一种可能性是使用 Google Compute Engine 创建虚拟机,安装 ffmpeg,并以某种方式获得对音频文件的访问权限。

I'm not sure if this is the best way or even possible.我不确定这是否是最好的方法,甚至是可能的。 So I'm still investigating.所以我还在调查。

If you have code that exists already which can talk to Google Cloud Storage, you can deploy that code as an App Engine application which runs on a Custom Runtime .如果您已有可以与 Google Cloud Storage 通信的代码,则可以将该代码部署为在Custom Runtime上运行的 App Engine 应用程序。 To ensure the ffmpeg binary is available to your application, you'd add this to your app's Dockerfile :为确保您的应用程序可以使用ffmpeg二进制文件,您需要将其添加到应用程序的Dockerfile

RUN apt-get install ffmpeg

Then, it is just a matter of having your code save the audio file from GCS somewhere in /tmp , then shelling out to /usr/bin/ffmpeg to do your conversion, then having your code do something else with the resulting output file (like serving it back to the client or saving it back to Cloud Storage).然后,只需让您的代码将来自 GCS 的音频文件保存在/tmp中的某处,然后转至/usr/bin/ffmpeg进行转换,然后让您的代码对生成的输出文件执行其他操作(比如将其服务回客户端或将其保存回 Cloud Storage)。

If you're not using the flexible environment or Kubernetes, download the ffmpeg binaries (Linux-64) from https://ffbinaries.com/downloads and include ffmpeg and ffprobe directly in your app.如果您不使用灵活的环境或 Kubernetes,请从https://ffbinaries.com/downloads下载 ffmpeg 二进制文件 (Linux-64),并将 ffmpeg 和 ffprobe 直接包含在您的应用程序中。 For apps using the standard environment this is really the only way without switching.对于使用标准环境的应用程序,这确实是唯一无需切换的方法。

Once you've added them, you'll need to point to them in your options array:添加它们后,您需要在选项数组中指向它们:

$options = array(
    'ffmpeg.binaries'  => '/workspace/ffmpeg-binaries/ffmpeg',
    'ffprobe.binaries' => '/workspace/ffmpeg-binaries/ffmpeg',
    'timeout'          => 3600,
    'ffmpeg.threads'   => 12,
);

To have it work locally, you should make them environment variables to point to the correct path in each set up.要让它在本地工作,您应该使它们成为环境变量以指向每个设置中的正确路径。 Add something like export FFMPEG_BINARIES_PATH="/usr/local/bin" (or wherever you have them locally) to your.zshrc or other rc file and the below code to your app.yaml:添加类似export FFMPEG_BINARIES_PATH="/usr/local/bin"的东西(或者你在本地的任何地方)到你的 .zshrc 或其他 rc 文件,并将以下代码添加到你的 app.yaml:

env_variables:
    FFMPEG_BINARIES_PATH: '/workspace/ffmpeg-binaries'

And then change the options array to:然后将选项数组更改为:

$options = array(
    'ffmpeg.binaries'  => getenv("FFMPEG_BINARIES_PATH") . '/ffmpeg',
    'ffprobe.binaries' => getenv("FFMPEG_BINARIES_PATH") . '/ffmprobe',
    'timeout'          => 3600,
    'ffmpeg.threads'   => 12,
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM