Search in sources :

Example 1 with MediaWaterMarkImage

use of com.qcloud.cos.model.ciModel.template.MediaWaterMarkImage 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)

Example 2 with MediaWaterMarkImage

use of com.qcloud.cos.model.ciModel.template.MediaWaterMarkImage in project cos-java-sdk-v5 by tencentyun.

the class RequestXmlFactory method convertToXmlByteArray.

/**
 * Converts the MediaTemplateRequest to an XML fragment that can be sent to the TemplateObject of COS MediaTemplate
 *
 * @param request The container which provides options for restoring an object
 * @return A byte array containing the data
 * @throws CosClientException
 */
public static byte[] convertToXmlByteArray(MediaTemplateRequest request) {
    XmlWriter xml = new XmlWriter();
    String tag = request.getTag();
    xml.start("Request");
    xml.start("Tag").value(tag).end();
    xml.start("Name").value(request.getName()).end();
    if ("Animation".equalsIgnoreCase(tag)) {
        xml.start("Container");
        xml.start("Format").value(request.getContainer().getFormat()).end();
        xml.end();
        addVideo(xml, request);
        if (CheckObjectUtils.objIsNotValid(request.getTimeInterval())) {
            xml.start("TimeInterval");
            xml.start("Duration").value(request.getTimeInterval().getDuration()).end();
            xml.start("Start").value(request.getTimeInterval().getStart()).end();
            xml.end();
        }
    } else if ("Snapshot".equalsIgnoreCase(tag)) {
        if (CheckObjectUtils.objIsNotValid(request.getSnapshot())) {
            xml.start("Snapshot");
            MediaSnapshotObject snapshot = request.getSnapshot();
            addIfNotNull(xml, "Mode", snapshot.getMode());
            addIfNotNull(xml, "Count", snapshot.getCount());
            addIfNotNull(xml, "Fps", snapshot.getFps());
            addIfNotNull(xml, "Height", snapshot.getHeight());
            addIfNotNull(xml, "Start", snapshot.getStart());
            addIfNotNull(xml, "TimeInterval", snapshot.getTimeInterval());
            addIfNotNull(xml, "Width", snapshot.getWidth());
            xml.end();
        }
    } else if ("Watermark".equalsIgnoreCase(tag)) {
        xml.start("Watermark");
        addIfNotNull(xml, "Type", request.getWatermark().getType());
        addIfNotNull(xml, "Dx", request.getWatermark().getDx());
        addIfNotNull(xml, "Dy", request.getWatermark().getDy());
        addIfNotNull(xml, "EndTime", request.getWatermark().getEndTime());
        addIfNotNull(xml, "LocMode", request.getWatermark().getLocMode());
        addIfNotNull(xml, "Pos", request.getWatermark().getPos());
        addIfNotNull(xml, "StartTime", request.getWatermark().getStartTime());
        if ("Text".equalsIgnoreCase(request.getWatermark().getType())) {
            xml.start("Text");
            MediaWaterMarkText text = request.getWatermark().getText();
            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(request.getWatermark().getType())) {
            xml.start("Image");
            MediaWaterMarkImage image = request.getWatermark().getImage();
            addIfNotNull(xml, "Height", image.getHeight());
            addIfNotNull(xml, "Mode", image.getMode());
            addIfNotNull(xml, "Url", image.getUrl());
            addIfNotNull(xml, "Transparency", image.getTransparency());
            addIfNotNull(xml, "Width", image.getWidth());
            xml.end();
        }
        xml.end();
    } else if ("Transcode".equalsIgnoreCase(tag)) {
        xml.start("Container");
        xml.start("Format").value(request.getContainer().getFormat()).end();
        xml.end();
        xml.start("TimeInterval");
        xml.start("Duration").value(request.getTimeInterval().getDuration()).end();
        xml.start("Start").value(request.getTimeInterval().getStart()).end();
        xml.end();
        addAudio(xml, request.getAudio());
        xml.start("TransConfig");
        addIfNotNull(xml, "AdjDarMethod", request.getTransConfig().getAdjDarMethod());
        addIfNotNull(xml, "AudioBitrateAdjMethod", request.getTransConfig().getAudioBitrateAdjMethod());
        addIfNotNull(xml, "IsCheckAudioBitrate", request.getTransConfig().getIsCheckAudioBitrate());
        addIfNotNull(xml, "IsCheckReso", request.getTransConfig().getIsCheckReso());
        addIfNotNull(xml, "IsCheckVideoBitrate", request.getTransConfig().getIsCheckVideoBitrate());
        addIfNotNull(xml, "ResoAdjMethod", request.getTransConfig().getResoAdjMethod());
        addIfNotNull(xml, "TransMode", request.getTransConfig().getTransMode());
        addIfNotNull(xml, "VideoBitrateAdjMethod", request.getTransConfig().getVideoBitrateAdjMethod());
        xml.end();
        addVideo(xml, request);
    }
    xml.end();
    return xml.getBytes();
}
Also used : MediaWaterMarkText(com.qcloud.cos.model.ciModel.template.MediaWaterMarkText) MediaWaterMarkImage(com.qcloud.cos.model.ciModel.template.MediaWaterMarkImage) MediaSnapshotObject(com.qcloud.cos.model.ciModel.template.MediaSnapshotObject)

Aggregations

MediaWaterMarkImage (com.qcloud.cos.model.ciModel.template.MediaWaterMarkImage)2 MediaWaterMarkText (com.qcloud.cos.model.ciModel.template.MediaWaterMarkText)2 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 MediaSnapshotObject (com.qcloud.cos.model.ciModel.template.MediaSnapshotObject)1 MediaWatermark (com.qcloud.cos.model.ciModel.template.MediaWatermark)1