Alibaba Cloud CLI is a general-purpose command-line tool that is developed based on OpenAPI. You can use Alibaba Cloud CLI to automate management and maintenance in ApsaraVideo Media Processing. This topic describes how to use Alibaba Cloud CLI to call API operations of ApsaraVideo Media Processing.
Before you start
Get familiar with Alibaba Cloud CLI. For more information, see What is Alibaba Cloud CLI?
Install Alibaba Cloud CLI
You must install Alibaba Cloud CLI before you can use Alibaba Cloud CLI. You can install Alibaba Cloud CLI on the Windows, Linux, and macOS operating systems. Select an installation package of Alibaba Cloud CLI based on the operating system of your device. For more information, see the following topics:
You can also use Cloud Shell provided by Alibaba Cloud to debug the commands that you want to run in Alibaba Cloud CLI. For more information about Cloud Shell, see What is Cloud Shell?
Configure Alibaba Cloud CLI
An Alibaba Cloud account has the permissions to manage and access the API operations of all Alibaba Cloud services. If you use an Alibaba Cloud account to call API operations, security risks may arise. We recommend that you call API operations or perform routine O&M as a Resource Access Management (RAM) user.
Before you use Alibaba Cloud CLI, you must configure information such as identity credentials and a region ID in Alibaba Cloud CLI. Alibaba Cloud CLI supports various identity credentials. For more information, see the "Credential types" section of the Configure profiles topic. In this example, AccessKey credentials are used. Perform the following steps to use AccessKey credentials:
Create a RAM user and grant the required permissions to the RAM user. For more information, see Create a RAM user and Grant permissions to a RAM user.
ImportantIn this example, the
AliyunMTSFullAccess
policy is attached to the RAM user. You can also use a custom policy. For more information, see Custom policies for MPS.Create an AccessKey pair for the RAM user and record the
AccessKey ID
andAccessKey secret
for the subsequent configuration of identity credentials. For more information, see Create an AccessKey pair.Obtain and record the ID of an available region for the subsequent configuration of identity credentials. Alibaba Cloud CLI uses the specified region ID to initiate API calls. For more information about the available regions, see Endpoints.
NoteWhen you use Alibaba Cloud CLI, you can specify the
--region
option to run a command in a specific region. If you specify this option, Alibaba Cloud CLI ignores the region information in the default profile and environment variable configurations. For more information, see Command line options for API calls.Use the AccessKey pair of the RAM user to configure AccessKey credentials in the profile named
AkProfile
. For more information, see the "Configuration examples" section of the Configure profiles topic.
Generate a CLI command
Go to the Debugging page of MPS.
In the left-side search box of the Debugging page, search for the API operation that you want to call. On the Parameters tab of the API operation, specify the parameters based on the API reference. Click the CLI Example tab on the right side to view the generated sample command that contains the specified parameters.
Click the icon to start Cloud Shell and debug the command in Cloud Shell.
Click the icon to copy the sample command to the clipboard. Then, paste the sample command into your local shell to run the sample command.
Pay attention to the formats of parameters when you paste the sample command into your local shell for debugging. For more information about the parameter formats of Alibaba Cloud CLI, see Parameter formats.
By default, OpenAPI Explorer adds the
--region
option to the generated sample command. When you run the command in your local shell, Alibaba Cloud CLI ignores the region information in the default profile and environment variable configurations, and preferentially runs the command in the specified region. You can delete or retain the option based on your business requirements.
Call an API operation
Syntax
In Alibaba Cloud CLI, you can use the following syntax to run a command. For more information, see the "Syntax" section of the Generate and run CLI commands topic.
aliyun <command> <subcommand> [options and parameters]
Command options
When you use Alibaba Cloud CLI, you can specify command options to change the default behavior of commands or implement the extended features of commands. Common command options:
--profile <profileName>
: You can use the--profile
option and theprofileName
parameter to specify a profile. After you specify a valid profile, Alibaba Cloud CLI ignores the default profile and environment variable configurations and preferentially uses the profile that you specify to run commands.--help
: You can use the--help
option to obtain the help information about a command. For more information, see Use the help command.
For more information, see Command line options for API calls.
Examples
Example 1: Use the --help
option to obtain a list of ApsaraVideo Media Processing API operations supported by Alibaba Cloud CLI. You can also view the API operations that can be called in List of operations by function.
Run the following command:
aliyun mts --help
View the command output.
Example 2: Use Alibaba Cloud CLI to call the QueryMediaInfoJobList
operation of ApsaraVideo Media Processing to query media information jobs. For more information about the QueryMediaInfoJobList
operation, see QueryMediaInfoJobList.
Run the following command:
aliyun mts QueryMediaInfoJobList --region cn-hangzhou --MediaInfoJobIds '23ca1d184c0e4341e5b665e2a12****'
View the command output.
{ "NonExistMediaInfoJobIds": { "String": [ "11ce1d184c0e4341e5b665e2a12****" ] }, "RequestId": "46A04AA5-B119-41BB-B750-7C5327AC3E7A", "MediaInfoJobList": { "MediaInfoJob": [ { "CreationTime": "2014-01-10T12:00:00Z", "State": "Success", "JobId": "23ca1d184c0e4341e5b665e2a12****", "UserData": "testid-001", "Code": "InvalidParameter.JsonObjectFormatInvalid", "Message": "The parameter "*" does not conform to the JSON Object specification", "PipelineId": "88c6ca184c0e432bbf5b665e2a15****", "Async": true, "Input": { "Object": "example.mp4", "Location": "oss-cn-hangzhou", "Bucket": "example-bucket" }, "MNSMessageResult": { "MessageId": "123", "ErrorMessage": "The parameter \\\"Input\\\" does not conform to the JSON Object specification", "ErrorCode": "InvalidParameter.JsonObjectFormatInvalid" }, "Properties": { "Width": "1280", "Height": "720", "Duration": "17.226000", "Fps": "25", "Bitrate": "1630.045", "FileFormat": "QuickTime/MOV", "Streams": { "VideoStreamList": { "VideoStream": [ { "Sar": "1:1", "Height": "1080", "CodecTagString": "[0][0][0][0]", "NetworkCost": { "PreloadTime": "8", "AvgBitrate": "300.34", "CostBandwidth": "10" }, "Width": "1920", "Index": "1", "Timebase": "1/1000", "AvgFPS": "23.976025", "PixFmt": "yuv420p", "Lang": "eng", "CodecLongName": "H.264/AVC/MPEG-4 AVC/MPEG-4 part 10", "NumFrames": "100", "Rotate": "180", "Bitrate": "30541090", "HasBFrames": "0", "Profile": "High", "StartTime": "0.042000", "Dar": "16:9", "CodecName": "h264", "Duration": "100", "Fps": "25", "CodecTag": "0x0000", "CodecTimeBase": "1001/48000", "Level": "41", "ColorRange": "700", "ColorTransfer": "R255 G83 B170", "ColorPrimaries": "700" } ] }, "AudioStreamList": { "AudioStream": [ { "Timebase": "1/1000", "Index": "1", "SampleFmt": "fltp", "ChannelLayout": "5.1(side)", "Lang": "eng", "Samplerate": "48000", "CodecLongName": "DCA (DTS Coherent Acoustics)", "Channels": "2", "NumFrames": "123", "Bitrate": "1536000", "CodecTagString": "[0][0][0][0]", "StartTime": "0.042000", "CodecName": "acc", "Duration": "123", "CodecTag": "0x0000", "CodecTimeBase": "1/48000" } ] }, "SubtitleStreamList": { "SubtitleStream": [ { "Timebase": "1/1000", "Index": "3", "StartTime": "0.000000", "CodecName": "ass", "Lang": "eng", "CodecLongName": "ASS (Advanced SSA) subtitle", "Duration": "1370.116000", "CodecTag": "0x0000", "CodecTimeBase": "0/1", "CodecTagString": "[0][0][0][0]" } ] } }, "Format": { "StartTime": "0.042000", "NumPrograms": "2", "Size": "3509895", "NumStreams": "1", "FormatLongName": "QuickTime/MOV", "Duration": "17.226000", "Bitrate": "1630.045", "FormatName": "mov" }, "FileSize": "3509895" } } ] } }
NoteIf an error is returned after you call an API operation of ApsaraVideo Media Processing, you must check whether the request parameters and their values are valid based on the returned error code.
You can also perform self-service diagnostics based on the returned request ID or SDK error information on the OpenAPI problem diagnosis page.