use of com.qcloud.cos.model.ciModel.job.MediaTimeIntervalObject in project cos-java-sdk-v5 by tencentyun.
the class RequestXmlFactory method convertToXmlByteArray.
/**
* Converts the MediaJobsRequest to an XML fragment that can be sent to the JobObject of COS
*
* @param request The container which provides options for restoring an object
* @return A byte array containing the data
* @throws CosClientException
*/
public static byte[] convertToXmlByteArray(MediaJobsRequest request) {
XmlWriter xml = new XmlWriter();
xml.start("Request");
xml.start("Tag").value(request.getTag()).end();
xml.start("BucketName").value(request.getBucketName()).end();
xml.start("Input");
xml.start("Object").value(request.getInput().getObject()).end();
xml.end();
MediaJobOperation operation = request.getOperation();
xml.start("Operation");
addIfNotNull(xml, "TemplateId", operation.getTemplateId());
List<String> watermarkTemplateId = operation.getWatermarkTemplateId();
if (watermarkTemplateId.size() != 0) {
for (String templateId : watermarkTemplateId) {
xml.start("WatermarkTemplateId").value(templateId).end();
}
}
MediaWatermark watermark = operation.getWatermark();
if (CheckObjectUtils.objIsNotValid(watermark)) {
addIfNotNull(xml, "Type", watermark.getType());
addIfNotNull(xml, "Dx", watermark.getDx());
addIfNotNull(xml, "Dy", watermark.getDy());
addIfNotNull(xml, "EndTime", watermark.getEndTime());
addIfNotNull(xml, "LocMode", watermark.getLocMode());
addIfNotNull(xml, "Pos", watermark.getPos());
addIfNotNull(xml, "StartTime", watermark.getStartTime());
if ("Text".equalsIgnoreCase(watermark.getType())) {
MediaWaterMarkText text = watermark.getText();
xml.start("Text");
addIfNotNull(xml, "FontColor", text.getFontColor());
addIfNotNull(xml, "FontSize", text.getFontSize());
addIfNotNull(xml, "FontType", text.getFontType());
addIfNotNull(xml, "Text", text.getText());
addIfNotNull(xml, "Transparency", text.getTransparency());
xml.end();
} else if ("Image".equalsIgnoreCase(watermark.getType())) {
MediaWaterMarkImage image = watermark.getImage();
xml.start("Image");
addIfNotNull(xml, "Height", image.getHeight());
addIfNotNull(xml, "Mode", image.getMode());
addIfNotNull(xml, "Transparency", image.getTransparency());
addIfNotNull(xml, "Url", image.getUrl());
addIfNotNull(xml, "Width", image.getWidth());
xml.end();
}
}
MediaRemoveWaterMark removeWatermark = operation.getRemoveWatermark();
if (CheckObjectUtils.objIsNotValid(removeWatermark)) {
xml.start("RemoveWatermark");
addIfNotNull(xml, "Height", removeWatermark.getHeight());
addIfNotNull(xml, "Dx", removeWatermark.getDx());
addIfNotNull(xml, "Dy", removeWatermark.getDy());
addIfNotNull(xml, "Switch", removeWatermark.get_switch());
addIfNotNull(xml, "Width", removeWatermark.getWidth());
xml.end();
}
MediaConcatTemplateObject mediaConcatTemplate = operation.getMediaConcatTemplate();
if (CheckObjectUtils.objIsNotValid(mediaConcatTemplate)) {
xml.start("ConcatTemplate");
List<MediaConcatFragmentObject> concatFragmentList = mediaConcatTemplate.getConcatFragmentList();
for (MediaConcatFragmentObject concatFragment : concatFragmentList) {
xml.start("ConcatFragment");
addIfNotNull(xml, "Mode", concatFragment.getMode());
addIfNotNull(xml, "Url", concatFragment.getUrl());
xml.end();
}
addVideo(xml, mediaConcatTemplate.getVideo());
addAudio(xml, mediaConcatTemplate.getAudio());
addIfNotNull(xml, "Index", mediaConcatTemplate.getIndex());
String format = mediaConcatTemplate.getContainer().getFormat();
if (!StringUtils.isNullOrEmpty(format)) {
xml.start("Container");
xml.start("Format").value(format).end();
xml.end();
}
xml.end();
}
MediaTranscodeObject transcode = operation.getTranscode();
String format = transcode.getContainer().getFormat();
if (CheckObjectUtils.objIsNotValid(transcode) && !StringUtils.isNullOrEmpty(format)) {
xml.start("Transcode");
MediaTranscodeVideoObject video = transcode.getVideo();
MediaAudioObject audio = transcode.getAudio();
MediaTransConfigObject transConfig = transcode.getTransConfig();
MediaTimeIntervalObject timeInterval = transcode.getTimeInterval();
if (format != null) {
xml.start("Container");
xml.start("Format").value(format).end();
xml.end();
}
if (CheckObjectUtils.objIsNotValid(timeInterval)) {
xml.start("TimeInterval");
xml.start("Duration").value(timeInterval.getDuration()).end();
xml.start("Start").value(timeInterval.getStart()).end();
xml.end();
}
if (CheckObjectUtils.objIsNotValid(video)) {
addVideo(xml, video);
}
if (CheckObjectUtils.objIsNotValid(audio)) {
addAudio(xml, audio);
}
if (CheckObjectUtils.objIsNotValid(transConfig)) {
xml.start("TransConfig");
addIfNotNull(xml, "AdjDarMethod", transConfig.getAdjDarMethod());
addIfNotNull(xml, "AudioBitrateAdjMethod", transConfig.getAudioBitrateAdjMethod());
addIfNotNull(xml, "IsCheckAudioBitrate", transConfig.getIsCheckAudioBitrate());
addIfNotNull(xml, "IsCheckReso", transConfig.getIsCheckReso());
addIfNotNull(xml, "IsCheckVideoBitrate", transConfig.getIsCheckVideoBitrate());
addIfNotNull(xml, "ResoAdjMethod", transConfig.getResoAdjMethod());
addIfNotNull(xml, "TransMode", transConfig.getTransMode());
addIfNotNull(xml, "VideoBitrateAdjMethod", transConfig.getVideoBitrateAdjMethod());
xml.end();
}
xml.end();
}
xml.start("Output");
xml.start("Region").value(operation.getOutput().getRegion()).end();
xml.start("Object").value(operation.getOutput().getObject()).end();
xml.start("Bucket").value(operation.getOutput().getBucket()).end();
xml.end();
xml.end();
xml.start("QueueId").value(request.getQueueId()).end();
addIfNotNull(xml, "CallBack", request.getCallBack());
xml.end();
return xml.getBytes();
}
use of com.qcloud.cos.model.ciModel.job.MediaTimeIntervalObject in project cos-java-sdk-v5 by tencentyun.
the class JobDemo method createMediaJobs2.
/**
* createMediaJobs 接口用于创建媒体任务
* demo 使用转码参数创建任务 推荐使用模板创建媒体任务
*
* @param client
*/
public static void createMediaJobs2(COSClient client) throws UnsupportedEncodingException {
// 1.创建任务请求对象
MediaJobsRequest request = new MediaJobsRequest();
// 2.添加请求参数 参数详情请见api接口文档
request.setBucketName("DemoBucket-123456789");
request.setTag("Transcode");
request.getInput().setObject("1.mp4");
// 2.1添加媒体任务操作参数
MediaTranscodeObject transcode = request.getOperation().getTranscode();
MediaContainerObject container = transcode.getContainer();
container.setFormat("mp4");
MediaTranscodeVideoObject video = transcode.getVideo();
video.setCodec("H.264");
video.setProfile("high");
video.setBitrate("1000");
video.setWidth("1280");
video.setFps("30");
video.setPreset("medium");
video.setBufSize("0");
video.setMaxrate("50000");
MediaAudioObject audio = transcode.getAudio();
audio.setCodec("aac");
audio.setSamplerate("44100");
audio.setBitrate("128");
audio.setChannels("4");
MediaTimeIntervalObject timeInterval = transcode.getTimeInterval();
timeInterval.setStart("0");
timeInterval.setDuration("60");
MediaTransConfigObject transConfig = transcode.getTransConfig();
// transConfig.setAdjDarMethod("scale");
// transConfig.setIsCheckAudioBitrate("false");
// transConfig.setResoAdjMethod("1");
request.getOperation().getOutput().setBucket("DemoBucket-123456789");
request.getOperation().getOutput().setRegion("ap-chongqing");
request.getOperation().getOutput().setObject("demo1.mp4");
request.setQueueId("p9900025e4ec44b5e8225e70a5217****");
request.setCallBack("https://cloud.tencent.com/xxx");
// 3.调用接口,获取任务响应对象
MediaJobResponse response = client.createMediaJobs(request);
System.out.println(response.getJobsDetail().getOperation().getTranscode());
}
use of com.qcloud.cos.model.ciModel.job.MediaTimeIntervalObject in project cos-java-sdk-v5 by tencentyun.
the class TranscodeTemplateDemo method createMediaTemplate.
/**
* CreateMediaTemplate 用于新增转码模板。
*
* @param client
*/
public static void createMediaTemplate(COSClient client) throws UnsupportedEncodingException {
// 1.创建模板请求对象
MediaTemplateRequest request = new MediaTemplateRequest();
// 2.添加请求参数 参数详情请见api接口文档
request.setBucketName("DemoBucket-123456789");
request.setTag("Transcode");
request.setName("mark-test-2");
request.getContainer().setFormat("mp4");
// 2.1 添加video对象的值
MediaVideoObject video = request.getVideo();
video.setCodec("H.264");
video.setProfile("high");
video.setBitrate("1000");
video.setWidth("1280");
video.setFps("30");
video.setPreset("medium");
video.setBufSize("1000");
video.setMaxrate("10");
// 2.2 添加audio对象的值
MediaAudioObject audio = request.getAudio();
audio.setCodec("aac");
audio.setSamplerate("44100");
audio.setBitrate("128");
audio.setChannels("1");
// 2.3 添加TransConfig对象的值
MediaTransConfigObject transConfig = request.getTransConfig();
transConfig.setAdjDarMethod("scale");
transConfig.setIsCheckReso("false");
transConfig.setResoAdjMethod("1");
// 2.4 添加TimeInterval对象的值
MediaTimeIntervalObject timeInterval = request.getTimeInterval();
timeInterval.setStart("0");
timeInterval.setDuration("60");
// 3. 调用接口 获取模板响应对象
MediaTemplateResponse response = client.createMediaTemplate(request);
System.out.println(response);
}
use of com.qcloud.cos.model.ciModel.job.MediaTimeIntervalObject in project cos-java-sdk-v5 by tencentyun.
the class TranscodeTemplateDemo method updateMediaTemplate.
/**
* UpdateMediaTemplate 用于更新转码模板。
*
* @param client
*/
public static void updateMediaTemplate(COSClient client) throws UnsupportedEncodingException {
// 1.创建模板请求对象
MediaTemplateRequest request = new MediaTemplateRequest();
// 2.添加请求参数 参数详情请见api接口文档
request.setBucketName("DemoBucket-123456789");
request.setTemplateId("t138b37dc82e59422d85f03bb7a8*****");
request.setTag("Transcode");
request.setName("mark-test-update-01");
request.getContainer().setFormat("mp4");
MediaVideoObject video = request.getVideo();
video.setCodec("H.264");
video.setProfile("high");
video.setBitrate("1000");
video.setWidth("1280");
video.setFps("30");
video.setPreset("medium");
video.setBufSize("1000");
video.setMaxrate("10");
MediaAudioObject audio = request.getAudio();
audio.setCodec("aac");
audio.setSamplerate("44100");
audio.setBitrate("128");
audio.setChannels("1");
MediaTransConfigObject transConfig = request.getTransConfig();
transConfig.setAdjDarMethod("scale");
transConfig.setIsCheckReso("false");
transConfig.setResoAdjMethod("1");
MediaTimeIntervalObject timeInterval = request.getTimeInterval();
timeInterval.setStart("1");
timeInterval.setDuration("30");
// 3.调用接口,获取模板响应对象
Boolean aBoolean = client.updateMediaTemplate(request);
System.out.println(aBoolean);
}
Aggregations