如何使用Blobstore API存储在GCS中播放(流而不是下载)视频文件 [英] How to play(stream instead of download) video file which was stored in GCS using Blobstore API

查看:117
本文介绍了如何使用Blobstore API存储在GCS中播放(流而不是下载)视频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何播放(流而不是下载)存储在GCS中的视频文件?该文件是在GAE Python中使用Blobstore API存储的?
目前,当我在前端使用由send_blob返回的url时,视频被下载。



我使用以下方式提供视频:

  video_url =/ v?video_id =+ video_blobkey 

::

class GCSFileServe(blobstore_handlers.BlobstoreDownloadHandler):
def get(self):
blob_key = self.request.get('video_id')
self.send_blob(blob_key)

::

app = webapp2.WSGIApplication([
('/',MainHandler),
('/ v',GCSFileServe),
],debug = True)

我上传视频并存储blobkey:

  filename = bucket +/ user_video _+ str(user_index)+_+ str(i)
gcs_file = gcs.open(filename,'w',content_type ='video / avi')
gcs_file.write(video)
gcs_file.close()
blobstore_filename ='/ gs'+ filename
video_blobkey = blobstore.create_gs_key(blobstore_filename)

在前端,我将视频网址传递给 TINY Box 2 jquery模式插件。如果我提供YouTube视频网址,而不是上传到GCS的视频,则此功能非常完美。



我看到流式传输在GCS文档中的主题,但可以理解如何在这种情况下使用它(如果这是解决方案)。

解决方案

最后,我想出了自己的想法。
其实,我提供视频的方式没有问题。问题出在我使用的 Galleria jquery插件。它可以播放来自youtube和其他几个网站的视频,但如果您指定了其他网址(例如自己托管的视频文件),则不会。


解决方案

我切换到 Videojs 在我的网站上播放视频。

How to play(stream instead of download) a video file stored in GCS? The file was stored using Blobstore API in GAE Python? Presently, the video gets downloaded when I use the url, returned by send_blob, in the frontend.

I serve the video using:

video_url = "/v?video_id="+video_blobkey 

:: 

class GCSFileServe(blobstore_handlers.BlobstoreDownloadHandler):
    def get (self): 
        blob_key = self.request.get('video_id') 
        self.send_blob(blob_key) 

:: 

app = webapp2.WSGIApplication([
    ('/', MainHandler), 
    ('/v', GCSFileServe), 
], debug=True)

I upload the video and store the blobkey:

filename = bucket + "/user_video_"+str (user_index) + "_" + str (i) 
gcs_file = gcs.open (filename, 'w', content_type = 'video/avi') 
gcs_file.write (video) 
gcs_file.close () 
blobstore_filename = '/gs' + filename 
video_blobkey = blobstore.create_gs_key (blobstore_filename)

On frontend, i pass the video URL to TINY Box 2 jquery modal plugin. This works perfectly if I provide youtube url instead of the video uploaded to GCS.

I saw Streaming Transfers topic in GCS docs but could understand how to use that in this context(if that is the solution).

解决方案

Finally, I figured it out myself. Actually, there was no problem with the way I am serving the video. The problem was with the Galleria jquery plugin which I was using. It can play videos from youtube, and a few more websites, but not if you specify a different URL (like of a self hosted video file).

Solution
I switched over to Videojs for playing videos on my website.

这篇关于如何使用Blobstore API存储在GCS中播放(流而不是下载)视频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆