spa*_*ode 9 video-streaming google-cloud-storage google-cloud-platform
我已将视频存储在谷歌云存储浏览器上。我想在我的前端播放这些视频。为此,我需要视频 URL。但问题是,每当我导航到该 URL 时,就会下载该文件。
我需要做什么才能获取我存储的对象的流视频 URL?
Cloud Storage 支持使用gcloud进行流式传输。您还可以使用第三方Boto python lib在应用程序的后端进行流传输。
但既然你希望这个解决方案是通过前置来实现的,我猜你实际上是在寻找一个媒体播放器。
因此,您需要:
1.- 生成对象(您的视频)的SignedUrl :
使用 gcloud 命令:
gsutil signurl -d 10m Desktop/private-key.json gs://example-bucket/cat.jpeg
Run Code Online (Sandbox Code Playgroud)
使用 python 库:
gsutil signurl -d 10m Desktop/private-key.json gs://example-bucket/cat.jpeg
Run Code Online (Sandbox Code Playgroud)
2.- 使用该 url 初始化 HMTL5 媒体播放器:
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")
Run Code Online (Sandbox Code Playgroud)
我使用 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>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11655 次 |
| 最近记录: |