3

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.

Pete Streem
  • 360
  • 5
  • 14
  • Please consider accepting an answer if one has been helpful. See [how does accepting an answer work](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) for info. – Jake Nelson Dec 22 '21 at 13:50
  • 1
    Hey @JakeNelson, sorry for delay. Thanks for your answer - guided me in the right direction of the search. – Pete Streem Dec 28 '21 at 11:46
  • @PeteStreem Hi! I am also implementing the scenario. Can you please share your journey and how you achieved this task? – Mrcreamio Jun 17 '22 at 08:54
  • 1
    @Mrcreamio Sorry man, I have not finished that project and it is still on hold for now due to war in our country. If I remember correctly, I tried to tigger a transcoder job on special google api, called Pipelines. You can create any pipeline you want (mp4->hls) and call it each time, user uploads mp4 file. Inside pipeline I used a nodejs library that decoded video stream. If you achieve a success story, will be also pleased if you share some instructions. – Pete Streem Jun 22 '22 at 15:14
  • @PeteStreem Thank you for replying. Sure I will share my journey. – Mrcreamio Jun 23 '22 at 06:09

1 Answers1

5

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
Jake Nelson
  • 1,748
  • 13
  • 22
  • Very expensive solution. Especially for a video of big size. – Xenolion Mar 29 '23 at 14:04
  • @Xenolion, suggest a cheaper one as an answer so people can use that. – Jake Nelson Mar 30 '23 at 06:17
  • Transcoder API is very expensive for smaller videos like what the asker has stated I would recommend to use `ffmpeg` directly in a cloud function. Thanks to google now ffmpeg is available in cloud function. https://stackoverflow.com/questions/42773497/can-you-call-out-to-ffmpeg-in-a-firebase-cloud-function – Xenolion Mar 30 '23 at 10:55