Firebase云功能压缩视频

时间:2020-04-18 16:47:40

标签: reactjs firebase react-native google-cloud-functions firebase-storage

我已经使用react native和firebase在我的应用中成功实现了视频共享,但是我想确保存储的视频不超过1080x1080(也许是720,具体取决于它的外观)。

视频最长为8秒,如果可能,我会尽力将每个视频的大小保持在5MB以下。我能够在客户端进行一些压缩(裁剪为正方形/修剪),但是我希望能够通过云功能(存储触发器)进一步压缩视频而不会降低质量。

环顾四周后,看来Moviepy是个不错的选择,但是它使用的是python,而且我不确定如何在云函数存储触发器中使用此脚本。

这是下面的样子:

//Not sure how this will import
import moviepy.editor as mp

//Can I get the video here from the bucket path in a cloud function?
clip = mp.VideoFileClip("video-stored.mp4")

clip_resized = clip.resize(height=1080) # make the height 1080px ( According to moviePy documenation The width is then computed so that the width/height ratio is conserved.)

//resize video, then we need to store it in the same location (same file path)
clip_resized.write_videofile("video-stored-resized.mp4")

我想听听有关通过云功能进行视频压缩的一些建议,以及有关将上述脚本/模块与云功能一起使用的想法。

1 个答案:

答案 0 :(得分:0)

目前,firebase函数不支持node.js以外的语言。 因此,有两种解决方案。

  1. ,如果您想继续使用moviepy。 在node.js中触发Firebase存储并在任何首选环境中都具有python API时,编写零件以调用与moviepy相关的api。 (我猜您应该使用gcp提供的pubsub来调用python API)

  2. 在node.js中编写所有部分 在node.js中也有一个名为fluent-ffmepg的很棒的模块,但是我知道用该模块添加水印并不像moviepy那样容易。

顺便说一句,当我尝试在Firebase函数中组合vid时,由于环境的限制,我无法做到这一点。 因此,我个人建议第一个解决方案:ofc取决于您的情况,例如视频文件的大小。