Commit 0e78c657 by 朱亚洁

'feat:[1003010]华为云迁移OBS/MPC'

parent c9b7cb66
## main
main.access.key.id = LTAIx8FODeVLN3bD
main.access.key.secret = eJbZwTzatZq4SMyDiQeh7NzIHkdAaO
## main Ϊak sk
main.access.key.id = CROQ0IJRW2FW5NSERZBR
main.access.key.secret = rAbki4thgWx9iKXendlIH3gvKi8JFHUcVOWwObyS
## OSS
oss.region = oss-cn-hangzhou
oss.endpoint = http://oss-cn-hangzhou.aliyuncs.com
file.bucket = whlg-oss-002
file.original.url = http://whlg-oss-002.oss-cn-hangzhou.aliyuncs.com/
oss.region = cn-east-2
oss.endpoint = obs.cn-east-2.myhuaweicloud.com
file.bucket = whlg-oss-prod-002
file.original.url = http://whlg-oss-001.obs.cn-east-2.myhuaweicloud.com/
input.bucket = whlg-oss-prod-001
oss.region.bj = oss-cn-beijing
oss.endpoint.bj = http://oss-cn-beijing-internal.aliyuncs.com
live.bucket = whlg-oss-livedev
oss.endpoint.bj = http://oss-cn-beijing.aliyuncs.com
live.bucket = whlg-oss-live
live.original.url = http://whlg-oss-livedev.oss-cn-beijing.aliyuncs.com/
by.bucket = byfile-oss-01
by.original.url = http://byfile-oss-01.oss-cn-hangzhou.aliyuncs.com/
## mts
mts.region = cn-hangzhou
mts.endpoint = mts.cn-hangzhou.aliyuncs.com
mts.region = cn-east-2
mts.endpoint = mpc.cn-east-2.myhuaweicloud.com
pipelineid = a63c988125054b07b1d3bd6e10c327de
mp3TemplateId = d60210d2fd5bfcacce66238142437965
mp4TemplateId = 67745f7eb8b7ca9bcf74d96c2364e6c1
mts.projectId = 07455135488025b22fe7c01fdb631c14
mts.ak = 8J56JHJN5P8OLR5ERKFU
mts.sk = xAlBYlowAhwa9c1Wi4JsX7XkZGFlzlWW3CBHdZWJ
mp3TemplateId = 104257
mp4TemplateId = 104256
m3u8TemplateId = 283cd916aa504502b3704f3f5a45addc
mts.region.bj = cn-beijing
......@@ -33,9 +37,13 @@ mp4TemplateId.bj = f4165d42e5eb680c8f919f960f35059c
## cdn
file.domain.name = oss.5rs.me
file.cdn.url = https://oss.5rs.me/
oss.cdn.urls = http://file.chubanyun.me/,http://file.techdc.cn/,https://file.raysyun.com/,http://file.raysgo.com/,https://file.5rs.me/,https://oss.5rs.me/,http://live.chubanyun.me/,https://download.5rs.me/,http://rays-adviser.chubanyun.me/,https://byfile.1wlshu.com/
oss.cdn.urls = http://file.chubanyun.me/,http://file.techdc.cn/,https://file.raysyun.com/,http://file.raysgo.com/,http://oss.raysgo.com/,https://file.5rs.me/,https://oss.5rs.me/,http://live.chubanyun.me/,https://download.5rs.me/,http://rays-adviser.chubanyun.me/,https://byfile.1wlshu.com/,https://byfile.raysgo.com/
rays.cdn.urls = https://file.5rs.me/,https://oss.5rs.me/
file.cdn.url.download = https://download.5rs.me/
file.cdn.url.live = http://live.chubanyun.me/
file.cdn.url.by = https://byfile.1wlshu.com/
\ No newline at end of file
file.cdn.url.by = https://byfile.raysgo.com/
huawei.access.key = CROQ0IJRW2FW5NSERZBR
huawei.secret.key = rAbki4thgWx9iKXendlIH3gvKi8JFHUcVOWwObyS
## main
main.access.key.id = LTAIx8FODeVLN3bD
main.access.key.secret = eJbZwTzatZq4SMyDiQeh7NzIHkdAaO
## main Ϊak sk
main.access.key.id = CROQ0IJRW2FW5NSERZBR
main.access.key.secret = rAbki4thgWx9iKXendlIH3gvKi8JFHUcVOWwObyS
## OSS
oss.region = oss-cn-hangzhou
oss.endpoint = http://oss-cn-hangzhou.aliyuncs.com
file.bucket = whlg-oss-002
file.original.url = http://whlg-oss-002.oss-cn-hangzhou.aliyuncs.com/
oss.region = cn-east-2
oss.endpoint = obs.cn-east-2.myhuaweicloud.com
file.bucket = whlg-oss-test-002
file.original.url = http://whlg-oss-001.obs.cn-east-2.myhuaweicloud.com/
input.bucket = whlg-oss-test-001
oss.region.bj = oss-cn-beijing
oss.endpoint.bj = http://oss-cn-beijing.aliyuncs.com
live.bucket = whlg-oss-livedev
live.bucket = whlg-oss-live
live.original.url = http://whlg-oss-livedev.oss-cn-beijing.aliyuncs.com/
by.bucket = byfile-oss-01
by.original.url = http://byfile-oss-01.oss-cn-hangzhou.aliyuncs.com/
## mts
mts.region = cn-hangzhou
mts.endpoint = mts.cn-hangzhou.aliyuncs.com
mts.region = cn-east-2
mts.endpoint = mpc.cn-east-2.myhuaweicloud.com
pipelineid = a63c988125054b07b1d3bd6e10c327de
mp3TemplateId = d60210d2fd5bfcacce66238142437965
mp4TemplateId = 67745f7eb8b7ca9bcf74d96c2364e6c1
mts.projectId = 07455135488025b22fe7c01fdb631c14
mts.ak = 8J56JHJN5P8OLR5ERKFU
mts.sk = xAlBYlowAhwa9c1Wi4JsX7XkZGFlzlWW3CBHdZWJ
mp3TemplateId = 104257
mp4TemplateId = 104256
m3u8TemplateId = 283cd916aa504502b3704f3f5a45addc
mts.region.bj = cn-beijing
......@@ -32,10 +36,14 @@ mp4TemplateId.bj = f4165d42e5eb680c8f919f960f35059c
## cdn
file.domain.name = oss.5rs.me
file.cdn.url = https://oss.5rs.me/
oss.cdn.urls = http://file.chubanyun.me/,http://file.techdc.cn/,https://file.raysyun.com/,http://file.raysgo.com/,http://oss.raysgo.com/,https://file.5rs.me/,https://oss.5rs.me/,http://live.chubanyun.me/,https://download.5rs.me/,http://rays-adviser.chubanyun.me/,https://byfile.1wlshu.com/,https://byfile.raysgo.com/
file.cdn.url = https://oss.raysgo.com/
oss.cdn.urls = http://file.chubanyun.me/,http://file.techdc.cn/,https://file.raysyun.com/,http://file.raysgo.com/,http://oss.raysgo.com/,https://file.5rs.me/,https://oss.5rs.me/,http://live.chubanyun.me/,https://download.5rs.me/,http://rays-adviser.chubanyun.me/,https://byfile.1wlshu.com/,https://byfile.raysgo.com/,https://oss.raysyun.com/
rays.cdn.urls = https://file.5rs.me/,https://oss.5rs.me/
file.cdn.url.download = https://download.5rs.me/
file.cdn.url.live = http://live.chubanyun.me/
file.cdn.url.by = https://byfile.raysgo.com/
huawei.access.key = CROQ0IJRW2FW5NSERZBR
huawei.secret.key = rAbki4thgWx9iKXendlIH3gvKi8JFHUcVOWwObyS
## main
main.access.key.id = LTAIx8FODeVLN3bD
main.access.key.secret = eJbZwTzatZq4SMyDiQeh7NzIHkdAaO
## main Ϊak sk
main.access.key.id = CROQ0IJRW2FW5NSERZBR
main.access.key.secret = rAbki4thgWx9iKXendlIH3gvKi8JFHUcVOWwObyS
## OSS
oss.region = oss-cn-hangzhou
oss.endpoint = http://oss-cn-hangzhou.aliyuncs.com
file.bucket = whlg-oss-002
file.original.url = http://whlg-oss-002.oss-cn-hangzhou.aliyuncs.com/
oss.region = cn-east-2
oss.endpoint = obs.cn-east-2.myhuaweicloud.com
file.bucket = whlg-oss-uat-002
file.original.url = http://whlg-oss-001.obs.cn-east-2.myhuaweicloud.com/
input.bucket = whlg-oss-uat-001
oss.region.bj = oss-cn-beijing
oss.endpoint.bj = http://oss-cn-beijing.aliyuncs.com
live.bucket = whlg-oss-livedev
live.bucket = whlg-oss-live
live.original.url = http://whlg-oss-livedev.oss-cn-beijing.aliyuncs.com/
by.bucket = byfile-oss-01
by.original.url = http://byfile-oss-01.oss-cn-hangzhou.aliyuncs.com/
## mts
mts.region = cn-hangzhou
mts.endpoint = mts.cn-hangzhou.aliyuncs.com
mts.region = cn-east-2
mts.endpoint = mpc.cn-east-2.myhuaweicloud.com
pipelineid = a63c988125054b07b1d3bd6e10c327de
mp3TemplateId = d60210d2fd5bfcacce66238142437965
mp4TemplateId = 67745f7eb8b7ca9bcf74d96c2364e6c1
mts.projectId = 07455135488025b22fe7c01fdb631c14
mts.ak = 8J56JHJN5P8OLR5ERKFU
mts.sk = xAlBYlowAhwa9c1Wi4JsX7XkZGFlzlWW3CBHdZWJ
mp3TemplateId = 104257
mp4TemplateId = 104256
m3u8TemplateId = 283cd916aa504502b3704f3f5a45addc
mts.region.bj = cn-beijing
......@@ -32,10 +36,14 @@ mp4TemplateId.bj = f4165d42e5eb680c8f919f960f35059c
## cdn
file.domain.name = oss.5rs.me
file.cdn.url = https://oss.5rs.me/
oss.cdn.urls = http://file.chubanyun.me/,http://file.techdc.cn/,https://file.raysyun.com/,http://file.raysgo.com/,https://file.5rs.me/,https://oss.5rs.me/,http://live.chubanyun.me/,https://download.5rs.me/,http://rays-adviser.chubanyun.me/,https://byfile.1wlshu.com
file.cdn.url = https://oss.raysyun.com/
oss.cdn.urls = http://file.chubanyun.me/,http://file.techdc.cn/,https://file.raysyun.com/,http://file.raysgo.com/,http://oss.raysgo.com/,https://file.5rs.me/,https://oss.5rs.me/,http://live.chubanyun.me/,https://download.5rs.me/,http://rays-adviser.chubanyun.me/,https://byfile.1wlshu.com/,https://byfile.raysgo.com/,https://oss.raysyun.com/
rays.cdn.urls = https://file.5rs.me/,https://oss.5rs.me/
file.cdn.url.download = https://download.5rs.me/
file.cdn.url.live = http://live.chubanyun.me/
file.cdn.url.by = https://byfile.1wlshu.com
\ No newline at end of file
file.cdn.url.by = https://byfile.raysgo.com/
huawei.access.key = CROQ0IJRW2FW5NSERZBR
huawei.secret.key = rAbki4thgWx9iKXendlIH3gvKi8JFHUcVOWwObyS
......@@ -155,10 +155,11 @@
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<!-- <dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<version>3.6.0</version>
</dependency>-->
<dependency>
<groupId>commons-codec</groupId>
......@@ -292,6 +293,20 @@
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-mts</artifactId>
</dependency>
<!--华为云媒体转码SDK包 -->
<dependency>
<groupId>com.huawei.mpc</groupId>
<artifactId>cloud-java-sdk-mpc</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
</dependency>
<dependency>
<groupId>com.huaweicloud</groupId>
<artifactId>esdk-obs-java</artifactId>
<version>3.19.7</version>
</dependency>
<!-- Jackson Begin -->
<dependency>
......
......@@ -18,7 +18,7 @@ import com.pcloud.common.utils.string.StringUtil;
public class AliyunConstant {
/**
* 主账号keyId
* 主账号keyId,华为云ak
*/
public static String MAIN_ACCESS_KEY_ID;
......@@ -28,7 +28,7 @@ public class AliyunConstant {
}
/**
* 主账号keySecret
* 主账号keySecret 华为云sk
*/
public static String MAIN_ACCESS_KEY_SECRET;
......@@ -52,7 +52,7 @@ public class AliyunConstant {
*/
public static String MTS_REGION_BJ;
@Value("${mts.region.bj}")
@Value("cn-north-4")
public void setMtsRegionBj(String mtsRegionBj) {
MTS_REGION_BJ = mtsRegionBj;
}
......@@ -72,7 +72,7 @@ public class AliyunConstant {
*/
public static String OSS_REGION_BJ;
@Value("${oss.region.bj}")
@Value("cn-north-4")
public void setOssRegionBj(String ossRegionBj) {
OSS_REGION_BJ = ossRegionBj;
}
......@@ -112,7 +112,7 @@ public class AliyunConstant {
*/
public static String MTS_ENDPOINT_BJ;
@Value("${mts.endpoint.bj}")
@Value("live.cn-north-4.myhuaweicloud.com")
public void setMtsEndpointBj(String mtsEndpointBj) {
MTS_ENDPOINT_BJ = mtsEndpointBj;
}
......@@ -138,6 +138,16 @@ public class AliyunConstant {
}
/**
* 设置用户项目编号ProjectId
*/
public static String PROJECT_ID;
@Value("${mts.projectId}")
public void setProjectId(String projectId) {
PROJECT_ID = projectId;
}
/**
* 转MP3模板ID
*/
public static String MP3_TEMPLATE_ID;
......@@ -182,7 +192,7 @@ public class AliyunConstant {
*/
public static String MP4_TEMPLATE_ID_BJ;
@Value("${mp4TemplateId}")
@Value("125799")
public void setMp4TemplateIdBj(String mp4TemplateIdBj) {
MP4_TEMPLATE_ID_BJ = mp4TemplateIdBj;
}
......@@ -190,7 +200,12 @@ public class AliyunConstant {
/**
* OSS存储输入地址
*/
public static final String INPUT_BUCKET = "whlg-oss-001";
public static String INPUT_BUCKET;
@Value("${input.bucket}")
public void setInputBucket(String imputBucket) {
INPUT_BUCKET = imputBucket;
}
/**
* OSS存储输出地址
......@@ -220,22 +235,27 @@ public class AliyunConstant {
/**
* 版元存储输出地址
*/
public static final String BY_BUCKET = "byfile-oss-01";
public static String BY_BUCKET;
@Value("${by.bucket}")
public void setByBucket(String byBucket){
BY_BUCKET = byBucket;
}
/**
* 开发存储输出地址
*/
public static final String DEV_BUCKET = "whlg-oss-dev";
public static final String DEV_BUCKET = "whlg-oss-dev-002";
/**
* 测试存储输出地址
*/
public static final String TEST_BUCKET = "whlg-oss-test";
public static final String TEST_BUCKET = "whlg-oss-test-002";
/**
* UAT存储输出地址
*/
public static final String UAT_BUCKET = "whlg-oss-uat";
public static final String UAT_BUCKET = "whlg-oss-uat-002";
/**
* OSS 鉴权KEY(仅限下载用)
......@@ -342,11 +362,55 @@ public class AliyunConstant {
BY_ORIGINAL_URL = byOriginalUrl;
}
/**
* 华为云转码ak
*/
public static String MtsAK;
@Value("${mts.ak}")
public void setMtsAK(String mtsAK) {
MtsAK = mtsAK;
}
/**
* 华为云转码sk
*/
public static String MtsSK;
@Value("${mts.sk}")
public void setMtsSK(String mtsSK) {
MtsSK = mtsSK;
}
/**
* 视频水印模板ID-左下角
*/
public static final String WATERMARK_BOTTOM_LEFT = "cb8fe5517c5a44c19284cdf130dd223d";
/**
* 华为云Access Key
*/
public static String ACCESS_KEY;
@Value("${huawei.access.key}")
public void setAccessKey(String accessKey) {
ACCESS_KEY = accessKey;
}
/**
* 华为云 Secret Key
*/
public static String SECRET_KEY;
@Value("${huawei.secret.key}")
public static void setSecretKey(String secretKey) {
SECRET_KEY = secretKey;
}
/**
* 根据域名获取bucket名称
*
......@@ -357,18 +421,23 @@ public class AliyunConstant {
if (StringUtil.isEmpty(fileUrl)) {
return null;
}
if (fileUrl.contains("transcode")){
return FILE_BUCKET;
}
String domainName = FileUtils.getDomainName(fileUrl);
if (domainName == null) {
if (StringUtil.isEmpty(domainName)) {
return INPUT_BUCKET;
}
//不根据域名判断
switch (domainName) {
case "file.chubanyun.me":
return DEV_BUCKET;
case "file.techdc.cn":
case "file.raysgo.com":
return TEST_BUCKET;
case "file.raysyun.com":
return UAT_BUCKET;
// case "file.chubanyun.me":
// return DEV_BUCKET;
// case "file.techdc.cn":
// case "file.raysgo.com":
// case "oss.raysgo.com":
// return TEST_BUCKET;
// case "file.raysyun.com":
// return UAT_BUCKET;
case "live.chubanyun.me":
return LIVE_BUCKET;
case "rays-adviser.chubanyun.me":
......@@ -376,12 +445,12 @@ public class AliyunConstant {
case "byfile.1wlshu.com":
case "byfile.raysgo.com":
return BY_BUCKET;
case "file.5rs.me":
case "oss.5rs.me":
case "download.5rs.me":
return FILE_BUCKET;
// case "file.5rs.me":
// case "oss.5rs.me":
// case "download.5rs.me":
// return FILE_BUCKET;
default:
return INPUT_BUCKET;
return FILE_BUCKET;
}
}
......@@ -395,11 +464,12 @@ public class AliyunConstant {
if (StringUtil.isEmpty(bucketName)) {
return null;
}
if (LIVE_BUCKET.equals(bucketName))
if (LIVE_BUCKET.equals(bucketName)) {
return OSS_REGION_BJ;
else
} else {
return OSS_REGION;
}
}
/**
* 获取媒体转码地域名称
......@@ -411,11 +481,12 @@ public class AliyunConstant {
if (StringUtil.isEmpty(bucketName)) {
return null;
}
if (LIVE_BUCKET.equals(bucketName))
if (LIVE_BUCKET.equals(bucketName)) {
return MTS_REGION_BJ;
else
} else {
return MTS_REGION;
}
}
/**
* 获取媒体转码EndPoint
......@@ -427,11 +498,12 @@ public class AliyunConstant {
if (StringUtil.isEmpty(bucketName)) {
return null;
}
if (LIVE_BUCKET.equals(bucketName))
if (LIVE_BUCKET.equals(bucketName)) {
return MTS_ENDPOINT_BJ;
else
} else {
return MTS_ENDPOINT;
}
}
/**
* 获取OSS输出bucket
......@@ -443,13 +515,14 @@ public class AliyunConstant {
if (StringUtil.isEmpty(bucketName)) {
return null;
}
if (LIVE_BUCKET.equals(bucketName))
if (LIVE_BUCKET.equals(bucketName)) {
return LIVE_BUCKET;
else if (BY_BUCKET.equals(bucketName))
} else if (BY_BUCKET.equals(bucketName)) {
return BY_BUCKET;
else
} else {
return FILE_BUCKET;
}
}
/**
* 获取转码管道ID
......@@ -461,11 +534,12 @@ public class AliyunConstant {
if (StringUtil.isEmpty(bucketName)) {
return null;
}
if (LIVE_BUCKET.equals(bucketName))
if (LIVE_BUCKET.equals(bucketName)) {
return PIPELINEID_BJ;
else
} else {
return PIPELINEID;
}
}
/**
* 获取MP3转码模板ID
......@@ -477,11 +551,12 @@ public class AliyunConstant {
if (StringUtil.isEmpty(bucketName)) {
return null;
}
if (LIVE_BUCKET.equals(bucketName))
if (LIVE_BUCKET.equals(bucketName)) {
return MP3_TEMPLATE_ID_BJ;
else
} else {
return MP3_TEMPLATE_ID;
}
}
/**
* 获取MP4转码模板ID
......@@ -493,11 +568,12 @@ public class AliyunConstant {
if (StringUtil.isEmpty(bucketName)) {
return null;
}
if (LIVE_BUCKET.equals(bucketName))
if (LIVE_BUCKET.equals(bucketName)) {
return MP4_TEMPLATE_ID_BJ;
else
} else {
return MP4_TEMPLATE_ID;
}
}
/**
* 获取视频转码模板ID
......@@ -509,13 +585,14 @@ public class AliyunConstant {
if (StringUtil.isEmpty(outFileType)) {
return null;
}
if (LIVE_BUCKET.equals(bucketName))
if (LIVE_BUCKET.equals(bucketName)) {
return MP4_TEMPLATE_ID_BJ;
else if ("m3u8".equalsIgnoreCase(outFileType))
} else if ("m3u8".equalsIgnoreCase(outFileType)) {
return M3U8_TEMPLATE_ID;
else
} else {
return MP4_TEMPLATE_ID;
}
}
/**
* 获取文件CDN地址
......@@ -527,13 +604,14 @@ public class AliyunConstant {
if (StringUtil.isEmpty(bucketName)) {
return null;
}
if (LIVE_BUCKET.equals(bucketName))
if (LIVE_BUCKET.equals(bucketName)) {
return FILE_CDN_URL_LIVE;
else if (BY_BUCKET.equals(bucketName))
} else if (BY_BUCKET.equals(bucketName)) {
return FILE_CDN_URL_BY;
else
} else {
return FILE_CDN_URL;
}
}
/**
* 获取OSS原始地址
......@@ -545,13 +623,14 @@ public class AliyunConstant {
if (StringUtil.isEmpty(bucketName)) {
return null;
}
if (LIVE_BUCKET.equals(bucketName))
if (LIVE_BUCKET.equals(bucketName)) {
return LIVE_ORIGINAL_URL;
else if (BY_BUCKET.equals(bucketName))
} else if (BY_BUCKET.equals(bucketName)) {
return BY_ORIGINAL_URL;
else
} else {
return FILE_ORIGINAL_URL;
}
}
/**
* 获取OSS EndPoint地址
......@@ -563,10 +642,11 @@ public class AliyunConstant {
if (StringUtil.isEmpty(bucketName)) {
return null;
}
if (LIVE_BUCKET.equals(bucketName))
if (LIVE_BUCKET.equals(bucketName)) {
return OSS_ENDPOINT_BJ;
else
} else {
return OSS_ENDPOINT;
}
}
}
package com.pcloud.common.utils.aliyun;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.List;
import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.common.utils.BinaryUtil;
import com.aliyun.oss.common.utils.IOUtils;
import com.aliyun.oss.model.GenericResult;
import com.aliyun.oss.model.GetObjectRequest;
import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.ObjectMetadata;
import com.aliyun.oss.model.ProcessObjectRequest;
import com.aliyun.oss.model.UploadFileRequest;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.mts.model.v20140618.QueryJobListRequest;
import com.aliyuncs.mts.model.v20140618.QueryJobListResponse;
import com.aliyuncs.mts.model.v20140618.QueryJobListResponse.Job;
import com.aliyuncs.mts.model.v20140618.QueryJobListResponse.Job.Output.Properties.Streams.AudioStream;
import com.aliyuncs.mts.model.v20140618.QueryJobListResponse.Job.Output.Properties.Streams.VideoStream;
import com.aliyuncs.mts.model.v20140618.SubmitJobsRequest;
import com.aliyuncs.mts.model.v20140618.SubmitJobsResponse;
import com.aliyuncs.mts.model.v20140618.SubmitMediaInfoJobRequest;
import com.aliyuncs.mts.model.v20140618.SubmitMediaInfoJobResponse;
import com.aliyuncs.mts.model.v20140618.SubmitMediaInfoJobResponse.MediaInfoJob.Properties.Format;
import com.aliyuncs.mts.model.v20140618.SubmitSnapshotJobRequest;
import com.aliyuncs.mts.model.v20140618.SubmitSnapshotJobResponse.SnapshotJob;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import com.huawei.mpc.client.MpcClient;
import com.huawei.mpc.client.MpcConfig;
import com.huawei.mpc.model.ObsObjInfo;
import com.huawei.mpc.model.thumbnail.CreateThumbnailRequest;
import com.huawei.mpc.model.thumbnail.CreateThumbnailResponse;
import com.huawei.mpc.model.thumbnail.QueryThumbTaskRequest;
import com.huawei.mpc.model.thumbnail.QueryThumbTaskResponse;
import com.huawei.mpc.model.transcoding.CreateTranscodingRequest;
import com.huawei.mpc.model.transcoding.CreateTranscodingResponse;
import com.huawei.mpc.model.transcoding.QueryTranscodingRequest;
import com.huawei.mpc.model.transcoding.QueryTranscodingResponse;
import com.huawei.mpc.model.transcoding.TextWatermark;
import com.obs.services.ObsClient;
import com.obs.services.internal.utils.ServiceUtils;
import com.obs.services.model.DownloadFileRequest;
import com.obs.services.model.DownloadFileResult;
import com.obs.services.model.GetObjectRequest;
import com.obs.services.model.ObjectMetadata;
import com.obs.services.model.ObsObject;
import com.obs.services.model.TemporarySignatureRequest;
import com.obs.services.model.TemporarySignatureResponse;
import com.obs.services.model.UploadFileRequest;
import com.pcloud.common.constant.AliyunConstant;
import com.pcloud.common.constant.FilePathConstant;
import com.pcloud.common.constant.UrlConstant;
......@@ -55,7 +39,6 @@ import com.pcloud.common.exceptions.FileException;
import com.pcloud.common.utils.DateUtils;
import com.pcloud.common.utils.FileUtils;
import com.pcloud.common.utils.ImageUtils;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.LocalDateUtils;
import com.pcloud.common.utils.UUIDUitl;
import com.pcloud.common.utils.encode.ZSEncode;
......@@ -64,10 +47,30 @@ import com.pcloud.common.utils.rsa.MD5;
import com.pcloud.common.utils.string.StringTools;
import com.pcloud.common.utils.string.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.hutool.core.codec.Base64;
import lombok.SneakyThrows;
/**
* @描述:
* @作者:songx
* @创建时间:2017年6月26日,下午12:03:44 @版本:1.0
* @作者:zyj
* @创建时间:2020年6月2日
*/
public class OssUtils {
......@@ -79,12 +82,12 @@ public class OssUtils {
/**
* ACS客户端,华东地区
*/
private static DefaultAcsClient acsClient;
private static MpcClient acsClient;
/**
* ACS客户端,华北地区
*/
private static DefaultAcsClient acsClientBj;
private static MpcClient acsClientBj;
/**
* 获取ACS客户端
......@@ -92,25 +95,29 @@ public class OssUtils {
* @param bucketName
* @return
*/
private static DefaultAcsClient initAcsClient(String bucketName) {
private static MpcClient initAcsClient(String bucketName) {
try {
String mtsRegion = AliyunConstant.getMtsRegion(bucketName);
DefaultProfile.addEndpoint(mtsRegion, mtsRegion, "Mts", AliyunConstant.getMtsEndPoint(bucketName));
return new DefaultAcsClient(DefaultProfile.getProfile(mtsRegion, AliyunConstant.MAIN_ACCESS_KEY_ID,
AliyunConstant.MAIN_ACCESS_KEY_SECRET));
MpcConfig mpcConfig = new MpcConfig();
mpcConfig.setEndPoint(AliyunConstant.getMtsEndPoint(bucketName));// 设置转码节点地址
mpcConfig.setProjectId(AliyunConstant.PROJECT_ID);// 设置用户项目编号ProjectId
mpcConfig.setSk(AliyunConstant.MtsSK);// 设置sk
mpcConfig.setAk(AliyunConstant.MtsAK);// 设置ak
MpcClient mpcClient = new MpcClient(mpcConfig);
return mpcClient;
} catch (Exception e) {
LOGGER.error("【aliOSS】初始化媒体转码ACS客户端失败:" + e.getMessage(), e);
throw new FileException(FileException.FILE_READ_FAILURE, "初始化Acs客户端失败");
}
}
/**
* 获取ACS客户端
*
* @param bucketName
* @return
*/
private static DefaultAcsClient getAcsClient(String bucketName) {
private static MpcClient getAcsClient(String bucketName) {
if (AliyunConstant.LIVE_BUCKET.equals(bucketName)) {
if (acsClientBj == null) {
acsClientBj = initAcsClient(bucketName);
......@@ -215,12 +222,12 @@ public class OssUtils {
* @return
* @throws FileException
*/
private static OSSFileDO uploadFileStream2OSS(InputStream is, String bucketName, String objectKey)
throws FileException {
@SneakyThrows
private static OSSFileDO uploadFileStream2OSS(InputStream is, String bucketName, String objectKey) {
if (is == null) {
throw new FileException(FileException.FILE_CONTENT_NOT_EXIST, "InputStream is null!");
}
OSSClient client = getOSSClient(bucketName);
ObsClient client = getOSSClient(bucketName);
OSSFileDO ossFileDO = null;
try {
client.putObject(bucketName, objectKey, is);
......@@ -231,7 +238,11 @@ public class OssUtils {
LOGGER.error("【aliOSS】上传文件失败:" + e.getMessage(), e);
throw new FileException(FileException.FILE_UPLOAD_FAILURE, "上传文件失败");
} finally {
client.shutdown();
client.close();
}
//oss%2Ftranscode%2Faudio%2Fmp3%2Ftest_20200529150529182.mp3
if (!StringUtil.isEmpty(ossFileDO.getObject()) && ossFileDO.getObject().contains("%2F")){
ossFileDO.setObject(ossFileDO.getObject().replace("%2F","/"));
}
return ossFileDO;
}
......@@ -244,12 +255,13 @@ public class OssUtils {
* @param objectKey
* @return
*/
@SneakyThrows
private static OSSFileDO uploadPointFile2OSS(String filePath, String bucketName, String objectKey)
throws FileException {
if (filePath == null) {
throw new RuntimeException("filePath is null!");
}
OSSClient ossClient = getOSSClient(bucketName);
ObsClient ossClient = getOSSClient(bucketName);
OSSFileDO ossFileDO = null;
try {
// 设置断点续传请求
......@@ -270,13 +282,55 @@ public class OssUtils {
LOGGER.error("【aliOSS】上传文件失败:" + e.getMessage(), e);
throw new FileException(FileException.FILE_UPLOAD_FAILURE, "上传文件失败");
} finally {
ossClient.shutdown();
ossClient.close();
}
//oss%2Ftranscode%2Faudio%2Fmp3%2Ftest_20200529150529182.mp3
if (!StringUtil.isEmpty(ossFileDO.getObject()) && ossFileDO.getObject().contains("%2F")){
ossFileDO.setObject(ossFileDO.getObject().replace("%2F","/"));
}
return ossFileDO;
}
/**
* 提交MP4转码作业
* 断点续传上传文件到aliOSS
*
* @param filePath
* @param bucketName
* @param objectKey
* @return
*/
@SneakyThrows
private static DownloadFileResult downloadPointFile2OSS(String filePath, String outFilePath, String bucketName, String objectKey)
throws FileException {
if (filePath == null) {
throw new RuntimeException("filePath is null!");
}
ObsClient ossClient = getOSSClient(bucketName);
DownloadFileResult result = null;
try {
// 创建ObsClient实例
ObsClient obsClient = getOSSClient(bucketName);
DownloadFileRequest request = new DownloadFileRequest(bucketName, objectKey);
// 设置下载对象的本地文件路径
request.setDownloadFile(outFilePath);
// 设置分段下载时的最大并发数
request.setTaskNum(5);
// 设置分段大小为10MB
request.setPartSize(10 * 1024 * 1024);
// 开启断点续传模式
request.setEnableCheckpoint(true);
// 进行断点续传下载
result = obsClient.downloadFile(request);
} catch (Throwable e) {
LOGGER.error("【aliOSS】下载文件失败:" + e.getMessage(), e);
throw new FileException(FileException.FILE_UPLOAD_FAILURE, "上传文件失败");
} finally {
ossClient.close();
}
return result;
}
/**
* 提交MP4转码作业 new
*
* @param fileName 源文件的名称不带后缀,可为null
* @param filePath 源文件本地路径
......@@ -289,7 +343,7 @@ public class OssUtils {
}
/**
* 提交MP4转码作业
* 提交MP4转码作业 new
*
* @param fileName
* @param filePath
......@@ -302,12 +356,12 @@ public class OssUtils {
String inObjectKey = getInObjectKey(AliyunEnum.TRANSCODE, fileName, fileType);
String inputBucketName = AliyunConstant.INPUT_BUCKET;
OSSFileDO ossFileDO = uploadPointFile2OSS(filePath, inputBucketName, inObjectKey);
String outObjectKey = getOutObjectKey(AliyunEnum.TRANSCODE, null, "mp4");
String outObjectKey = getTranscodeOutObjectKey(AliyunEnum.TRANSCODE, "mp4");
return transcodeJob(ossFileDO, AliyunConstant.getMp4TemplateId(inputBucketName), outObjectKey, null, null);
}
/**
* 提交MP4转码作业,文件流方式
* 提交MP4转码作业,文件流方式 new
*
* @param buff 源文件流
* @param fileName 源文件的名称不带后缀,可为null
......@@ -319,14 +373,14 @@ public class OssUtils {
String inObjectKey = getInObjectKey(AliyunEnum.TRANSCODE, fileName, fileType);
String inputBucketName = AliyunConstant.INPUT_BUCKET;
OSSFileDO inputFile = uploadFileStream2OSS(new ByteArrayInputStream(buff), inputBucketName, inObjectKey);
String outObjectKey = getOutObjectKey(AliyunEnum.TRANSCODE, null, "mp4");
String outObjectKey = getTranscodeOutObjectKey(AliyunEnum.TRANSCODE, "mp4");
String[] result = transcodeJob(inputFile, AliyunConstant.getMp4TemplateId(inputBucketName), outObjectKey, null,
null);
return result[0];
}
/**
* 提交MP3转码作业
* 提交MP3转码作业 new
*
* @param fileName 源文件的名称不带后缀,可为null
* @param filePath 源文件本地路径
......@@ -339,7 +393,7 @@ public class OssUtils {
}
/**
* 提交MP3转码作业
* 提交MP3转码作业 new
*
* @param fileName
* @param filePath
......@@ -352,12 +406,12 @@ public class OssUtils {
String inObjectKey = getInObjectKey(AliyunEnum.TRANSCODE, fileName, fileType);
String inputBucketName = AliyunConstant.INPUT_BUCKET;
OSSFileDO ossFileDO = uploadPointFile2OSS(filePath, AliyunConstant.INPUT_BUCKET, inObjectKey);
String outObjectKey = getOutObjectKey(AliyunEnum.TRANSCODE, null, "mp3");
String outObjectKey = getTranscodeOutObjectKey(AliyunEnum.TRANSCODE, "mp3");
return transcodeJob(ossFileDO, AliyunConstant.getMp3TemplateId(inputBucketName), outObjectKey, null, null);
}
/**
* 提交MP3转码作业,文件流方式 <br/> 使用byte[]方式上传,文件流上传容易导致读取长度0,造成转码失败
* 提交MP3转码作业,文件流方式 <br/> 使用byte[]方式上传,文件流上传容易导致读取长度0,造成转码失败 new
*
* @param is 源文件流
* @param fileName 源文件的名称不带后缀,可为null
......@@ -369,14 +423,14 @@ public class OssUtils {
String inObjectKey = getInObjectKey(AliyunEnum.TRANSCODE, fileName, fileType);
String inputBucketName = AliyunConstant.INPUT_BUCKET;
OSSFileDO inputFile = uploadFileStream2OSS(is, inputBucketName, inObjectKey);
String outObjectKey = getOutObjectKey(AliyunEnum.TRANSCODE, null, "mp3");
String outObjectKey = getTranscodeOutObjectKey(AliyunEnum.TRANSCODE, "mp3");
String[] result = transcodeJob(inputFile, AliyunConstant.getMp3TemplateId(inputBucketName), outObjectKey, null,
null);
return result[0];
}
/**
* 提交MP3转码作业
* 提交MP3转码作业 new
*
* @param buff 文件
* @param fileName 源文件的名称不带后缀,可为null
......@@ -389,14 +443,14 @@ public class OssUtils {
String inObjectKey = getInObjectKey(AliyunEnum.TRANSCODE, fileName, fileType);
String inputBucketName = AliyunConstant.INPUT_BUCKET;
OSSFileDO inputFile = uploadFileStream2OSS(new ByteArrayInputStream(buff), inputBucketName, inObjectKey);
String outObjectKey = getOutObjectKey(AliyunEnum.TRANSCODE, null, "mp3");
String outObjectKey = getTranscodeOutObjectKey(AliyunEnum.TRANSCODE, "mp3");
String[] result = transcodeJob(inputFile, AliyunConstant.getMp3TemplateId(inputBucketName), outObjectKey, null,
null);
return result[0];
}
/**
* 转码作业,同步的方式
* 转码作业,同步的方式 new
*
* @param fileUrl
* @return
......@@ -409,7 +463,7 @@ public class OssUtils {
}
/**
* 转码作业
* 转码作业 new
*
* @param fileName 文件名称
* @param filePath 文件地址
......@@ -422,7 +476,7 @@ public class OssUtils {
}
/**
* 转码作业
* 转码作业 new
*
* @param fileName
* @param fileUrl 文件地址
......@@ -441,7 +495,7 @@ public class OssUtils {
}
/**
* 已经存在于OSS中的文件转码
* 已经存在于OSS中的文件转码 new
*
* @param fileUrl
* @param fileName
......@@ -459,13 +513,13 @@ public class OssUtils {
OSSFileDO ossFileDO = new OSSFileDO(AliyunConstant.getOssRegion(inputBucketName), inputBucketName, inObjectKey);
if (FileUtils.VIDEO.equals(FileUtils.getGatherName(fileType))) {
outFileType = StringUtil.isEmpty(outFileType) ? "mp4" : outFileType;
String outObjectKey = getOutObjectKey(AliyunEnum.TRANSCODE, fileName, outFileType);
String outObjectKey = getTranscodeOutObjectKey(AliyunEnum.TRANSCODE, outFileType);
// 组装水印参数
JSONArray waterMarkConfigArray = getWaterMarkConfig(waterMarkContent);
CreateTranscodingRequest.Watermark[] waterMarkConfigArray = getWaterMarkConfig(waterMarkContent);
result = transcodeJob(ossFileDO, AliyunConstant.getVideoTemplateId(inputBucketName, outFileType),
outObjectKey, waterMarkConfigArray, null);
} else if (FileUtils.AUDIO.equals(FileUtils.getGatherName(fileType))) {
String outObjectKey = getOutObjectKey(AliyunEnum.TRANSCODE, fileName, "mp3");
String outObjectKey = getTranscodeOutObjectKey(AliyunEnum.TRANSCODE, "mp3");
result = transcodeJob(ossFileDO, AliyunConstant.getMp3TemplateId(inputBucketName), outObjectKey, null,
null);
}
......@@ -473,7 +527,7 @@ public class OssUtils {
}
/**
* 不存在于OSS中的文件转码,要先上传
* 不存在于OSS中的文件转码,要先上传 new
*
* @param fileUrl
* @param fileName
......@@ -512,7 +566,7 @@ public class OssUtils {
* @return
* @throws FileException
*/
public static String submitMergeJob(String fileUrl, List<String> mergeUrls) throws FileException {
/* public static String submitMergeJob(String fileUrl, List<String> mergeUrls) throws FileException {
LOGGER.info("【aliOSS】提交合并作业.<START>.[fileUrl]=" + fileUrl + ",[mergeUrls]=" + mergeUrls);
String fileType = FileUtils.getFileType(fileUrl);
if (ListUtils.isEmpty(mergeUrls)) {
......@@ -535,7 +589,7 @@ public class OssUtils {
String[] result = transcodeJob(ossFileDO, templateId, outObjectKey, null, mergeUrls);
LOGGER.info("【aliOSS】提交合并作业.<END>.[result]=" + JSON.toJSONString(result));
return result[0];
}
}*/
/**
* 视频文件合并,同步方法
......@@ -545,11 +599,11 @@ public class OssUtils {
* @return
* @throws FileException
*/
public static UploadResultInfo submitMergeJobMp4Sync(String fileUrl, List<String> mergeUrls) throws FileException {
/* public static UploadResultInfo submitMergeJobMp4Sync(String fileUrl, List<String> mergeUrls) throws FileException {
String bucketName = AliyunConstant.getBucketName(fileUrl);
String jobId = submitMergeJob(fileUrl, mergeUrls);
return transcodeJobResultSync(jobId, bucketName);
}
}*/
/**
* 视频文件合并,同步方法
......@@ -559,14 +613,14 @@ public class OssUtils {
* @return
* @throws FileException
*/
public static UploadResultInfo submitMergeJobSync(String fileUrl, List<String> mergeUrls) throws FileException {
/* public static UploadResultInfo submitMergeJobSync(String fileUrl, List<String> mergeUrls) throws FileException {
String bucketName = AliyunConstant.getBucketName(fileUrl);
String jobId = submitMergeJob(fileUrl, mergeUrls);
return transcodeJobResultSync(jobId, bucketName);
}
}*/
/**
* 同步的方式获取转码后的结果
* 同步的方式获取转码后的结果 new
*
* @param jobId
* @return
......@@ -596,6 +650,59 @@ public class OssUtils {
/**
* 转码作业
* * @param null
*/
private static String[] transcodeJob(OSSFileDO inputFile,String templateId,String outObjectKey, CreateTranscodingRequest.Watermark[] watermarkArray, List<String> mergeUrls){
// 媒体处理服务构造方法
MpcClient mpcClient = getAcsClient(inputFile.getBucket());
//设置媒体处理服务请求参数
CreateTranscodingRequest createTranscodingRequest = new CreateTranscodingRequest();
//设置转码的输入文件路径参数,可通过华为云OBS对象存储服务控制台查看。
ObsObjInfo input = new ObsObjInfo();
//设置输入桶名
input.setBucket(inputFile.getBucket());
//设置源文件路径
input.setObject(inputFile.getObject());
//设置输入桶所在区域
input.setLocation(inputFile.getLocation());
createTranscodingRequest.setInput(input);
// 设置转码的输出文件路径参数,可通过华为云OBS对象存储服务控制台查看。
ObsObjInfo output = new ObsObjInfo();
//设置输出桶名
output.setBucket(AliyunConstant.getOutBucket(input.getBucket()));
//设置输出文件路径
output.setObject(outObjectKey);
//设置输出桶所在区域
output.setLocation(inputFile.getLocation());
createTranscodingRequest.setOutput(output);
//设置转码模板ID
List<Long> transTempIds = new ArrayList<Long>();
transTempIds.add(Long.valueOf(templateId));
createTranscodingRequest.setTransTemplateId(transTempIds);
//文字水印
createTranscodingRequest.setWatermarks(watermarkArray);
String[] result = new String[2];
try {
//发送媒体处理服务请求
CreateTranscodingResponse createTranscodingResponse = mpcClient.createTranscodingTask(createTranscodingRequest);
//返回消息
LOGGER.info(new Gson().toJson(createTranscodingResponse));
result[0] = createTranscodingResponse.getTaskId();
result[1] = getOSSUrl(URLDecoder.decode(outObjectKey, "utf-8"), output.getBucket());
} catch (Exception e) {
LOGGER.error("【aliOSS】【ignoreLog】转码作业失败:" + e.getMessage(), e);
throw new FileException(FileException.FILE_CONVERT_FAIL, "转码作业失败");
}
return result;
}
/**
* 转码作业
*
* @param inputFile 输入文件
* @param templateId 转码模板
......@@ -604,7 +711,7 @@ public class OssUtils {
* @return
* @throws FileException
*/
private static String[] transcodeJob(OSSFileDO inputFile, String templateId, String outObjectKey,
/* private static String[] transcodeJob(OSSFileDO inputFile, String templateId, String outObjectKey,
JSONArray waterMarkConfigArray, List<String> mergeUrls) throws FileException {
try {
outObjectKey = URLEncoder.encode(outObjectKey, "utf-8");
......@@ -643,7 +750,7 @@ public class OssUtils {
if (response.getJobResultList().size() != outputJobCount) {
throw new RuntimeException("SubmitJobsRequest Size failed");
}
com.aliyuncs.mts.model.v20140618.SubmitJobsResponse.JobResult.Job job = response.getJobResultList().get(0)
SubmitJobsResponse.JobResult.Job job = response.getJobResultList().get(0)
.getJob();
result[0] = job.getJobId();
result[1] = getOSSUrl(URLDecoder.decode(outObjectKey, "utf-8"), outputBucketName);
......@@ -652,7 +759,7 @@ public class OssUtils {
throw new FileException(FileException.FILE_CONVERT_FAIL, "转码作业失败");
}
return result;
}
}*/
/**
* 组装视频合并参数
......@@ -661,7 +768,7 @@ public class OssUtils {
* @param bucketName
* @return
*/
private static JSONArray generateMergeInput(List<String> mergeUrls, String bucketName) {
/*private static JSONArray generateMergeInput(List<String> mergeUrls, String bucketName) {
if (ListUtils.isEmpty(mergeUrls)) {
return null;
}
......@@ -687,14 +794,14 @@ public class OssUtils {
mergeInput.put("MergeList", mergeJsons);
return mergeJsons;
}
*/
/**
* 组装视频水印参数
*
* @param content
* @return
*/
private static JSONArray getWaterMarkConfig(String content) {
/* private static JSONArray getWaterMarkConfig(String content) {
if (StringUtil.isEmpty(content)) {
return null;
}
......@@ -702,7 +809,7 @@ public class OssUtils {
waterMarkConfig.put("Type", "Text");
// 组装水印文本
JSONObject waterMarkText = new JSONObject();
waterMarkText.put("content", new String(Base64.encodeBase64(content.getBytes())));
waterMarkText.put("content", new String(Base64.encode(content.getBytes())));
waterMarkText.put("FontSize", 16);
waterMarkText.put("Top", 2000);
waterMarkText.put("Left", 20);
......@@ -710,6 +817,31 @@ public class OssUtils {
JSONArray waterMarkConfigArray = new JSONArray();
waterMarkConfigArray.add(waterMarkConfig);
return waterMarkConfigArray;
}*/
private static CreateTranscodingRequest.Watermark[] getWaterMarkConfig(String content){
if (StringUtil.isEmpty(content)) {
return null;
}
CreateTranscodingRequest.Watermark watermark = new CreateTranscodingRequest.Watermark();
// 文字水印内容,内容需做Base64编码,
// 示例:若想添加文字水印“测试文字水印”,那么Content的值为:5rWL6K+V5paH5a2X5rC05Y2w
watermark.setTextContext(new String(Base64.encode(content.getBytes())));
TextWatermark textWatermark = new TextWatermark();
// 字体颜色。
// 目前颜色支持black,blue,white,green,red,yellow,brown,gold,pink,orange,purple。
// 默认颜色是white
textWatermark.setFontColor("black");
// 字体,当前支持fzyouh、msyh
// 默认字体是msyh
textWatermark.setFontName("fzyouh");
// 字体大小。默认值:16,范围:(4, 120)
textWatermark.setFontSize(16);
watermark.setTextWatermark(textWatermark);
List<CreateTranscodingRequest.Watermark> watermarks = new ArrayList<CreateTranscodingRequest.Watermark>();
watermarks.add(watermark);
CreateTranscodingRequest.Watermark[] watermarkArray = new CreateTranscodingRequest.Watermark[watermarks.size()];
return watermarks.toArray(watermarkArray);
}
/**
......@@ -722,7 +854,7 @@ public class OssUtils {
* @return
* @throws FileException
*/
public static String submitClipJob(String fileName, String fileUrl, String seek, String duration)
/*public static String submitClipJob(String fileName, String fileUrl, String seek, String duration)
throws FileException {
LOGGER.info("【aliOSS】提交音视频剪切作业.<START>.[fileUrl]=" + fileUrl + ",[seek]=" + seek + ",[duration]=" + duration);
if (StringUtil.isEmpty(duration)) {
......@@ -735,7 +867,7 @@ public class OssUtils {
}
String resultFileUrl = "";
String outFileType = FileUtils.VIDEO.equals(gatherName) ? "mp4" : "mp3";
if (StringTools.contains(fileUrl, AliyunConstant.OSS_CDN_URLS)) {
*//*if (StringTools.contains(fileUrl, AliyunConstant.OSS_CDN_URLS)) {
String inObjectKey = splitObjectKey(fileUrl);
String inBucketName = fileUrlExist001(fileUrl) ? AliyunConstant.INPUT_BUCKET
: AliyunConstant.getBucketName(fileUrl);
......@@ -747,10 +879,10 @@ public class OssUtils {
OSSFileDO ossFileDO = uploadPointFile2OSS(fileUrl, AliyunConstant.FILE_BUCKET, inObjectKey);
String outObjectKey = getOutObjectKey(AliyunEnum.CUT, fileName, outFileType);
resultFileUrl = clipJob(ossFileDO, outObjectKey, seek, duration);
}
}*//*
LOGGER.info("【aliOSS】提交音视频剪切作业.<END>.[resultFileUrl]=" + resultFileUrl);
return resultFileUrl;
}
}*/
/**
* 提交视频剪切作业
......@@ -763,7 +895,7 @@ public class OssUtils {
* @return
* @throws FileException
*/
public static String submitClipJob(byte[] buff, String fileName, String fileType, String seek, String duration)
/*public static String submitClipJob(byte[] buff, String fileName, String fileType, String seek, String duration)
throws FileException {
LOGGER.info("【aliOSS】提交音视频剪切作业.<START>.[fileName]=" + fileName + ",[seek]=" + seek + ",[duration]=" + duration);
fileName = MD5.getMD5StrLower(fileName);
......@@ -774,7 +906,7 @@ public class OssUtils {
String resultFileUrl = clipJob(inputFile, outObjectKey, seek, duration);
LOGGER.info("【aliOSS】提交音视频剪切作业.<END>.[resultFileUrl]=" + resultFileUrl);
return resultFileUrl;
}
}*/
/**
* 视频剪切作业
......@@ -786,7 +918,7 @@ public class OssUtils {
* @return
* @throws FileException
*/
private static String clipJob(OSSFileDO inputFile, String outObjectKey, String seek, String duration)
/*private static String clipJob(OSSFileDO inputFile, String outObjectKey, String seek, String duration)
throws FileException {
try {
outObjectKey = URLEncoder.encode(outObjectKey, "utf-8");
......@@ -814,17 +946,17 @@ public class OssUtils {
String object = null;
try {
SubmitJobsResponse response = getAcsClient(inputBucketName).getAcsResponse(request);
*//* SubmitJobsResponse response = getAcsClient(inputBucketName).getAcsResponse(request);
if (response.getJobResultList().size() != outputJobCount) {
throw new RuntimeException("SubmitJobsRequest Size failed");
}
object = response.getJobResultList().get(0).getJob().getOutput().getOutputFile().getObject();
object = URLDecoder.decode(object, "UTF-8");
object = URLDecoder.decode(object, "UTF-8");*//*
} catch (Exception e) {
LOGGER.error("【aliOSS】视频剪辑作业失败:" + e.getMessage(), e);
}
return getOSSUrl(object, outputBucketName);
}
}*/
/**
* 组装剪切参数
......@@ -833,7 +965,7 @@ public class OssUtils {
* @param duration 持续时长 sssss[.SSS]
* @return
*/
private static JSONObject generateClipInput(String seek, String duration) {
/* private static JSONObject generateClipInput(String seek, String duration) {
LOGGER.info("【aliOSS】组装剪切参数.<START>.[seek]=" + seek + ",[duration]=" + duration);
JSONObject input = new JSONObject();
input.put("Seek", seek);
......@@ -843,7 +975,7 @@ public class OssUtils {
LOGGER.info("【aliOSS】组装剪切参数.<END>");
return timeSpanObject;
}
*/
/**
* 提交视频截图任务,成功返回图片地址 <br>
*
......@@ -851,7 +983,7 @@ public class OssUtils {
* @param time 秒
* @return 成功:图片地址,失败:null
*/
public static String submitSnapshotJob(String fileUrl, int time) {
/* public static String submitSnapshotJob(String fileUrl, int time) {
LOGGER.info("【aliOSS】提交MP4截图作业,<START>.[fileUrl]=" + fileUrl);
String fileType = FileUtils.getFileType(fileUrl);
if (!FileUtils.VIDEO.equals(FileUtils.getGatherName(fileType))) {
......@@ -869,7 +1001,8 @@ public class OssUtils {
String outputBucketName = AliyunConstant.FILE_BUCKET;
request.setSnapshotConfig(generateSnapshotConfig(outputBucketName, outObjectKey, time).toJSONString());
request.setPipelineId(AliyunConstant.getPipelineId(inputBucketName));
SnapshotJob snapshotJob = getAcsClient(inputBucketName).getAcsResponse(request).getSnapshotJob();
SnapshotJob snapshotJob = new SnapshotJob();
getAcsClient(inputBucketName).getAcsResponse(request).getSnapshotJob();
if ("Success".equalsIgnoreCase(snapshotJob.getState())) {
String outObject = URLDecoder.decode(snapshotJob.getSnapshotConfig().getOutputFile().getObject(),
"UTF-8");
......@@ -879,7 +1012,132 @@ public class OssUtils {
LOGGER.error("【aliOSS】视频截图失败:" + e.getMessage(), e);
}
return null;
}*/
/**
* 提交视频截图任务,成功返回图片地址
* @author:zhuyajie
* @date:2020/6/1 20:08
* * @param null
*/
public static String submitSnapshotJob(String fileUrl, int time){
LOGGER.info("【aliOSS】提交MP4截图作业,<START>.[fileUrl]=" + fileUrl);
String fileType = FileUtils.getFileType(fileUrl);
if (!FileUtils.VIDEO.equals(FileUtils.getGatherName(fileType))) {
return null;
}
if (!StringTools.contains(fileUrl, AliyunConstant.OSS_CDN_URLS)) {
return null;
}
String inputBucketName = AliyunConstant.getBucketName(fileUrl);
MpcClient mpcClient = getAcsClient(inputBucketName);
String objectKey = splitObjectKey(fileUrl);
// 设置创建截图模板的请求参数
CreateThumbnailRequest createThumbnailRequest = new CreateThumbnailRequest();
// 设置截图源文件地址
ObsObjInfo input = new ObsObjInfo();
//OBS桶名
input.setBucket(inputBucketName);
//OBS下媒资路径
input.setObject(objectKey);
//OBS桶所在区域
input.setLocation(AliyunConstant.getOssRegion(inputBucketName));
createThumbnailRequest.setInput(input);
// 设置截图后文件存放地址
String outObjectKey = getTranscodeOutObjectKey(AliyunEnum.SNAPSHOT, ImageTypeEnum.JPG.value);
String outputBucketName = AliyunConstant.FILE_BUCKET;
ObsObjInfo output = new ObsObjInfo();
output.setBucket(outputBucketName);
output.setObject(outObjectKey);
output.setLocation(AliyunConstant.getOssRegion(outputBucketName));
createThumbnailRequest.setOutput(output);
// 设置截图参数
CreateThumbnailRequest.ThumbnailPara thumbnailPara = new CreateThumbnailRequest.ThumbnailPara();
//采样类型。支持三种采样方式PERCENT、TIME和DOTS(根据时间间隔time,根据视频时长百分比percent,根据时间截图时的时间点数组dots,目前只支持TIME和DOTS两种方式)
thumbnailPara.setType(CreateThumbnailRequest.ThumbnailPara.TypeEnum.TIME);
//从视频文件的第“start_time”开始,持续时间为“duration”,每间隔“time”生成一张截图。
thumbnailPara.setTime(12);
thumbnailPara.setStartTime(time);
thumbnailPara.setDuration(3);
//设置最大长度,范围(380,3840)
thumbnailPara.setMaxLength(480);
//设置纵横比(min = 0, max = 1)
thumbnailPara.setAspectRatio(0);
//设置截图格式,0表示默认,1表示JPG格式
thumbnailPara.setFormat(1);
createThumbnailRequest.setThumbnailPara(thumbnailPara);
// 发送创建截图任务请求给媒体处理服务
CreateThumbnailResponse createThumbnailResponse = mpcClient.createThumbnailsTask(createThumbnailRequest);
// 返回消息
System.out.println(new Gson().toJson(createThumbnailResponse));
String taskId = null;
if ("SUCCESS".equalsIgnoreCase(createThumbnailResponse.getRequestStatus())) {
taskId = createThumbnailResponse.getTaskId();
} else {
LOGGER.error("【aliOSS】提交视频截图任务失败:" + new Gson().toJson(createThumbnailResponse));
return null;
}
String outObject = getThumnailObject(outputBucketName, taskId);
if (!StringUtil.isEmpty(outObject)) {
return getOSSUrl(outObject, outputBucketName);
} else {
return null;
}
}
public static String getThumnailObject(String bucketName, String taskId){
int total = 0;
while (true) {
// 如果超过1小时,认定转换失败
if (total > 1 * 60 * 60) {
return null;
}
String object = OssUtils.getThumbnail(bucketName, taskId);
if (object != null) {
return object;
}
try {
Thread.sleep(3 * 1000);
} catch (Exception e) {
LOGGER.error("【视频截图】进入休眠状态失败: " + e.getMessage(), e);
throw new FileException(FileException.FILE_CONVERT_FAIL, "获取视频截图失败");
}
total += 3;
}
}
private static String getThumbnail(String bucketName, String taskId) {
if (StringUtil.isEmpty(taskId)) {
return null;
}
MpcClient mpcClient = getAcsClient(bucketName);
// 设置创建水印模板的请求参数
QueryThumbTaskRequest queryThumbTaskRequest = new QueryThumbTaskRequest();
//根据任务ID查询,最多支持10个任务ID
queryThumbTaskRequest.setTaskId(new String[]{taskId});
String outObject = null;
try {
// 发送查询截图任务请求给媒体处理服务
QueryThumbTaskResponse queryThumbTaskResponse = mpcClient.queryThumbnailsTask(queryThumbTaskRequest);
// 返回消息
System.out.println(new Gson().toJson(queryThumbTaskResponse));
if (QueryThumbTaskResponse.ThumbTask.StatusEnum.SUCCEEDED.equals(queryThumbTaskResponse.getTaskArray().get(0).getStatus())) {
QueryThumbTaskResponse.ThumbTask thumbTask = queryThumbTaskResponse.getTaskArray().get(0);
String picName = thumbTask.getThumbnailInfo().get(0).getPicName();
outObject = URLDecoder.decode(thumbTask.getOutput().getObject()+"/"+picName, "UTF-8");
}
} catch (Exception e) {
LOGGER.error("【aliOSS】查询视频截图任务失败:" + e.getMessage(), e);
}
return outObject;
}
/**
* 组装截图参数
......@@ -889,7 +1147,7 @@ public class OssUtils {
* @param time
* @return
*/
private static JSONObject generateSnapshotConfig(String bucketName, String outputobject, int time) {
/* private static JSONObject generateSnapshotConfig(String bucketName, String outputobject, int time) {
JSONObject snapshotConfig = new JSONObject();
JSONObject output = generateSnapshotInput(bucketName, outputobject);
snapshotConfig.put("OutputFile", output);
......@@ -898,7 +1156,7 @@ public class OssUtils {
// 截图类型,普通帧:normal,I帧:intra,默认值intra
snapshotConfig.put("FrameType", "normal");
return snapshotConfig;
}
}*/
/**
* 组装截图参数
......@@ -907,16 +1165,16 @@ public class OssUtils {
* @param inputObject
* @return
*/
private static JSONObject generateSnapshotInput(String bucketName, String inputObject) {
/* private static JSONObject generateSnapshotInput(String bucketName, String inputObject) {
JSONObject input = new JSONObject();
input.put("Location", AliyunConstant.OSS_REGION);
input.put("Bucket", bucketName);
input.put("Object", inputObject);
return input;
}
}*/
/**
* 组装转换后的地址(华东地区)
* 组装转换后的地址(华东地区) new
*
* @param transcodeJobId
* @return
......@@ -927,7 +1185,7 @@ public class OssUtils {
}
/**
* 组装转换后的地址,根据BUCKETNAME
* 组装转换后的地址,根据BUCKETNAME new
*
* @param transcodeJobId
* @return
......@@ -953,7 +1211,8 @@ public class OssUtils {
if (StringUtil.isEmpty(transcodeJobId)) {
return new UploadResultInfo("ali", "ali转码作业失败[transcodeJobId=null]", false);
}
Job transcodeJob = getTranscodeJob(transcodeJobId, outputBucketName);
// Job transcodeJob = getTranscodeJob(transcodeJobId, outputBucketName);
QueryTranscodingResponse.QueryTranscodingInfo transcodeJob = getTranscodeJob(transcodeJobId,outputBucketName);
return explainTranscodeResult(transcodeJob);
}
......@@ -963,7 +1222,7 @@ public class OssUtils {
* @param transcodeJobId
* @return
*/
private static Job getTranscodeJob(String transcodeJobId, String bucketName) throws FileException {
/*private static Job getTranscodeJob(String transcodeJobId, String bucketName) throws FileException {
QueryJobListRequest request = new QueryJobListRequest();
request.setJobIds(transcodeJobId);
QueryJobListResponse response = null;
......@@ -974,22 +1233,64 @@ public class OssUtils {
LOGGER.error("【aliOSS】获取转换作业情况失败:" + e.getMessage(), e);
throw new FileException(FileException.FILE_CONVERT_FAIL, "获取转换作业情况失败");
}
}*/
private static QueryTranscodingResponse.QueryTranscodingInfo getTranscodeJob(String transcodeJobId, String bucketName){
MpcClient mpcClient = OssUtils.initAcsClient(bucketName);
//设置查询转码任务ID
QueryTranscodingRequest queryTranscodingRequest=new QueryTranscodingRequest();
queryTranscodingRequest.setTaskId(transcodeJobId);
try {
//发送查询转码任务请求
QueryTranscodingResponse queryTranscodingResponse=mpcClient.queryTranscodingTask(queryTranscodingRequest);
System.out.println(new Gson().toJson(queryTranscodingResponse));
return queryTranscodingResponse.getTranscodingArray().get(0);
} catch (Exception e) {
LOGGER.error("【aliOSS】获取转换作业情况失败:" + e.getMessage(), e);
throw new FileException(FileException.FILE_CONVERT_FAIL, "获取转换作业情况失败");
}
}
private static UploadResultInfo explainTranscodeResult(QueryTranscodingResponse.QueryTranscodingInfo transcodingInfo){
String status = transcodingInfo.getStatus();
if ("FAILED".equals(status)) {
LOGGER.warn("【huawei】转换作业失败:[jobId]" + transcodingInfo.getTaskId() + ",[status]=" + status);
return new UploadResultInfo("ali", "huawei转码作业失败", false);
}
if ("SUCCEEDED".equals(status)) {
QueryTranscodingResponse.QueryTranscodingInfo.Output output = transcodingInfo.getOutput();
String bucketName = output.getBucket();
String objectKey = null;
String outputFileName = transcodingInfo.getOutputFileNames().get(0);
try {
objectKey = URLDecoder.decode(output.getObject()+"/"+outputFileName, "UTF-8");
} catch (Exception e) {
LOGGER.error("【aliOSS】组装转换后的地址失败:" + e.getMessage(), e);
return new UploadResultInfo("ali", "huawei转码作业失败", false);
}
// 文件大小
Long fileSize =transcodingInfo.getTranscodeDetail().getMultitaskInfo().get(0).getOutputFile().getSize();
// 视频时长 音频时长
Integer duration = transcodingInfo.getTranscodeDetail().getMultitaskInfo().get(0).getOutputFile().getDuration();
return getResultInfo(objectKey, fileSize, duration.toString(), bucketName);
}
return null;
}
/**
* 解析转换后的结果
*
* @param transcodeJob
* @return
*/
private static UploadResultInfo explainTranscodeResult(Job transcodeJob) {
/* private static UploadResultInfo explainTranscodeResult(Job transcodeJob) {
String status = transcodeJob.getState();
if ("TranscodeFail".equals(status)) {
LOGGER.warn("【aliOSS】转换作业失败:[jobId]" + transcodeJob.getJobId() + ",[status]=" + status);
return new UploadResultInfo("ali", "ali转码作业失败", false);
}
if ("TranscodeSuccess".equals(status)) {
com.aliyuncs.mts.model.v20140618.QueryJobListResponse.Job.Output output = transcodeJob.getOutput();
Job.Output output = transcodeJob.getOutput();
String bucketName = output.getOutputFile().getBucket();
String objectKey = null;
try {
......@@ -1016,7 +1317,7 @@ public class OssUtils {
return getResultInfo(objectKey, fileSize, duration, bucketName);
}
return null;
}
}*/
/**
* 获取媒体信息,仅限经过转码的音视频文件
......@@ -1032,26 +1333,22 @@ public class OssUtils {
}
String objectKey = splitObjectKey(fileUrl);
String bucketName = AliyunConstant.getBucketName(fileUrl);
SubmitMediaInfoJobRequest request = new SubmitMediaInfoJobRequest();
OSSFileDO ossFileDO = new OSSFileDO(AliyunConstant.getOssRegion(bucketName), bucketName, objectKey);
request.setInput(ossFileDO.toJsonString());
SubmitMediaInfoJobResponse response = null;
ObjectMetadata objectMetadata = null;
try {
response = getAcsClient(bucketName).getAcsResponse(request);
objectMetadata = getObjectMetadata(objectKey,bucketName);
} catch (Exception e) {
LOGGER.error("【aliOSS】获取媒体信息失败:" + e.getMessage(), e);
}
if (response == null) {
if (objectMetadata == null) {
return null;
}
// 封装返回对象
Format format = response.getMediaInfoJob().getProperties().getFormat();
OssMediaInfoDTO ossMediaInfoDTO = new OssMediaInfoDTO();
ossMediaInfoDTO.setBucket(bucketName);
ossMediaInfoDTO.setLocation(AliyunConstant.getOssRegion(bucketName));
ossMediaInfoDTO.setObejctKey(objectKey);
ossMediaInfoDTO.setSize(StringUtil.isEmpty(format.getSize()) ? 0L : Long.parseLong(format.getSize()));
ossMediaInfoDTO.setDuration(StringUtil.isEmpty(format.getDuration()) ? BigDecimal.ZERO : new BigDecimal(format.getDuration()));
ossMediaInfoDTO.setSize(1L);
ossMediaInfoDTO.setDuration(new BigDecimal(1));
LOGGER.info("【aliOSS】获取媒体信息,仅限经过转码的音视频文件,<END>.[ossMediaInfoDTO]=" + ossMediaInfoDTO);
return ossMediaInfoDTO;
}
......@@ -1062,12 +1359,13 @@ public class OssUtils {
* @param objectKey
* @return
*/
@SneakyThrows
public static ObjectMetadata getObjectMetadata(String objectKey, String bucketName) throws FileException {
// 创建OSSClient实例
OSSClient ossClient = getOSSClient(bucketName);
ObsClient ossClient = getOSSClient(bucketName);
ObjectMetadata objectMetadata = ossClient.getObjectMetadata(bucketName, objectKey);
// 关闭client
ossClient.shutdown();
ossClient.close();
return objectMetadata;
}
......@@ -1082,13 +1380,13 @@ public class OssUtils {
String objectKey = splitObjectKey(fileUrl);
String bucketName = AliyunConstant.getBucketName(fileUrl);
// OSSClient实例
OSSClient ossClient = null;
ObsClient ossClient = null;
InputStream is = null;
ByteArrayOutputStream os = null;
byte[] result = null;
try {
ossClient = getOSSClient(bucketName);
OSSObject ossObject = ossClient.getObject(bucketName, objectKey);
ObsObject ossObject = ossClient.getObject(bucketName, objectKey);
is = ossObject.getObjectContent();
os = new ByteArrayOutputStream();
byte[] buff = new byte[1024];
......@@ -1110,7 +1408,7 @@ public class OssUtils {
os.close();
}
if (ossClient != null) {
ossClient.shutdown();
ossClient.close();
}
} catch (Exception e) {
LOGGER.error("【aliOSS】下载文件,关闭文件流失败:" + e.getMessage(), e);
......@@ -1120,27 +1418,21 @@ public class OssUtils {
}
/**
* 下载文件到本地
* 下载文件到本地()
*
* @param fileUrl
* @param outFilePath
*/
@SneakyThrows
public static void downloadFile(String fileUrl, String outFilePath) throws FileException {
String objectKey = splitObjectKey(fileUrl);
String bucketName = AliyunConstant.getBucketName(fileUrl);
OSSClient ossClient = null;
try {
// 创建OSSClient实例
ossClient = getOSSClient(bucketName);
// 下载object到文件
ossClient.getObject(new GetObjectRequest(bucketName, objectKey), new File(outFilePath));
downloadPointFile2OSS(fileUrl,outFilePath,bucketName,objectKey);
} catch (Exception e) {
LOGGER.error("【aliOSS】下载文件失败:" + e.getMessage(), e);
throw new FileException(FileException.FILE_DOWNLOAD_FAILURE, "下载文件失败");
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
//下载失败再次尝试断点下载
downloadPointFile2OSS(fileUrl,outFilePath,bucketName,objectKey);
}
}
......@@ -1164,7 +1456,7 @@ public class OssUtils {
uploadResultInfo.setSize(size);
}
uploadResultInfo.setFileName(FileUtils.getFileName(objectKey));
uploadResultInfo.setFileId("ali");
uploadResultInfo.setFileId("huawei");
uploadResultInfo.setFlag(true);
uploadResultInfo.setFinish(true);
if (!StringUtil.isEmpty(duration)) {
......@@ -1245,6 +1537,21 @@ public class OssUtils {
return getObjectKey(aliyunEnum, fileName, fileType);
}
/**
* 组装输出文件Object路径-转码
*
* @param aliyunEnum
* @param fileType
* @return
*/
private static String getTranscodeOutObjectKey(AliyunEnum aliyunEnum, String fileType) {
//用于“output”时,只需指定到转码结果期望存放的路径。
String gatherName = FileUtils.getGatherName(fileType);
gatherName = StringUtil.isEmpty(gatherName) ? "other" : gatherName.toLowerCase();
return new StringBuilder("oss/").append(aliyunEnum.value).append("/").append(gatherName).append("/")
.append(fileType).append("/").toString();
}
/**
* 组装ObjectKey
*
......@@ -1550,6 +1857,7 @@ public class OssUtils {
* @return
* @throws FileException
*/
@SneakyThrows
public static OssImageCropDTO imageCropSaveas(String fileUrl, int width, int height, int x, int y)
throws FileException {
LOGGER.info("【aliOSS】图片裁剪持久化,<START>.[fileUrl]=" + fileUrl);
......@@ -1565,24 +1873,28 @@ public class OssUtils {
style.append(",h_").append(height);
style.append(",x_").append(x);
style.append(",y_").append(y);
style.append("|sys/saveas");
String outObjectKey = getOutObjectKey(AliyunEnum.CUT, null, fileType);
style.append(",o_").append(BinaryUtil.toBase64String(outObjectKey.getBytes()));
style.append(",b_").append(BinaryUtil.toBase64String(bucketName.getBytes()));
ProcessObjectRequest request = new ProcessObjectRequest(bucketName, sourceKey, style.toString());
// 创建OSSClient实例
OSSClient ossClient = getOSSClient(bucketName);
GenericResult processResult = ossClient.processObject(request);
OssImageCropDTO ossImageCropDTO = null;
ObsClient ossClient = getOSSClient(bucketName);
TemporarySignatureRequest temporarySignatureRequest = new TemporarySignatureRequest();
temporarySignatureRequest.setObjectKey(sourceKey);
Map<String, Object> queryParams =new HashMap<>();
queryParams.put("x-image-process",style.toString());
queryParams.put("x-image-save-object", ServiceUtils.toBase64(sourceKey.getBytes("UTF-8")));
queryParams.put("x-image-save-bucket",ServiceUtils.toBase64(bucketName.getBytes("UTF-8")));
temporarySignatureRequest.setQueryParams(queryParams);
temporarySignatureRequest.setBucketName(bucketName);
TemporarySignatureResponse response = ossClient.createTemporarySignature(temporarySignatureRequest);
//访问的url
String url = response.getSignedUrl();
LOGGER.info(url);
OssImageCropDTO ossImageCropDTO = new OssImageCropDTO();
try {
String json = IOUtils.readStreamAsString(processResult.getResponse().getContent(), "UTF-8");
processResult.getResponse().getContent().close();
ossImageCropDTO = JSON.parseObject(json, OssImageCropDTO.class);
ossImageCropDTO.setFileUrl(getOSSUrl(ossImageCropDTO.getObject(), bucketName));
ossImageCropDTO.setBucket(bucketName);
ossImageCropDTO.setObject(sourceKey);
ossImageCropDTO.setFileUrl(url);
} catch (Exception e) {
LOGGER.error("【aliOSS】图片裁剪持久化失败:" + e.getMessage(), e);
}
LOGGER.info("【aliOSS】图片裁剪持久化,<END>.[ossImageCropDTO]=" + ossImageCropDTO);
return ossImageCropDTO;
}
......@@ -1592,28 +1904,50 @@ public class OssUtils {
* @param fileUrl
* @param style
*/
@SneakyThrows
private static String imageHandle(String fileUrl, String style) {
String fileType = FileUtils.getFileType(fileUrl);
String key = splitObjectKey(fileUrl);
String bucketName = AliyunConstant.getBucketName(fileUrl);
GetObjectRequest request = new GetObjectRequest(bucketName, key);
request.setProcess(style);
request.setImageProcess(style);
// 创建OSSClient实例
OSSClient ossClient = getOSSClient(bucketName);
ObsClient ossClient = getOSSClient(bucketName);
// 生成新的图片地址
String localPath = FilePathConstant.IMAGE + UUIDUitl.generateString(32) + "." + fileType;
FileUtils.creatFiles(localPath);
try {
ossClient.getObject(request, new File(localPath));
ObsObject obsObject = ossClient.getObject(request);
obsObjectToLocalFile(localPath, obsObject);
} catch (Exception e) {
FileUtils.deleteFile(localPath);
LOGGER.error("【aliOSS】图片处理API:" + e.getMessage(), e);
} finally {
ossClient.shutdown();
ossClient.close();
}
return localPath;
}
private static void obsObjectToLocalFile(String localPath, ObsObject obsObject) throws IOException {
InputStream input = null;
FileOutputStream downloadFile = null;
try {
input = obsObject.getObjectContent();
int index;
byte[] bytes = new byte[1024];
downloadFile = new FileOutputStream(localPath);
while ((index = input.read(bytes)) != -1) {
downloadFile.write(bytes, 0, index);
downloadFile.flush();
}
} catch (IOException e) {
LOGGER.error("obsObjectToLocalFile失败");
} finally {
input.close();
downloadFile.close();
}
}
/**
* 图片增加水印
*
......@@ -1628,7 +1962,7 @@ public class OssUtils {
ImageUtils.checkIsImage(fileUrl);
StringBuilder style = new StringBuilder("image/watermark");
// 水印文本,需要转换成base64格式
style.append(",text_" + new String(Base64.encodeBase64(watermarkContent.getBytes())));
style.append(",text_" + new String(Base64.encode(watermarkContent.getBytes())));
// 水印字体大小,位置,偏移量
style.append(",size_60,g_se,x_20,y_20");
// 生成新的图片地址
......@@ -1657,7 +1991,7 @@ public class OssUtils {
fileUrl = checkImageFileUrl(fileUrl);
// 水印文本
StringBuilder style = new StringBuilder("image/watermark");
style.append(",text_" + new String(Base64.encodeBase64URLSafe(text.getBytes())));
style.append(",text_" + new String(Base64.encode(text.getBytes())));
// 水印字体大小,如果小于1,自动计算文字大小2
int size = ossImageDTO.getSize();
style.append(",size_").append(size < 1 ? caleImageFontSize(fileUrl) : size);
......@@ -1696,10 +2030,10 @@ public class OssUtils {
}
StringBuilder style = new StringBuilder("image/watermark");
// 水印图片地址,按主图大小的10%缩放
watermarkImageUrl = splitObjectKey(watermarkImageUrl) + "?x-oss-process=image/resize,P_10";
style.append(",image_" + new String(Base64.encodeBase64URLSafe(watermarkImageUrl.getBytes())));
watermarkImageUrl = AliyunConstant.getBucketName(watermarkImageUrl)+"/" + splitObjectKey(watermarkImageUrl);
style.append(",image_" + new String(Base64.encode(watermarkImageUrl.getBytes())));
// 水印颜色,位置,偏移量
style.append(",g_nw,x_20,y_10");
style.append(",g_br,t_90,x_10,y_10");
String result = imageWatermarkHandle(fileUrl, style.toString());
LOGGER.info("【aliOSS】图片增加水印(图片),<END>.[result]=" + result);
return result;
......@@ -1711,21 +2045,23 @@ public class OssUtils {
* @param fileUrl
* @param style
*/
@SneakyThrows
private static String imageWatermarkHandle(String fileUrl, String style) {
String fileName = FileUtils.getFileName(fileUrl);
String fileType = FileUtils.getFileType(fileUrl);
String key = splitObjectKey(fileUrl);
String bucketName = AliyunConstant.getBucketName(fileUrl);
GetObjectRequest request = new GetObjectRequest(bucketName, key);
request.setProcess(style.toString());
request.setImageProcess(style);
// 创建OSSClient实例
OSSClient ossClient = getOSSClient(bucketName);
ObsClient ossClient = getOSSClient(bucketName);
// 生成带水印的本地图片地址
String localPath = FilePathConstant.IMAGE_WATERMARK + fileName + "_" + LocalDateUtils.getYmdhmss() + "."
+ fileType;
FileUtils.creatFiles(localPath);
ossClient.getObject(request, new File(localPath));
ossClient.shutdown();
ObsObject obsObject = ossClient.getObject(request);
obsObjectToLocalFile(localPath,obsObject);
ossClient.close();
// 上传处理后的图片,并删除本地文件
UploadResultInfo uploadResultInfo = uploadLocalFile4CustomName(localPath, fileName);
FileUtils.deleteFile(localPath);
......@@ -1776,9 +2112,9 @@ public class OssUtils {
*
* @return
*/
private static OSSClient getOSSClient(String bucketName) {
return new OSSClient(AliyunConstant.getOSSEndPoint(bucketName), AliyunConstant.MAIN_ACCESS_KEY_ID,
AliyunConstant.MAIN_ACCESS_KEY_SECRET);
private static ObsClient getOSSClient(String bucketName) {
return new ObsClient(AliyunConstant.MAIN_ACCESS_KEY_ID,
AliyunConstant.MAIN_ACCESS_KEY_SECRET,AliyunConstant.getOSSEndPoint(bucketName));
}
/**
......@@ -1788,11 +2124,12 @@ public class OssUtils {
* @param objectKey
* @return
*/
@SneakyThrows
private static boolean objectExist(String bucketName, String objectKey) {
OSSClient ossClient = getOSSClient(bucketName);
ObsClient ossClient = getOSSClient(bucketName);
boolean found = ossClient.doesObjectExist(bucketName, objectKey);
// 关闭client
ossClient.shutdown();
ossClient.close();
return found;
}
......
package com.pcloud.common.utils.aliyun.test;
import static feign.Util.toByteArray;
import com.google.gson.Gson;
import com.huawei.mpc.client.MpcClient;
import com.huawei.mpc.client.MpcConfig;
import com.huawei.mpc.model.ObsObjInfo;
import com.huawei.mpc.model.thumbnail.CreateThumbnailRequest;
import com.huawei.mpc.model.thumbnail.CreateThumbnailResponse;
import com.huawei.mpc.model.thumbnail.QueryThumbTaskRequest;
import com.huawei.mpc.model.thumbnail.QueryThumbTaskResponse;
import com.huawei.mpc.model.transcoding.CreateTranscodingRequest;
import com.huawei.mpc.model.transcoding.CreateTranscodingResponse;
import com.huawei.mpc.model.transcoding.QueryTranscodingRequest;
import com.huawei.mpc.model.transcoding.QueryTranscodingResponse;
import com.huawei.mpc.model.transcoding.TextWatermark;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.exceptions.FileException;
import com.pcloud.common.utils.aliyun.OssUtils;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @ClassName com.pcloud.auditcenter.utils.test.MPCTest
* @Author zhuyajie
* @Description 转码
* @Date 2020/5/25 17:34
* @Version 1.0
**/
@Slf4j
@RestController
@RequestMapping("mpcTest")
public class MPCTest {
public static final String AK="8J56JHJN5P8OLR5ERKFU";
public static final String SK="xAlBYlowAhwa9c1Wi4JsX7XkZGFlzlWW3CBHdZWJ";
public static final String PROJECT_ID="07455135488025b22fe7c01fdb631c14";
private static MpcClient initMpcClient(){
MpcConfig mpcConfig = new MpcConfig();
mpcConfig.setEndPoint("mpc.cn-east-2.myhuaweicloud.com");// 设置转码节点地址
mpcConfig.setProjectId(PROJECT_ID);// 设置用户项目编号ProjectId
mpcConfig.setSk(SK);// 设置sk
mpcConfig.setAk(AK);// 设置ak
MpcClient mpcClient = new MpcClient(mpcConfig);
return mpcClient;
}
@RequestMapping(value = "transcodeJob", method = RequestMethod.GET)
public void transcodeJob(@RequestParam("fileUrl") String fileUrl, @RequestParam("outPutUrl") String outPutUrl,
@RequestParam("ext") String ext) throws FileException {
// String fileUrl = "oss/transcode/audio/mp3/test_20200529145343507.mp3";
// String outPutUrl = "oss/transcode/audio/mp3/";
// url=oss/transcode/video/mp4/7599ec23e9f8454f8897c4ca64a2df34.mp4
Long templateId=null;
if ("mp3".equals(ext)){
templateId=104257L;
} else {
templateId =104256L;
}
transcodeJob("whlg-oss-test-001",fileUrl,templateId,"cn-east-2",outPutUrl);
}
// public static void main(String[] args) {
// String fileUrl = "oss/transcode/video/mp4/7599ec23e9f8454f8897c4ca64a2df34.mp4";
// String outPutUrl = "oss/transcode/video/mp4/";
// transcodeJob("whlg-oss-test-002",fileUrl,104256L,"cn-east-2",outPutUrl);
//// getTranscodeJob("460368","test");
// }
private static void transcodeJob(String bucketName,String fileUrl, Long templateId,String location,String outputUrl){
// 媒体处理服务构造方法
MpcClient mpcClient = initMpcClient();
//设置媒体处理服务请求参数
CreateTranscodingRequest createTranscodingRequest = new CreateTranscodingRequest();
//设置转码的输入文件路径参数,可通过华为云OBS对象存储服务控制台查看。
ObsObjInfo input = new ObsObjInfo();
//设置输入桶名
input.setBucket(bucketName);
//设置源文件路径
input.setObject(fileUrl);
//设置输入桶所在区域
input.setLocation(location);
createTranscodingRequest.setInput(input);
// 设置转码的输出文件路径参数,可通过华为云OBS对象存储服务控制台查看。
ObsObjInfo output = new ObsObjInfo();
//设置输出桶名
output.setBucket(bucketName);
//设置输出文件路径
output.setObject(outputUrl);
//设置输出桶所在区域
output.setLocation(location);
createTranscodingRequest.setOutput(output);
//设置转码模板ID
List<Long> transTempIds = new ArrayList<Long>();
transTempIds.add(templateId);
createTranscodingRequest.setTransTemplateId(transTempIds);
// 设置水印功能
CreateTranscodingRequest.Watermark watermark = new CreateTranscodingRequest.Watermark();
// watermark.setTemplateId("watermark_template_id");
// 设置水印图片地址
// ObsObjInfo watermarkInput = new ObsObjInfo();
// // 水印图片地址所在桶
// watermarkInput.setBucket(bucketName);
// // 水印图片地址所在路径
// watermarkInput.setObject("objectKey");
// // 水印图片地址所在区域
// watermarkInput.setLocation(location);
// watermark.setInput(watermarkInput);
// 文字水印内容,内容需做Base64编码,
// 示例:若想添加文字水印“测试文字水印”,那么Content的值为:5rWL6K+V5paH5a2X5rC05Y2w
watermark.setTextContext("5rWL6K+V5paH5a2X5rC05Y2w");
TextWatermark textWatermark = new TextWatermark();
// 字体颜色。
// 目前颜色支持black,blue,white,green,red,yellow,brown,gold,pink,orange,purple。
// 默认颜色是white
textWatermark.setFontColor("black");
// 字体,当前支持fzyouh、msyh
// 默认字体是msyh
textWatermark.setFontName("fzyouh");
// 字体大小。默认值:16,范围:(4, 120)
textWatermark.setFontSize(16);
watermark.setTextWatermark(textWatermark);
List<CreateTranscodingRequest.Watermark> watermarks = new ArrayList<CreateTranscodingRequest.Watermark>();
watermarks.add(watermark);
CreateTranscodingRequest.Watermark[] watermarkArray = new CreateTranscodingRequest.Watermark[watermarks.size()];
createTranscodingRequest.setWatermarks(watermarks.toArray(watermarkArray));
//发送媒体处理服务请求
CreateTranscodingResponse createTranscodingResponse = mpcClient.createTranscodingTask(createTranscodingRequest);
//返回消息
log.info(new Gson().toJson(createTranscodingResponse));
}
private static QueryTranscodingResponse getTranscodeJob(String taskId, String bucketName) throws FileException {
MpcClient mpcClient = initMpcClient();
//设置查询转码任务ID
QueryTranscodingRequest queryTranscodingRequest=new QueryTranscodingRequest();
queryTranscodingRequest.setTaskId(taskId);
//发送查询转码任务请求
QueryTranscodingResponse queryTranscodingResponse=mpcClient.queryTranscodingTask(queryTranscodingRequest);
System.out.println(new Gson().toJson(queryTranscodingResponse));
return queryTranscodingResponse;
}
@GetMapping("getTranscodeJob")
public ResponseDto<?> getTranscodeJob(@RequestParam("taskId") String taskId){
QueryTranscodingResponse response = getTranscodeJob(taskId,"test");
return new ResponseDto<>(response);
}
@GetMapping("submitTranscodeJobMp3")
public ResponseDto<?> submitTranscodeJobMp3(){
String filePath = "E:\\KuGou\\Delacey - Dream It Possible.mp3";
String fileName = "test";
String str =OssUtils.submitTranscodeJobMp3(fileName,filePath);
return new ResponseDto<>(str);
}
@GetMapping("submitTranscodeJobMp302")
public ResponseDto<?>submitTranscodeJobMp302() throws IOException {
String filePath = "E:\\KuGou\\Delacey - Dream It Possible.mp3";
InputStream in = new FileInputStream(filePath);
byte[] data = toByteArray(in);
return new ResponseDto<>(OssUtils.submitTranscodeJobMp3(data,"test","mp3"));
}
@GetMapping("submitTranscodeJobMp303")
public ResponseDto<?>submitTranscodeJobMp303() throws FileNotFoundException {
String filePath = "E:\\KuGou\\Delacey - Dream It Possible.mp3";
InputStream in = new FileInputStream(filePath);
return new ResponseDto<>(OssUtils.submitTranscodeJobMp3(in,"test","mp3"));
}
@GetMapping("submitTranscodeJobMp4")
public ResponseDto<?> submitTranscodeJobMp4(){
String filePath = "C:\\Users\\HP\\Desktop\\temp\\test.mp4";
String fileName = "test";
String str =OssUtils.submitTranscodeJobMp4(fileName,filePath);
return new ResponseDto<>(str);
}
@GetMapping("submitTranscodeJobMp402")
public ResponseDto<?>submitTranscodeJobMp402() throws IOException {
String filePath = "C:\\Users\\HP\\Desktop\\temp\\test.mp4";
InputStream in = new FileInputStream(filePath);
byte[] data = toByteArray(in);
return new ResponseDto<>(OssUtils.submitTranscodeJobMp4(data,"test","mp4"));
}
@GetMapping("getOSSResult")
public ResponseDto<?> getOSSResult(@RequestParam("transcodeJobId") String transcodeJobId){
return new ResponseDto<>(OssUtils.getOSSResult(transcodeJobId));
}
@GetMapping("getOSSResultByRegion")
public ResponseDto<?> getOSSResultByRegion(@RequestParam("transcodeJobId") String transcodeJobId, @RequestParam("buckectName") String buckectName){
return new ResponseDto<>(OssUtils.getOSSResultByRegion(transcodeJobId,buckectName));
}
@GetMapping("submitTranscodeJobSync")
public ResponseDto<?>submitTranscodeJobSync(@RequestParam("fileUrl") String fileUrl){
return new ResponseDto(OssUtils.submitTranscodeJobSync(fileUrl));
}
@GetMapping("submitThumbnailRequest")
public ResponseDto<?> submitThumbnailRequest(@RequestParam("fileUrl") String fileUrl){
return new ResponseDto<>(OssUtils.submitSnapshotJob(fileUrl,10));
}
private static void createThumbnail(){
MpcClient mpcClient = initMpcClient();
// 设置创建截图模板的请求参数
CreateThumbnailRequest createThumbnailRequest = new CreateThumbnailRequest();
// 设置截图源文件地址
ObsObjInfo input = new ObsObjInfo();
//OBS桶名
input.setBucket("whlg-oss-test-002");
//OBS下媒资路径
input.setObject("oss/transcode/video/mp4/test_20200529160425176.mp4");
//OBS桶所在区域
input.setLocation("cn-east-2");
createThumbnailRequest.setInput(input);
// 设置截图后文件存放地址
ObsObjInfo output = new ObsObjInfo();
output.setBucket("whlg-oss-test-002");
output.setObject("oss/transcode/video/mp4/");
output.setLocation("cn-east-2");
createThumbnailRequest.setOutput(output);
// 设置截图参数
CreateThumbnailRequest.ThumbnailPara thumbnailPara = new CreateThumbnailRequest.ThumbnailPara();
//采样类型。支持三种采样方式PERCENT、TIME和DOTS(根据时间间隔time,根据视频时长百分比percent,根据时间截图时的时间点数组dots,目前只支持TIME和DOTS两种方式)
thumbnailPara.setType(CreateThumbnailRequest.ThumbnailPara.TypeEnum.TIME);
thumbnailPara.setTime(12);
thumbnailPara.setStartTime(3);
thumbnailPara.setDuration(3);
//设置最大长度,范围(380,3840)
thumbnailPara.setMaxLength(480);
//设置纵横比(min = 0, max = 1)
thumbnailPara.setAspectRatio(0);
//设置截图格式,0表示默认,1表示JPG格式
thumbnailPara.setFormat(1);
createThumbnailRequest.setThumbnailPara(thumbnailPara);
// 发送创建截图任务请求给媒体处理服务
CreateThumbnailResponse createThumbnailResponse = mpcClient.createThumbnailsTask(createThumbnailRequest);
// 返回消息
System.out.println(new Gson().toJson(createThumbnailResponse));
}
private static void getThumbnail(String taskId){
MpcClient mpcClient = initMpcClient();
// 设置创建水印模板的请求参数
QueryThumbTaskRequest queryThumbTaskRequest = new QueryThumbTaskRequest();
//根据任务ID查询,最多支持10个任务ID
queryThumbTaskRequest.setTaskId(new String[]{taskId});
// 发送查询截图任务请求给媒体处理服务
QueryThumbTaskResponse queryThumbTaskResponse = mpcClient.queryThumbnailsTask(queryThumbTaskRequest);
// 返回消息
System.out.println(new Gson().toJson(queryThumbTaskResponse));
}
}
package com.pcloud.common.utils.aliyun.test;
import com.obs.services.model.ObjectMetadata;
import com.pcloud.common.dto.OssMediaInfoDTO;
import com.pcloud.common.entity.UploadResultInfo;
import com.pcloud.common.exceptions.FileException;
import com.pcloud.common.utils.aliyun.OssUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
* @ClassName com.pcloud.auditcenter.hw.utils.test.ObsTest
* @Author 吴博
* @Description 华为云测试类
* @Date 2020/5/24 9:27
* @Version 1.0
**/
@RestController
@RequestMapping("obsTest")
@Slf4j
public class ObsTest {
private static final String textFilePath = "C:\\Users\\Administrator\\Desktop\\sql.txt";
private static final String audioFilePath = "C:\\Users\\Administrator\\Desktop\\123321.mp3";
private static final String imageFilePath = "C:\\Users\\Administrator\\Desktop\\girl.jpg";
private static final String imageFileUrl = "https://oss.raysgo.com/oss/upload/image/jpg/add52c60c88a4989bdf6bdb554b5f928.jpg";
private static final String videoFilePath = "C:\\Users\\Administrator\\Desktop\\e610844f3210d9e249fc8ee0cc6b9a1b_20190815173921219.mp4";
private static final String parentFileUrl = "https://oss.raysgo.com/oss/upload/video/mp4/b2f2df50279d43b4af52ebb760924e08";
private static final String videoUrl = "https://oss.raysgo.com/oss/upload/video/mp4/e297ea15516146acabbbcb8c31fe0f92.mp4";
private static final String ObjectKey = "oss/upload/video/mp4/b2f2df50279d43b4af52ebb760924e08.mp4";
private static final String textUrl = "https://oss.raysgo.com/oss/upload/text/txt/4b19722b10604da282497b80c77860fe.txt";
private static final String outFilePath4Mp3 = "C:\\Users\\Administrator\\Desktop\\localaudio.mp3";
private static final String outFilePath4Mp4 = "C:\\Users\\Administrator\\Desktop\\localVideo.mp4";
private static final String huaweiImage = "C:\\Users\\Administrator\\Desktop\\1588081459(1).png";
private static final String huaweiImageUrl = "https://oss.raysgo.com/oss/upload/image/png/7348e76b4a654fdbbccf3a2adbe0d028.png";
@RequestMapping(value = "uploadFileByte", method = RequestMethod.GET)
public UploadResultInfo uploadFileByte() throws FileException {
String content = "Hello OBS";
byte[] buff = content.getBytes();
String fileName = "";
String fileType = "txt";
UploadResultInfo uploadResultInfo = OssUtils.uploadFileByte(buff, fileName, fileType);
log.info(uploadResultInfo.toString());
return uploadResultInfo;
}
@RequestMapping(value = "uploadLocalFile", method = RequestMethod.GET)
public UploadResultInfo uploadLocalFile() throws FileException {
String content = "Hello OBS";
byte[] buff = content.getBytes();
String fileName = "";
String fileType = "txt";
UploadResultInfo uploadResultInfo = OssUtils.uploadLocalFile(videoFilePath,null);
log.info(uploadResultInfo.toString());
return uploadResultInfo;
}
@RequestMapping(value = "uploadLocalFile4Child", method = RequestMethod.GET)
public UploadResultInfo uploadLocalFile4Child() throws FileException {
String content = "Hello OBS";
byte[] buff = content.getBytes();
String fileName = "";
String fileType = "txt";
UploadResultInfo uploadResultInfo = OssUtils.uploadLocalFile4Child(audioFilePath,parentFileUrl);
log.info(uploadResultInfo.toString());
return uploadResultInfo;
}
@RequestMapping(value = "getMediaInfo", method = RequestMethod.GET)
public OssMediaInfoDTO getMediaInfo() throws FileException {
String content = "Hello OBS";
byte[] buff = content.getBytes();
String fileName = "";
String fileType = "txt";
OssMediaInfoDTO ossMediaInfoDTO = OssUtils.getMediaInfo(videoUrl);
log.info(ossMediaInfoDTO.toString());
return ossMediaInfoDTO;
}
@RequestMapping(value = "getObjectMetadata", method = RequestMethod.GET)
public ObjectMetadata getObjectMetadata() throws FileException {
String content = "Hello OBS";
byte[] buff = content.getBytes();
String fileName = "";
String fileType = "txt";
ObjectMetadata objectMetadata = OssUtils.getObjectMetadata(ObjectKey,"whlg-oss-test-002");
log.info(objectMetadata.toString());
return objectMetadata;
}
@RequestMapping(value = "downloadFile2Byte", method = RequestMethod.GET)
public String downloadFile2Byte() throws FileException {
String content = "Hello OBS";
byte[] buff = content.getBytes();
String fileName = "";
String fileType = "txt";
byte[] bytes = OssUtils.downloadFile2Byte(textUrl);
log.info(new String (bytes));
return new String (bytes);
}
@RequestMapping(value = "downloadFile", method = RequestMethod.GET)
public void downloadFile() throws FileException {
String content = "Hello OBS";
byte[] buff = content.getBytes();
String fileName = "";
String fileType = "txt";
OssUtils.downloadFile(videoUrl,outFilePath4Mp4);
}
@RequestMapping(value = "imageWidthResize", method = RequestMethod.GET)
public void imageWidthResize() throws FileException {
String content = "Hello OBS";
byte[] buff = content.getBytes();
String fileName = "";
String fileType = "txt";
OssUtils.imageWidthResize(imageFileUrl,100);
}
@RequestMapping(value = "imageResize", method = RequestMethod.GET)
public void imageResize() throws FileException {
String content = "Hello OBS";
byte[] buff = content.getBytes();
String fileName = "";
String fileType = "txt";
OssUtils.imageResize(imageFileUrl,50);
}
@RequestMapping(value = "imageAutoOrient", method = RequestMethod.GET)
public void imageAutoOrient() throws FileException {
String content = "Hello OBS";
byte[] buff = content.getBytes();
String fileName = "";
String fileType = "txt";
OssUtils.imageAutoOrient(imageFileUrl,50);
}
@RequestMapping(value = "imageCrop", method = RequestMethod.GET)
public void imageCrop() throws FileException {
String content = "Hello OBS";
byte[] buff = content.getBytes();
String fileName = "";
String fileType = "txt";
OssUtils.imageCrop(imageFileUrl,500,500,0,0);
}
@RequestMapping(value = "imageCropSaveas", method = RequestMethod.GET)
public void imageCropSaveas() throws FileException {
OssUtils.imageCropSaveas(imageFileUrl,500,500,0,0);
}
@RequestMapping(value = "imageWatermark", method = RequestMethod.GET)
public void imageWatermark() throws FileException {
String waterMark = OssUtils.imageWatermark(imageFileUrl,"哈哈哈哈,大笨蛋");
log.info(waterMark);
}
@RequestMapping(value = "imageWatermark4Image", method = RequestMethod.GET)
public void imageWatermark4Image() throws FileException {
String waterMark = OssUtils. imageWatermark4Image(imageFileUrl,huaweiImageUrl);
log.info(waterMark);
}
}
\ No newline at end of file
......@@ -106,6 +106,7 @@
<!-- frameworks -->
<slf4j.version>1.7.18</slf4j.version>
<mpc-sdk-version>2.0.7</mpc-sdk-version>
</properties>
<dependencies>
......@@ -306,6 +307,11 @@
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>com.huaweicloud</groupId>
<artifactId>esdk-obs-java</artifactId>
<version>3.19.7</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-mts</artifactId>
<version>2.1.7</version>
......@@ -319,6 +325,29 @@
<version>1.9.13</version>
</dependency>
<!-- Jackson End -->
<dependency>
<groupId>com.huawei.mpc</groupId>
<artifactId>cloud-java-sdk-mpc</artifactId>
<version>${mpc-sdk-version}</version>
<exclusions>
<exclusion>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>2.5.0</version>
<!--<exclusions>
<exclusion>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</exclusion>
</exclusions>-->
</dependency>
</dependencies>
</dependencyManagement>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment