This document describes how to transcode a video in VOD and get the transcoding output result.
The code provided in this document is open-source and free of charge, but it may incur the following fees during use:
Please activate the VOD service as instructed in Getting Started - Step 1.
Upload a test video as instructed in Getting Started - Step 2. Click here to view the test video used in the demo. The corresponding FileId
is 5285890804162014755
as shown below:
Note:
We recommend you use a short video file (of dozens of seconds in duration) for the test to avoid taking too much time for transcoding.
Check the uploaded test video on the Video Management page in the console and click Process Video:
In the pop-up window, select Transcoding as the processing type and click Transcoding Template:
Select the desired transcoding template and click OK. This demo uses the preset templates MP4-FLU
(ID: 100010) and MP4-SD
(ID: 100020) as examples. You can also use a custom template as instructed in Template Settings.
Click OK to initiate transcoding:
On the "Video Management" page, you can see that the test video status is "Processing", which indicates that the video is being transcoded:
On the Video Management page in the console, wait for the test video status to become "Normal", which indicates that the transcoding is completed. Then, click Manage on the right of the test video to enter the video management page:
In the Standard Transcoding List on the "Basic Information" tab, videos in MP4-FLU
and MP4-SD
specifications are output. You can click Preview on the right to directly watch the corresponding video. You can also click Copy Address to copy the URL of the corresponding output video and publish it to viewers through other channels.
The TencentCloud API request script needs to be executed on a CVM instance meeting the following requirements:
Ubuntu Server 16.04.1 LTS 64-bit
or Ubuntu Server 18.04.1 LTS 64-bit
.For detailed directions on how to purchase a CVM instance and reinstall the system, please see Operation Guide - Creating Instances via CVM Purchase Page and Operation Guide - Reinstalling System, respectively.
Note:
If you do not have a CVM instance satisfying the above conditions, you can also run the script on another Linux (such as CentOS or Debian) or macOS server with public network access, but you need to modify certain commands in the script based on the operating system. Please search for the specific modification method by yourself.
Your API key (i.e., SecretId
and SecretKey
) is required for TencentCloud API request. 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.
Please activate the VOD service as instructed in Getting Started - Step 1.
Upload a test video as instructed in Getting Started - Step 2. Click here to view the test video used in the demo. The corresponding FileId
is 5285890804162014755
as shown below:
Note:
We recommend you use a short video file (of dozens of seconds in duration) for the test to avoid taking too much time for transcoding.
Log in to the CVM instance prepared in step 1 as instructed in Logging into Linux Instance in Standard Login Method and enter and run the following command on the remote terminal:
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/transcode_api.sh
Note:
Please assign the corresponding values obtained in step 2 to
SECRET_ID
andSECRET_KEY
in the command.
This command will download the demo source code from GitHub and automatically run the installation script. The installation process will take several minutes (subject to the CVM network conditions), during which the remote terminal will print the following information:
[2020-06-15 20:39:56] Start installing pip3.
[2020-06-15 20:40:06] pip3 is successfully installed.
[2020-06-15 20:40:06] Start installing the TencentCloud API SDK for Python.
[2020-06-15 20:40:07] The TencentCloud API SDK for Python is successfully installed.
[2020-06-15 20:40:07] Start configuring API parameters.
[2020-06-15 20:40:07] API parameter configuration is completed.
Run the process_media.py
script to initiate transcoding:
ubuntu@VM-69-2-ubuntu:~$ cd ~/vod-server-demo/transcode_api/; python3 process_media.py 5285890804162014755
Note:
Please replace
5285890804162014755
in the command with the actualFileId
obtained in step 4.
This command will initiate a ProcessMedia request to the 5285890804162014755
video so as to transcode it to two VOD preset transcoding template specifications (100010
and 100020
) and print the request response content:
{"TaskId": "1400329073-procedurev2-f6bf6f01612369b6db30f2224792a2aft0", "RequestId": "809918fb-791c-4937-b684-5027ba6bc5f0"}
On the "Video Management" page, you can see that the test video status is "Processing", which indicates that the video is being transcoded:
Wait for the test video status to become "Normal", which indicates that the transcoding is completed. Then, click Manage on the right of the test video to enter the video management page:
In the Standard Transcoding List on the "Basic Information" tab, videos in MP4-FLU
and MP4-SD
specifications are output. You can click Preview on the right to directly watch the corresponding video. You can also click Copy Address to copy the URL of the corresponding output video and publish it to viewers through other channels.
VOD provides multiple video upload methods such as upload through console, upload from server, upload from client, and pull from URL (for more information, please see Overview). All upload methods allow you to specify a task flow, which can automatically trigger transcoding after the upload is completed.
After video upload or a transcoding task is completed, the VOD backend will initiate an event notification request. You can use the event notification mechanism to initiate transcoding for the newly uploaded video and automatically get the transcoding result through an event notification (the method of manually viewing the transcoding result in the console is as described above).
For more information, please see How to Receive Event Notification under Best Practices.
Was this page helpful?