Example 2: Submit a Video Transcoding Task
Scenario
If you need to transcode a video file stored in an OBS bucket and add an image watermark, you can call an MPC API to transcode the video file.
This section describes how to submit a video transcoding task by invoking an API.
Constraints
Cross-region transcoding is not supported. For example, MPC in the CN North-Beijing1 region cannot transcode video files stored in an OBS bucket in the CN North-Beijing4 region.
Prerequisites
- You have obtained the project ID of the region where the transcoding task is to be created. For details, see Obtaining a Project ID.
- You have determined the region where the transcoding task to be created is located and obtained the endpoint of MPC for this region from the Regions and Endpoints.
- You have stored the video file to be transcoded in an OBS bucket. If you have not, call the API for uploading an object to upload the file.
- You have created an OBS bucket where transcoding outputs will be stored. If you have not, call the API for creating a bucket.
Overall Process
Procedure
- Obtain a user token and use it to authenticate the calling of MPC APIs.
Obtain the username, password, domainname, and projectname from the My Credentials page. Call the following API to obtain the token. For details, see Making an API Request.
POST https://iam.cn-north-4.myhuaweicloud.com/v3/auth/tokens Content-Type: application/json { "auth": { "identity": { "methods": [ "password" ], "password": { "user": { "name": "********", //Username "password": "********", //Login password "domain": { "name": "domainname" //Name of the account to which the user belongs } } } }, "scope": { "project": { "name": "*******" //Project name } } } }
As shown in Figure 1, information in the red box indicates the user token.
- Create a video transcoding template and obtain the transcoding template ID. For details about how to call the API for creating a transcoding template, see Example 1: Create a Transcoding Template.
- Create a watermark template.
- Select the POST request method and enter the request URI.
https://{endpoint}/v1/{project_id}/template/watermark
- In the request header, add X-Auth-Token and set its value to be the token obtained in 1.
- Specify the following parameters in the request body:
{ "template_name": "watermark_1920*1080_10*10_ BottomLeft", "type": "Image", "image_process": "Grayed", "width": "1920", "height": "1080", "dx": "10", "dy": "10", "referpos": "BottomLeft", "timeline_start": "6", "timeline_duration": "8" }
- If the request succeeds, the watermark template ID is returned.
{ "template_id":242 }
- Select the POST request method and enter the request URI.
- Submit the transcoding task.
- Select the POST request method and enter the request URI.
https://{endpoint}/v1/{project_id}/transcodings
- In the request header, add X-Auth-Token and set its value to be the token obtained in 1.
- Specify the following parameters in the request body:
{ "input": { "bucket": "example-bucket", "location": "region01", "object": "/mpc/input/sample.MP4" }, "output": { "bucket": "example-bucket", "location": "region01", "object": "/mpc/output/" }, "trans_template_id":[1002], "watermarks": [{ "input": { "bucket": "example-bucket", "location": "region01", "object": "meipai.jpg" }, "template_id":242 }], "priority":"9", "audit":{ "position":2, "index":2 } }
- If the request succeeds, the transcoding task ID is returned.
{ "task_id":100211 }
- Select the POST request method and enter the request URI.
- Query the task status.
- Select the GET request method and enter the request URI.
https://{endpoint}/v1/{project_id}/transcodings?task_id=100211
- In the request header, add X-Auth-Token and set its value to be the token obtained in 1.
- If the request succeeds, details about the transcoding task are returned.
- Select the GET request method and enter the request URI.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot