Search in sources :

Example 1 with MediaAudioObject

use of com.qcloud.cos.model.ciModel.job.MediaAudioObject 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 MediaAudioObject

use of com.qcloud.cos.model.ciModel.job.MediaAudioObject 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());
}
Also used : MediaJobsRequest(com.qcloud.cos.model.ciModel.job.MediaJobsRequest) MediaTranscodeObject(com.qcloud.cos.model.ciModel.job.MediaTranscodeObject) MediaJobResponse(com.qcloud.cos.model.ciModel.job.MediaJobResponse) MediaAudioObject(com.qcloud.cos.model.ciModel.job.MediaAudioObject) MediaTimeIntervalObject(com.qcloud.cos.model.ciModel.job.MediaTimeIntervalObject) MediaTranscodeVideoObject(com.qcloud.cos.model.ciModel.job.MediaTranscodeVideoObject) MediaTransConfigObject(com.qcloud.cos.model.ciModel.job.MediaTransConfigObject) MediaContainerObject(com.qcloud.cos.model.ciModel.job.MediaContainerObject)

Example 3 with MediaAudioObject

use of com.qcloud.cos.model.ciModel.job.MediaAudioObject 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);
}
Also used : MediaTemplateResponse(com.qcloud.cos.model.ciModel.template.MediaTemplateResponse) MediaAudioObject(com.qcloud.cos.model.ciModel.job.MediaAudioObject) MediaTimeIntervalObject(com.qcloud.cos.model.ciModel.job.MediaTimeIntervalObject) MediaTemplateRequest(com.qcloud.cos.model.ciModel.template.MediaTemplateRequest) MediaTransConfigObject(com.qcloud.cos.model.ciModel.job.MediaTransConfigObject) MediaVideoObject(com.qcloud.cos.model.ciModel.job.MediaVideoObject)

Example 4 with MediaAudioObject

use of com.qcloud.cos.model.ciModel.job.MediaAudioObject 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);
}
Also used : MediaAudioObject(com.qcloud.cos.model.ciModel.job.MediaAudioObject) MediaTimeIntervalObject(com.qcloud.cos.model.ciModel.job.MediaTimeIntervalObject) MediaTemplateRequest(com.qcloud.cos.model.ciModel.template.MediaTemplateRequest) MediaTransConfigObject(com.qcloud.cos.model.ciModel.job.MediaTransConfigObject) MediaVideoObject(com.qcloud.cos.model.ciModel.job.MediaVideoObject)

Aggregations

MediaAudioObject (com.qcloud.cos.model.ciModel.job.MediaAudioObject)4 MediaTimeIntervalObject (com.qcloud.cos.model.ciModel.job.MediaTimeIntervalObject)4 MediaTransConfigObject (com.qcloud.cos.model.ciModel.job.MediaTransConfigObject)4 MediaTranscodeObject (com.qcloud.cos.model.ciModel.job.MediaTranscodeObject)2 MediaTranscodeVideoObject (com.qcloud.cos.model.ciModel.job.MediaTranscodeVideoObject)2 MediaVideoObject (com.qcloud.cos.model.ciModel.job.MediaVideoObject)2 MediaTemplateRequest (com.qcloud.cos.model.ciModel.template.MediaTemplateRequest)2 MediaConcatFragmentObject (com.qcloud.cos.model.ciModel.job.MediaConcatFragmentObject)1 MediaConcatTemplateObject (com.qcloud.cos.model.ciModel.job.MediaConcatTemplateObject)1 MediaContainerObject (com.qcloud.cos.model.ciModel.job.MediaContainerObject)1 MediaJobOperation (com.qcloud.cos.model.ciModel.job.MediaJobOperation)1 MediaJobResponse (com.qcloud.cos.model.ciModel.job.MediaJobResponse)1 MediaJobsRequest (com.qcloud.cos.model.ciModel.job.MediaJobsRequest)1 MediaRemoveWaterMark (com.qcloud.cos.model.ciModel.job.MediaRemoveWaterMark)1 MediaTemplateResponse (com.qcloud.cos.model.ciModel.template.MediaTemplateResponse)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