阿里云OSS转码(java)

当上传到阿里云OSS的视频为MOV格式时,无法在线播放,需要进行转码。文章提供了一段Java代码示例,使用阿里云MTS服务将MOV格式转为MP4,以便于在线播放。代码涉及创建客户端、提交转码作业及配置相关参数。
摘要由CSDN通过智能技术生成

对于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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值