Query media information
A media information analysis job performs deep analysis and metadata extraction on an input file and returns the media information of the file. This topic provides examples on how to call ApsaraVideo Media Processing (MPS) SDK for Java V2.0 to submit and query media information analysis jobs.
Prerequisites
An SDK client is initialized. For more information, see Initialize a client.
Submit a media information analysis job
Call the SubmitMediaInfoJob operation to submit a media information analysis job.
-
URL-encode the input object when you submit a job through the SDK. Otherwise, the job fails. For more information, see URL encoding.
-
The media file name must be valid. Otherwise, the file cannot be found and the job fails. For more information, see Parameter details.
-
Record the ID of the submitted job for use in subsequent operations.
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
/**
* <b>description</b> :
* <p>Use your AccessKey ID and AccessKey secret to initialize the client.</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.mts20140618.Client createClient() throws Exception {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured.
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
config.endpoint = "mts.cn-qingdao.aliyuncs.com";
return new com.aliyun.mts20140618.Client(config);
}
public static void main(String[] args_) throws Exception {
java.util.List<String> args = java.util.Arrays.asList(args_);
com.aliyun.mts20140618.Client client = Sample.createClient();
com.aliyun.mts20140618.models.SubmitMediaInfoJobRequest submitMediaInfoJobRequest = new com.aliyun.mts20140618.models.SubmitMediaInfoJobRequest()
// The job input.
.setInput("{\"Bucket\":\"example-bucket\",\"Location\":\"example-location\",\"Object\":\"example%2Fexample.flv\"}")
// The user-defined data.
.setUserData("testid-001")
// The ID of the MPS queue.
.setPipelineId("88c6ca184c0e432bbf5b665e2a15****")
// Specify whether to asynchronously run the job.
.setAsync(true);
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
// Write your own code to display the response of the API operation if necessary.
client.submitMediaInfoJobWithOptions(submitMediaInfoJobRequest, runtime);
} catch (TeaException error) {
// Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only.
// The error message.
System.out.println(error.getMessage());
// The URL of the corresponding error diagnostics page.
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only.
// The error message.
System.out.println(error.getMessage());
// The URL of the corresponding error diagnostics page.
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}
Query media information analysis jobs
Call the QueryMediaInfoJobList operation to query media information analysis jobs.
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
/**
* <b>description</b> :
* <p>Use your AccessKey ID and AccessKey secret to initialize the client.</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.mts20140618.Client createClient() throws Exception {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured.
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
config.endpoint = "mts.cn-qingdao.aliyuncs.com";
return new com.aliyun.mts20140618.Client(config);
}
public static void main(String[] args_) throws Exception {
java.util.List<String> args = java.util.Arrays.asList(args_);
com.aliyun.mts20140618.Client client = Sample.createClient();
com.aliyun.mts20140618.models.QueryMediaInfoJobListRequest queryMediaInfoJobListRequest = new com.aliyun.mts20140618.models.QueryMediaInfoJobListRequest()
// The ID of the media information analysis job.
.setMediaInfoJobIds("23ca1d184c0e4341e5b665e2a12****");
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
// Write your own code to display the response of the API operation if necessary.
client.queryMediaInfoJobListWithOptions(queryMediaInfoJobListRequest, runtime);
} catch (TeaException error) {
// Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only.
// The error message.
System.out.println(error.getMessage());
// The URL of the corresponding error diagnostics page.
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only.
// The error message.
System.out.println(error.getMessage());
// The URL of the corresponding error diagnostics page.
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}