Search in sources :

Example 1 with MediaConcatTemplateObject

use of com.qcloud.cos.model.ciModel.job.MediaConcatTemplateObject 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();
}
Also used : MediaTranscodeObject(com.qcloud.cos.model.ciModel.job.MediaTranscodeObject) MediaAudioObject(com.qcloud.cos.model.ciModel.job.MediaAudioObject) MediaTimeIntervalObject(com.qcloud.cos.model.ciModel.job.MediaTimeIntervalObject) MediaWatermark(com.qcloud.cos.model.ciModel.template.MediaWatermark) MediaRemoveWaterMark(com.qcloud.cos.model.ciModel.job.MediaRemoveWaterMark) MediaConcatTemplateObject(com.qcloud.cos.model.ciModel.job.MediaConcatTemplateObject) MediaConcatFragmentObject(com.qcloud.cos.model.ciModel.job.MediaConcatFragmentObject) MediaTransConfigObject(com.qcloud.cos.model.ciModel.job.MediaTransConfigObject) MediaJobOperation(com.qcloud.cos.model.ciModel.job.MediaJobOperation) MediaWaterMarkText(com.qcloud.cos.model.ciModel.template.MediaWaterMarkText) MediaWaterMarkImage(com.qcloud.cos.model.ciModel.template.MediaWaterMarkImage) MediaTranscodeVideoObject(com.qcloud.cos.model.ciModel.job.MediaTranscodeVideoObject)

Aggregations

MediaAudioObject (com.qcloud.cos.model.ciModel.job.MediaAudioObject)1 MediaConcatFragmentObject (com.qcloud.cos.model.ciModel.job.MediaConcatFragmentObject)1 MediaConcatTemplateObject (com.qcloud.cos.model.ciModel.job.MediaConcatTemplateObject)1 MediaJobOperation (com.qcloud.cos.model.ciModel.job.MediaJobOperation)1 MediaRemoveWaterMark (com.qcloud.cos.model.ciModel.job.MediaRemoveWaterMark)1 MediaTimeIntervalObject (com.qcloud.cos.model.ciModel.job.MediaTimeIntervalObject)1 MediaTransConfigObject (com.qcloud.cos.model.ciModel.job.MediaTransConfigObject)1 MediaTranscodeObject (com.qcloud.cos.model.ciModel.job.MediaTranscodeObject)1 MediaTranscodeVideoObject (com.qcloud.cos.model.ciModel.job.MediaTranscodeVideoObject)1 MediaWaterMarkImage (com.qcloud.cos.model.ciModel.template.MediaWaterMarkImage)1 MediaWaterMarkText (com.qcloud.cos.model.ciModel.template.MediaWaterMarkText)1 MediaWatermark (com.qcloud.cos.model.ciModel.template.MediaWatermark)1