When the videos uploaded by oss need to be played online, if some of them are uploaded in mp4 format, they can be played normally, but if they are uploaded in mov format, they will be downloaded. At this time, transcoding is required.
The following code can be used directly
First copy maven
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>tea-console</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>tea-openapi</artifactId>
<version>0.2.2</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>darabonba-env</artifactId>
<version>0.1.1</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>tea-util</artifactId>
<version>0.2.13</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>mts20140618</artifactId>
<version>3.3.44</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>tea</artifactId>
<version>1.1.14</version>
</dependency>
workTvName=source file name
workTvNew=The name of the transcoded file
public void sample(String workTvName, String workTvNew) throws Exception {
//accessKeyId和accessKeySecret在阿里云后台可以查看
com.aliyun.mts20140618.Client client = Sample.createClient("accessKeyId", "accessKeySecret");
com.aliyun.mts20140618.models.SubmitJobsRequest submitJobsRequest = new com.aliyun.mts20140618.models.SubmitJobsRequest()
.setInput("{\"Bucket\":\"xunli-ymy\",\"Location\":\"oss-cn-beijing\",\"Object\":\"video%2F" + workTvName + "\"}")
.setOutputs("[{\"OutputObject\":\"video%2F" + workTvNew + ".mp4" + "\",\"TemplateId\":\"TemplateId\"}]")
.setPipelineId("pipelineId")
.setOutputLocation("oss-cn-beijing")
.setOutputBucket("Bucket");
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
com.aliyun.mts20140618.models.SubmitJobsResponse resp = client.submitJobsWithOptions(submitJobsRequest, runtime);
com.aliyun.teaconsole.Client.log(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(resp)));
}
public static com.aliyun.mts20140618.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// 您的 AccessKey ID
.setAccessKeyId(accessKeyId)
// 您的 AccessKey Secret
.setAccessKeySecret(accessKeySecret);
// 访问的域名
config.endpoint = "mts.cn-beijing.aliyuncs.com";
return new com.aliyun.mts20140618.Client(config);
}
pipelineId