node.jsgoogle-cloud-platformffmpeggoogle-cloud-transcoder

Google Cloud Platform: Convert uploaded MP4 file to HLS file


I am building a platform, that allows users to upload some video files (20-40 seconds) from their phone to server. All this upload is working great for now, files are stored in google storage bucket via nodejs cloud functions.

Now I want to create a gcp transcoder-job, that will convert uploaded .mp4 video file to .hls video stream with .ts chunks of 2-4 seconds duration.

Probably success scenario:

  1. User uploads mp4 file [Done]
  2. .mp4 file after upload triggers functions.storage.object().onFinalize [Done]
  3. onFinalize triggers Google Cloud Job, that will convert mp4 to hls. [We are here]
  4. .mp4 file is removed from google storage.

Will appreciate any help on creating such job. I am using firebase cloud functions with nodejs.


Solution

  • I would do this using the transcoder API in GCP. It supports mp4 input and hls output. See supported formats

    Note that videos must be greater than 5 seconds in length. If they can't be 5 seconds in length, maybe avoid this API and using a tool on AppEngine.

    A rough flow of events to accomplish this could be something like:

    1. Upload MP4 to bucket
    2. pubsub is triggered from the upload event
    3. This can trigger a cloud function that can create a new Transcoder job
    4. The job status updates a pubsub topic
    5. Pubsub topic triggers a cloud function when the status indicates the job is done
    6. Cloud function deletes the original mp4 from the bucket