Ubuntu Server 16.04.1 LTS 64-bit
or Ubuntu Server 18.04.1 LTS 64-bit
.SecretId
and SecretKey
) is required for video upload. If you have not created an API key yet, please generate one as instructed in Root Account Access Key. If you have already created a key, please get it as instructed in the same document.ubuntu@VM-69-2-ubuntu:~$ export SECRET_ID=AKxxxxxxxxxxxxxxxxxxxxxxx; export SECRET_KEY=xxxxxxxxxxxxxxxxxxxxx;git clone https://github.com/tencentyun/vod-server-demo.git ~/vod-server-demo; bash ~/vod-server-demo/installer/server_upload.sh
SECRET_ID
and SECRET_KEY
in the command.[2020-06-23 19:56:31] Start installing pip3.[2020-06-23 19:56:34] pip3 is successfully installed.[2020-06-23 19:56:34] Start installing the VOD upload SDK for Python.[2020-06-23 19:56:36] The VOD upload SDK for Python is successfully installed.[2020-06-23 19:56:36] Start configuring SDK parameters.[2020-06-23 19:56:36] SDK parameter configuration is completed.
ubuntu@VM-69-2-ubuntu:~$ wget http://1400329073.vod2.myqcloud.com/d62d88a7vodtranscq1400329073/7a9b2b565285890804459281865/v.f100010.mp4 -O ~/vod-server-demo/server_upload/tencent_cloud.mp4; wget http://1400329073.vod2.myqcloud.com/ff439affvodcq1400329073/8aa658d15285890804459940822/5285890804459940825.jpg -O ~/vod-server-demo/server_upload/tencent_cloud.jpg
server.upload.py
script to start uploading:ubuntu@VM-69-2-ubuntu:~$ cd ~/vod-server-demo/server_upload/; python3 server_upload.py ./tencent_cloud.mp4 ./tencent_cloud.jpg
tencent_cloud.mp4
video to VOD and upload the tencent_cloud.jpg
image as its cover. After the upload is completed, the remote terminal will print information similar to the following:{"CoverUrl": "http://1400329073.vod2.myqcloud.com/ff439affvodcq1400329073/8aa658d15285890804459940822/5285890804459940825.jpg", "FileId": "5285890804459940822", "MediaUrl": "http://1400329073.vod2.myqcloud.com/ff439affvodcq1400329073/8aa658d15285890804459940822/f0.mp4", "RequestId": "84a7fb42-9f05-4acd-9cc8-843690b188ce"}
main()
is the script entry.parse_conf_file()
and read the configuration information from the config.json
file. The configuration items are as described below:Field | Data Type | Description |
secret_id | String | API key |
secret_key | String | API key |
procedure | String | Task flow name. The specified task flow will be automatically triggered after video upload is completed. It is empty by default |
subappid | String | Whether to upload the video to a VOD subapplication |
procedure
and subappid
upload parameters. For the complete features, please see SDK for Python.upload_media()
to initiate upload:if len(sys.argv) < 2:usage()returnvideo_path = sys.argv[1]cover_path = sys.argv[2] if len(sys.argv) > 2 else ""# Initiate uploadrsp = upload_media(configuration, video_path, cover_path)
upload_media()
, use the method provided by the SDK for Python to construct an upload instance client
, set upload parameters in req
, and initiate upload:client = VodUploadClient(conf["secret_id"], conf["secret_key"])req = VodUploadRequest()req.MediaFilePath = videoif cover != "":req.CoverFilePath = coverif conf["procedure"] != "":req.Procedure = conf["procedure"]req.SubAppId = int(conf["subappid"])rsp = client.upload("ap-guangzhou", req)return rsp
"ap-guangzhou"
) in client.upload()
is the access region of the upload instance rather than the storage region of the uploaded video. You can simply fix the parameter value as "ap-guangzhou"
. If you want to specify the storage region for uploaded videos, please set the req.StorageRegion
parameter.
Was this page helpful?