Creating a Video Parsing Task
You can create a video parsing task by creating an MpcClient instance and setting related parameters. The task is used to parse video metadata.
Prerequisites
- You have bought Object Storage Service (OBS) resources and uploaded an input file to an OBS bucket which is in the same region (for example, CN North-Beijing4) as MPC by referring to Uploading Media Files.
- MPC has been authorized to access OBS resources. For details, see Authorizing Access to Cloud Resources.
Core Code
- Create MPC configuration items.
These configuration items are used for MPC to obtain authorization. Table 1 describes the parameters.
1 2 3 4 5
MpcConfig mpcConfig = new MpcConfig(); mpcConfig.setEndPoint(endPoint);// Set the endpoint. mpcConfig.setProjectId(projectId);// Set the project ID. mpcConfig.setSk(sk);// Set the SK. mpcConfig.setAk(ak);// Set the AK.
Table 1 MPC parameters Parameter
Type
Description
endPoint
String
Endpoint. For details, see Obtaining an Endpoint.
ProjectId
String
Project ID. For details, see Obtaining a Project ID and Account Name.
ak
String
Access key ID (AK). For details, see Obtaining the AK/SK Pair.
sk
String
Secret Access Key (SK) used together with the AK. For details, see Obtaining the AK/SK Pair.
- Create an MpcClient instance.
If no proxy server is configured, you can directly create an MpcClient instance.
1 2
// Create an MpcClient instance. MpcClient mpcClient = new MpcClient(mpcConfig);
If a proxy server needs to be configured, set proxy parameters and then transfer the proxy as a constructor to the MpcClient instance.
1 2 3 4 5 6 7 8
// Configure the proxy. ClientConfig clientConfig = new ClientConfig(); clientConfig.setProxyHost(proxyHost);// Set the IP address of the proxy server. clientConfig.setProxyPort(Integer.parseInt(proxyPort));// Set the port number of the proxy server. clientConfig.setProxyUserName(proxyUserName);// Set the username for accessing the proxy server. clientConfig.setProxyPassword(proxyPassword);// Set the password for accessing the proxy server. // Use the constructor to initialize MpcClient. MpcClient mpcClient =new MpcClient(mpcConfig, clientConfig);
- Create a video parsing task.
For a video parsing task, you need to set input video file parameters. If necessary, you can save the metadata file to a specified path.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
CreateExtractTaskReq req = new CreateExtractTaskReq(); // Set the input file path. ObsObjInfo input = new ObsObjInfo(); input.setBucket("obs-test"); input.setLocation("cn-north-4"); input.setObject("test.flv"); req.setInput(input); // Set the output file path. ObsObjInfo output = new ObsObjInfo(); output.setBucket("obs-test"); output.setLocation("cn-north-7"); output.setObject("/test-output/"); output.setFileName("my-test.txt"); req.setOutput(output); // Send a request. CommonCreateTaskRsp rsp = mpcClient.createExtractTask(req); // Print the result. System.out.println(gson.toJson(rsp));
Full Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import com.google.gson.Gson;
import com.huawei.mpc.client.MpcClient;
import com.huawei.mpc.client.MpcConfig;
import com.huawei.mpc.model.CommonCreateTaskRsp;
import com.huawei.mpc.model.ObsObjInfo;
import com.huawei.mpc.model.extract.CreateExtractTaskReq;
Gson gson = new Gson();
MpcConfig mpcConfig = new MpcConfig();
mpcConfig.setEndPoint("mpc.cn-north-4.myhuaweicloud.com:443");
mpcConfig.setProjectId("ca225055625d48f6888f60730fb82657");
mpcConfig.setAk("Your project ID");
mpcConfig.setSk("****************************************");
MpcClient mpcClient = new MpcClient(mpcConfig);
CreateExtractTaskReq req = new CreateExtractTaskReq();
// Set the input file path.
ObsObjInfo input = new ObsObjInfo();
input.setBucket("obs-test");
input.setLocation("cn-north-7");
input.setObject("test.flv");
req.setInput(input);
// Set the output file path.
ObsObjInfo output = new ObsObjInfo();
output.setBucket("obs-test");
output.setLocation("cn-north-4");
output.setObject("/test-output/");
output.setFileName("my-test.txt");
req.setOutput(output);
// Send a request.
CommonCreateTaskRsp rsp = mpcClient.createExtractTask(req);
// Print the result.
System.out.println(gson.toJson(rsp));
|
Last Article: Video Parsing
Next Article: Querying Video Parsing Tasks
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.