【问题标题】:Firebase cloud functions compress videoFirebase 云功能压缩视频
【发布时间】:2020-08-01 04:54:43
【问题描述】:

我已经使用 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")

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

【问题讨论】:

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


【解决方案1】:

此时,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函数中组合vids时,我可能因为环境的限制而无法做到。 所以,我个人推荐第一个解决方案:这取决于你的情况,比如你的视频文件有多大。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-19
    • 2020-10-29
    • 2020-06-09
    • 2019-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-29
    相关资源
    最近更新 更多