我已将视频存储在Google云存储浏览器中。我想在前端播放这些视频。为此,我需要视频URL。但是问题是,每当我导航到该URL时,文件都会被下载。
我该怎么做才能获取存储对象的流视频URL?
答案 0 :(得分:2)
我使用video.js做到了这一点。
<html>
<head>
<link href="https://unpkg.com/video.js/dist/video-js.css" rel="stylesheet">
<style>
.video-js {
width: 600px;
height: 600px;
}
</style>
</head>
<body>
<video-js controls data-setup="{}">
<source src="https://storage.cloud.google.com/bucketName/folderName/recordingName.flv" type="video/flv">
</video-js>
<script src="https://unpkg.com/video.js/dist/video.min.js"></script>
<script src="https://unpkg.com/videojs-flash/dist/videojs-flash.min.js"></script>
</body>
</html>
答案 1 :(得分:0)
Cloud Storage确实支持使用gcloud进行流传输。您也可以使用第三方Boto python lib在应用程序的后端进行流传输。
但是,由于您希望该解决方案能够以前端实现,所以我猜您实际上是在寻找媒体播放器。
因此,您需要:
1.-生成对象(您的视频)的SignedUrl:
使用gcloud命令:
gsutil signurl -d 10m Desktop/private-key.json gs://example-bucket/cat.jpeg
使用python lib:
from google.cloud import storage
import datetime
def generate_download_signed_url_v4(bucket_name, blob_name):
"""Generates a signed URL for downloading a blob.
Note that this method requires a service account key file. You can not use
this if you are using Application Default Credentials from Google Compute
Engine or from the Google Cloud SDK.
"""
storage_client = storage.Client.from_service_account_json('key.json')
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(blob_name)
url = blob.generate_signed_url(
# This URL is valid for 15 minutes
expiration=datetime.timedelta(minutes=15),
# Allow GET requests using this URL.
method='GET'
)
print('Generated GET signed URL:')
print(url)
print('You can use this URL with any user agent, for example:')
print('curl \'{}\''.format(url))
return url
generate_download_signed_url_v4("example-id", "example.mp4")
2.-使用该URL初始化HMTL5媒体播放器:
<!DOCTYPE html>
<html>
<body>
<video width="320" height="240" controls>
<source src="video-signedurl.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</body>