视频点播 VOD-示例1:媒资上传(20M以下):操作步骤
操作步骤
- 获取用户Token,用于调用点播接口时进行认证鉴权。
详细信息请参见构造请求。以“华北-北京四”为示例,若您需要调用其它区域的点播接口,请替换成对应区域的 IAM 终端节点。
POST https://iam.cn-north-4.myhuaweicloud.com/v3/auth/tokens Content-Type: application/json { "auth": { "identity": { "methods": [ "password" ], "password": { "user": { "name": "username", "password": "password", "domain": { "name": "domainname" } } } }, "scope": { "project": { "name": "projectname" } } } }
如图2所示,红框中的信息为获取用户Token。 - 调用创建媒资:上传方式接口,创建媒资,在请求头中增加“X-Auth-Token”字段,其中“Value”为步骤1获取的。
POST https://vod.cn-north-4.myhuaweicloud.com/v1.0/{project_id}/asset { "title": "test", "description": "test", "category_id": 87748, "video_name": "test.mp4", "video_type": "MP4", "cover_type": "PNG", "tags":"mytags,test", "auto_publish": 0, "template_group_name":"test", "subtitles":[ { "id":1, "language":"CN", "type": "SRT", "md5": "SqcyFjJZoDZaP8oKIY6rgQ==", "description":"AAAAA" , "name":"cc.srt" } ], "thumbnail":{ "type":"time", "cover_position":1 }, "review":{ "interval":10, "politics":-1, "terrorism":-1, "porn":-1 } }
- 在返回参数中获取“video_upload_url”,“cover_upload_url”和“subtitle_upload_urls”。
{ "asset_id": "3f40a2c7c60454f5f84381e0313ca230", "video_upload_url": "https://vod-bucket-81.obs.cn-north-4.myhuaweicloud.com:443/474bcff2992f4be5b883a2fb9cec7343/3f40a2c7c60454f5f84381e0313ca230/cdeda86cd1b7b3dd760a3ff28a5ee497.mp4?AWSAccessKeyId=BG923RWHL4HFXOGKCVAL&Expires=1560420274&Signature=9f%2BZcdD6SwjIU5ARHYiP6YY1Lyw%3D", "cover_upload_url": "https://vod-bucket-81.obs.cn-north-4.myhuaweicloud.com:443/474bcff2992f4be5b883a2fb9cec7343/3f40a2c7c60454f5f84381e0313ca230/cover/Cover0.png?AWSAccessKeyId=BG923RWHL4HFXOGKCVAL&Expires=1560420274&Signature=4Aa88NK%2By%2By1Xo0RvLpOvuaFCoE%3D", "subtitle_upload_urls": [ "https://vod-bucket-81.obs.cn-north-4.myhuaweicloud.com:443/474bcff2992f4be5b883a2fb9cec7343/3f40a2c7c60454f5f84381e0313ca230/subtitle/1.srt?AWSAccessKeyId=BG923RWHL4HFXOGKCVAL&Expires=1560420274&Signature=l0UclE9yfaVrxkl0kaNnr%2BemG98%3D" ], "target": { "bucket": "vod-bucket-81", "location": "cn-north-4", "object": "474bcff2992f4be5b883a2fb9cec7343/3f40a2c7c60454f5f84381e0313ca230/cdeda86cd1b7b3dd760a3ff28a5ee497.mp4" } }
- 使用PUT请求分别向“video_upload_url”,“cover_upload_url”和“subtitle_upload_urls”中上传音视频文件、封面图片和字幕文件。
其中,请求头“Content-Type”需要根据上传的文件类型分别设置,如下所示:
- 视频文件:video/视频格式,如:“video/mp4”。更多视频文件格式对应的请求头填写规则,请参见表1。
- 音频文件:audio/音频格式,如:“audio/mp3”。更多音频文件格式对应的请求头填写规则,请参见表2。
- 图片文件:image/图片格式,如:“image/png”。
- 字幕文件:application/octet-stream。
表1 视频文件请求头填写说明 文件后缀
Content-Type
MP4
video/mp4
MOV
video/quicktime
MXF
application/mxf
TS
video/mp2t
MPG
video/mpeg
FLV
video/flv
WMV
video/x-ms-wmv
AVI
video/x-msvideo
M4V
video/m4v
F4V
application/f4v
MPEG
video/mpeg
M3U8
application/octet-stream
_3GP/3GP
video/3gpp
ASF
video/x-ms-asf
MKV
video/x-matroska
WEBM
video/webm
MPD
video/dash
- 调用接口确认媒资上传接口,完成媒资上传。
POST https://vod.cn-north-4.myhuaweicloud.com/v1.0/{project_id}/asset/status/uploaded { "asset_id": "0f4d3f1f32ec353d8866f2d84a036124", "status":"CREATED" }
媒资上传成功后,您可以在 视频点播 控制台查看媒资相关详细信息。