简体   繁体   中英

Using FFMPEG on Google Cloud Platform

I'm storing audio files on Google Cloud Storage (through Firebase storage).

I need to use FFMPEG to convert the audio file from stereo (two channels) to mono (one channel).

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.

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 . To ensure the ffmpeg binary is available to your application, you'd add this to your app's 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).

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. 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:

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,
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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