Skip to content

Google Cloud Function that creates LINEAR16 converted copies of files uploaded to Google Cloud Storage.

License

Notifications You must be signed in to change notification settings

newgotecnologia/gfc-ffmpeg-linear16

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

GCF FFmpeg convert to LINEAR16

This Cloud Function automatically creates a LINEAR16 converted copy of files uploaded to Google Cloud Storage. Intended to be compatible for usage with Google Cloud Speech-to-Text API.

The audio is converted to the s16le format and codec, with mono-channel audio @ 16000hz.

This function was based on the ffmpeg-convert-audio function sample from firebase/functions-samples.

Functions Code

See file functions/index.js for the audio conversion code.

The audio is first downloaded locally from the Cloud Storage bucket to the tmp/ folder using the Node.js Client. Then the audio is converted using FFmpeg and uploaded back to the bucket.

Trigger rules

The function should be set to trigger on upload of any file to your Firebase project's default Cloud Storage bucket.

Deploy and test

To deploy and test the function:

  • Create a Firebase or Google Cloud project and open the bucket which the function will subscribe to.
  • Deploy the code by creating the function via Cloud Console or via the gcloud command line tool, see below.
  • Upload a file to the bucket, monitor your function logs and after the processing is over the bucket should have the converted file with a _converted.pcm suffix.

Deploying via Cloud Console

  1. Go to the Create function page and choose your settings.
  2. Copy and paste the code from functions/index.js and functions/package.json into their respective files.
  3. Follow the instructions to deploy the function and monitor/test it.

Be sure to have the tool configured to target the correct project.

  1. Get the code, for instance using git clone .
  2. Enter the correct directory cd gfc-ffmpeg-linear16/.
  3. Deploy the function via the gcloud functions deploy command with your settings.

Notes

  • Take into account that the audio files produced should not exceed the size of the memory of your function.
  • The audio conversion could take a certain amount of time, increase the timeout of your function using the cloud functions webgui so the function can run for a longer time.
  • When deploying, be sure to select the correct bucket, trigger, event type and a service account that has enough permission.
  • Consider making your function idempotent to prevent wasting resources on repeated conversions.

License

© Google, 2015-2020. Modifications © NewGo Tecnologia, 2020. Licensed under an Apache-2 license.

About

Google Cloud Function that creates LINEAR16 converted copies of files uploaded to Google Cloud Storage.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%