Commit e9e40a82 authored by 张永's avatar 张永

调整 阿里云接口,创建转码模板

parent 3f52e3fb
......@@ -12,12 +12,16 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.vod.model.v20170321.CreateUploadVideoResponse;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import com.aliyuncs.vod.model.v20170321.RefreshUploadVideoResponse;
import com.egolm.common.HttpUtil;
import com.egolm.common.StringUtil;
import com.egolm.common.bean.Rjx;
import com.egolm.film.api.service.Messages;
import com.egolm.film.util.AliyunSign;
import com.egolm.film.util.AliyunUtil;
import io.swagger.annotations.Api;
......@@ -36,6 +40,10 @@ public class AliyunApiController {
@Value("${aliyun.sts.accessKeySecret}")
private String accessKeySecret;
@Value("${aliyun.video.templateId}")
private String templateId;
@Autowired
private Messages messages;
......@@ -74,7 +82,7 @@ public class AliyunApiController {
return Rjx.jsonOk().set("RequestId", response.getRequestId()).set("UploadAuth", response.getUploadAuth())
.set("UploadAddress", response.getUploadAddress())
.set("VideoId", response.getVideoId());
.set("VideoId", response.getVideoId()).set("templateId", templateId);
}
......@@ -93,7 +101,7 @@ public class AliyunApiController {
AliyunUtil aliyunUtil = new AliyunUtil(accessKeyId,accessKeySecret);
RefreshUploadVideoResponse response = aliyunUtil.refreshUploadVideo(videoId);
if(response != null) {
return Rjx.jsonOk().set("RequestId", response.getRequestId()).set("UploadAuth", response.getUploadAuth()).set("UploadAddress", response.getUploadAddress());
return Rjx.jsonOk().set("RequestId", response.getRequestId()).set("UploadAuth", response.getUploadAuth()).set("UploadAddress", response.getUploadAddress()).set("templateId", templateId);
}else {
return Rjx.jsonErr().setCode(-1).setMessage("InvalidVideo.NotFound : The video does not exist.");
}
......@@ -129,5 +137,109 @@ public class AliyunApiController {
}
}
/**
* https://help.aliyun.com/document_detail/52839.html?spm=a2c4g.11186623.2.16.56da9028Qxc5wl#TranscodeTemplate
* @Title: transcode
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @param request
* @param: @return
* @return: Object
* @throws
*/
@ResponseBody
@ApiOperation("新增视频转码模板")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "templateName", dataType = "String", required = true, value = "转码组名称", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "watermarkIds", dataType = "String", required = true, value = "水印ID(值来源于水印管理)", defaultValue = ""),
})
@RequestMapping(value = "/addTranscodeTemplate",method=RequestMethod.GET)
public Object addTranscodeTemplate(HttpServletRequest request) {
String templateName = request.getParameter("templateName");
String watermarkIds = request.getParameter("watermarkIds");
if(!StringUtil.isNotEmpty(templateName,watermarkIds)) {
return Rjx.jsonErr().setCode(-1).setMessage("参数不能为空");
}
//模板参数信息
JSONObject videoObj = new JSONObject();
videoObj.put("Codec", "H.264");
videoObj.put("Bitrate", "900");
videoObj.put("Width", "960");
videoObj.put("Height", "540");
videoObj.put("Remove",false);
videoObj.put("Fps", "25");
videoObj.put("Gop", "250");
JSONObject audioObj = new JSONObject();
audioObj.put("Codec", "AAC");
audioObj.put("Bitrate", "96");
audioObj.put("Remove", false);
audioObj.put("Samplerate", "44100");
audioObj.put("Channels", "2");
JSONObject containerObj = new JSONObject();
containerObj.put("Format", "m3u8"); //填m3u8 生成的格式就为 hls
JSONObject muxConfigObj = new JSONObject();
JSONObject segmentObj = new JSONObject();
segmentObj.put("Duration", "10");
muxConfigObj.put("Segment", segmentObj);
JSONObject encryptSettingObj = new JSONObject();
encryptSettingObj.put("EncryptType", "Private");
JSONObject packageSettingObj = new JSONObject();
packageSettingObj.put("PackageType", "HLSPackage");
JSONObject packageConfigObj = new JSONObject();
packageConfigObj.put("BandWidth", "900000");
packageSettingObj.put("PackageConfig",packageConfigObj);
JSONObject obj = new JSONObject();
obj.put("Video",videoObj);
obj.put("Audio", audioObj);
obj.put("Container", containerObj);
obj.put("MuxConfig", muxConfigObj);
obj.put("EncryptSetting", encryptSettingObj);
//obj.put("PackageSetting", packageSettingObj);
obj.put("WatermarkIds", watermarkIds);
obj.put("Definition", "SD"); //原画
obj.put("TemplateName",templateName);
JSONArray array = new JSONArray();
array.add(obj);
//生成私有参数,不同API需要修改
Map<String,String> privateParams = new HashMap<String,String>();
privateParams.put("Action", "AddTranscodeTemplateGroup");
privateParams.put("Name", templateName);
privateParams.put("TranscodeTemplateList", array.toJSONString());
System.out.println(array.toJSONString());
//生成公共参数,不需要修改
Map<String, String> publicParams = AliyunSign.generatePublicParamters();
//生成OpenAPI地址,不需要修改
String URL = AliyunSign.generateOpenAPIURL(publicParams, privateParams);
//发送HTTP GET 请求
String result = HttpUtil.get(URL);
System.out.println(result);
return result;
}
}
......@@ -213,7 +213,7 @@ public class AliyunUtil {
// API名称
privateParams.put("Action", "GetVideoPlayAuth");
String url = AliyunSign.generateURL("GET", this.accessKeyId, publicParams, privateParams);
String url = AliyunSign.generateOpenAPIURL( publicParams, privateParams);
String result = HttpsUtil.doGet(url);
System.out.println(result);
......
......@@ -36,5 +36,6 @@ spring.datasource.min-idle=10
aliyun.sts.accessKeyId=LTAIOtHCCpDLXYp8
aliyun.sts.accessKeySecret=9XTHW7P9TTRvCsBHBSclOue2tdWOoa
#\u89C6\u9891\u8F6C\u7801ID
aliyun.video.templateId=d9f4a79cba14ce4cbc98d6516d35bf37
opt.project.type=1
\ No newline at end of file
......@@ -35,5 +35,6 @@ spring.datasource.min-idle=10
aliyun.sts.accessKeyId=LTAIOtHCCpDLXYp8
aliyun.sts.accessKeySecret=9XTHW7P9TTRvCsBHBSclOue2tdWOoa
#\u89C6\u9891\u8F6C\u7801ID
aliyun.video.templateId=d9f4a79cba14ce4cbc98d6516d35bf37
opt.project.type=1
\ No newline at end of file
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