阿里云OSS转码(java)

对于oss上传视频的视频需要在线播放时,如果有的传的是mp4的可以正常播放,但是如果传mov格式的话就会变成下载,这个时候就需要进行转码了。

下面代码可以直接用

首先复制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=源文件名称

workTvNew=转码后的文件名称

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

猜你喜欢

转载自blog.csdn.net/m0_57666466/article/details/131742432