腾讯云点播怎么获取不同清晰度的视频地址

首先确定是否已设置回调地址

编写后台代码接收回调传来的不同清晰度的视频地址,下面以 720和1080清晰度为例:

复制代码
package com.wkk.test.wkk_test.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.wkk.test.wkk_test.domain.TencentVideoOnDemandJsonData;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("notify")
public class NotifyController {

    Integer height720 = 720;
    Integer height1080 = 1080;

    @PostMapping(value = "/tencentVideoOnDemand")
    public void payNotify(HttpServletRequest request, HttpServletResponse response,@RequestBody String jsonObject) throws Exception{

        TencentVideoOnDemandJsonData jsonData = null;
        String height720VideoUrl = "";
        String height1080VideoUrl = "";
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            jsonData = objectMapper.readValue(jsonObject, TencentVideoOnDemandJsonData.class);
            if (jsonData.getEventType().equals("ProcedureStateChanged")){
                TencentVideoOnDemandJsonData.ProcedureStateChangeEvent event = jsonData.getProcedureStateChangeEvent();
                String fileId = event.getFileId();
                TencentVideoOnDemandJsonData.MediaProcessResultSet[] mediaProcessResultSet = event.getMediaProcessResultSet();

                for (TencentVideoOnDemandJsonData.MediaProcessResultSet processResultSet : mediaProcessResultSet) {
                    TencentVideoOnDemandJsonData.TranscodeTask transcodeTask = processResultSet.getTranscodeTask();
                    TencentVideoOnDemandJsonData.Output output = transcodeTask.getOutput();
                    int height = output.getHeight();
                    if (height==height720){
                        height720VideoUrl = output.getUrl();
                    }else if (height==height1080){
                        height1080VideoUrl = output.getUrl();
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("腾讯云回调");
        System.out.println("height720VideoUrl: "+height720VideoUrl); // 720 清晰度视频地址
        System.out.println("height1080VideoUrl: "+height1080VideoUrl); // 1080 清晰度视频地址

    }

}

对应的解析json的实体类代码:

复制代码
package com.wkk.test.wkk_test.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

@Data
public class TencentVideoOnDemandJsonData {
    @JsonProperty("EventType")
    private String eventType;
    @JsonProperty("FileUploadEvent")
    private Object fileUploadEvent;
    @JsonProperty("ProcedureStateChangeEvent")
    private ProcedureStateChangeEvent procedureStateChangeEvent;
    @JsonProperty("FileDeleteEvent")
    private Object fileDeleteEvent;
    @JsonProperty("PullCompleteEvent")
    private Object pullCompleteEvent;
    @JsonProperty("EditMediaCompleteEvent")
    private Object editMediaCompleteEvent;
    @JsonProperty("ComposeMediaCompleteEvent")
    private Object composeMediaCompleteEvent;
    @JsonProperty("WechatPublishCompleteEvent")
    private Object wechatPublishCompleteEvent;
    @JsonProperty("TranscodeCompleteEvent")
    private Object transcodeCompleteEvent;
    @JsonProperty("ConcatCompleteEvent")
    private Object concatCompleteEvent;
    @JsonProperty("ClipCompleteEvent")
    private Object clipCompleteEvent;
    @JsonProperty("CreateImageSpriteCompleteEvent")
    private Object createImageSpriteCompleteEvent;
    @JsonProperty("SnapshotByTimeOffsetCompleteEvent")
    private Object snapshotByTimeOffsetCompleteEvent;
    @JsonProperty("WechatMiniProgramPublishEvent")
    private Object wechatMiniProgramPublishEvent;
    @JsonProperty("WechatMiniProgramPublishCompleteEvent")
    private Object wechatMiniProgramPublishCompleteEvent;
    @JsonProperty("RemoveWatermarkCompleteEvent")
    private Object removeWatermarkCompleteEvent;
    @JsonProperty("RestoreMediaCompleteEvent")
    private Object restoreMediaCompleteEvent;
    @JsonProperty("ForbidMediaCompleteEvent")
    private Object forbidMediaCompleteEvent;
    @JsonProperty("SplitMediaCompleteEvent")
    private Object splitMediaCompleteEvent;
    @JsonProperty("RebuildMediaCompleteEvent")
    private Object rebuildMediaCompleteEvent;
    @JsonProperty("FastClipMediaCompleteEvent")
    private Object fastClipMediaCompleteEvent;
    @JsonProperty("BackUpMediaCompleteEvent")
    private Object backUpMediaCompleteEvent;
    @JsonProperty("ReviewAudioVideoCompleteEvent")
    private Object reviewAudioVideoCompleteEvent;
    @JsonProperty("DescribeFileAttributesCompleteEvent")
    private Object describeFileAttributesCompleteEvent;
    @JsonProperty("ExtractTraceWatermarkCompleteEvent")
    private Object extractTraceWatermarkCompleteEvent;
    @JsonProperty("ExtractCopyRightWatermarkCompleteEvent")
    private Object extractCopyRightWatermarkCompleteEvent;
    @JsonProperty("QualityInspectCompleteEvent")
    private Object qualityInspectCompleteEvent;
    @JsonProperty("QualityEnhanceCompleteEvent")
    private Object qualityEnhanceCompleteEvent;
    @JsonProperty("ReduceMediaBitrateCompleteEvent")
    private Object reduceMediaBitrateCompleteEvent;

    @Data
    public static class ProcedureStateChangeEvent {
        @JsonProperty("TaskId")
        private String taskId;
        @JsonProperty("Status")
        private String status;
        @JsonProperty("ErrCode")
        private int errCode;
        @JsonProperty("Message")
        private String message;
        @JsonProperty("FileId")
        private String fileId;
        @JsonProperty("FileName")
        private String fileName;
        @JsonProperty("FileUrl")
        private String fileUrl;
        @JsonProperty("MetaData")
        private MetaData metaData;
        @JsonProperty("AiAnalysisResultSet")
        private Object[] aiAnalysisResultSet;
        @JsonProperty("AiRecognitionResultSet")
        private Object[] aiRecognitionResultSet;
        @JsonProperty("AiContentReviewResultSet")
        private Object[] aiContentReviewResultSet;
        @JsonProperty("MediaProcessResultSet")
        private MediaProcessResultSet[] mediaProcessResultSet;
        @JsonProperty("SessionContext")
        private String sessionContext;
        @JsonProperty("SessionId")
        private String sessionId;
        @JsonProperty("TasksPriority")
        private int tasksPriority;
        @JsonProperty("TasksNotifyMode")
        private String tasksNotifyMode;
        @JsonProperty("Operator")
        private String operator;
        @JsonProperty("OperationType")
        private String operationType;
    }

    @Data
    public static class MetaData {
        @JsonProperty("AudioDuration")
        private double audioDuration;
        @JsonProperty("AudioStreamSet")
        private AudioStream[] audioStreamSet;
        @JsonProperty("Bitrate")
        private int bitrate;
        @JsonProperty("Container")
        private String container;
        @JsonProperty("Duration")
        private double duration;
        @JsonProperty("Height")
        private int height;
        @JsonProperty("Md5")
        private String md5;
        @JsonProperty("Rotate")
        private int rotate;
        @JsonProperty("Size")
        private long size;
        @JsonProperty("VideoDuration")
        private double videoDuration;
        @JsonProperty("VideoStreamSet")
        private VideoStream[] videoStreamSet;
        @JsonProperty("Width")
        private int width;
    }

    @Data
    public static class MediaProcessResultSet {
        @JsonProperty("Type")
        private String type;
        @JsonProperty("TranscodeTask")
        private TranscodeTask transcodeTask;
        @JsonProperty("AnimatedGraphicTask")
        private Object animatedGraphicTask;
        @JsonProperty("SnapshotByTimeOffsetTask")
        private Object snapshotByTimeOffsetTask;
        @JsonProperty("SampleSnapshotTask")
        private Object sampleSnapshotTask;
        @JsonProperty("ImageSpriteTask")
        private Object imageSpriteTask;
        @JsonProperty("CoverBySnapshotTask")
        private Object coverBySnapshotTask;
        @JsonProperty("AdaptiveDynamicStreamingTask")
        private Object adaptiveDynamicStreamingTask;
    }

    @Data
    public static class AudioStream {
        @JsonProperty("Bitrate")
        private int bitrate;
        @JsonProperty("Codec")
        private String codec;
        @JsonProperty("Codecs")
        private String codecs;
        @JsonProperty("Loudness")
        private int loudness;
        @JsonProperty("SamplingRate")
        private int samplingRate;
    }

    @Data
    public static class VideoStream {
        @JsonProperty("Bitrate")
        private int bitrate;
        @JsonProperty("Codec")
        private String codec;
        @JsonProperty("CodecTag")
        private String codecTag;
        @JsonProperty("Codecs")
        private String codecs;
        @JsonProperty("DynamicRangeInfo")
        private DynamicRangeInfo dynamicRangeInfo;
        @JsonProperty("Fps")
        private int fps;
        @JsonProperty("Height")
        private int height;
        @JsonProperty("Width")
        private int width;
    }

    @Data
    public static class DynamicRangeInfo {
        @JsonProperty("HDRType")
        private String hdrType;
        @JsonProperty("Type")
        private String type;
    }

    @Data
    public static class TranscodeTask {
        @JsonProperty("Status")
        private String status;
        @JsonProperty("ErrCode")
        private int errCode;
        @JsonProperty("ErrCodeExt")
        private String errCodeExt;
        @JsonProperty("Message")
        private String message;
        @JsonProperty("Progress")
        private int progress;
        @JsonProperty("BeginProcessTime")
        private String beginProcessTime;
        @JsonProperty("FinishTime")
        private String finishTime;
        @JsonProperty("Input")
        private Input input;
        @JsonProperty("Output")
        private Output output;
    }

    @Data
    public static class Input {
        @JsonProperty("Definition")
        private int definition;
        @JsonProperty("TraceWatermark")
        private TraceWatermark traceWatermark;
        @JsonProperty("CopyRightWatermark")
        private CopyRightWatermark copyRightWatermark;
        @JsonProperty("WatermarkSet")
        private Object[] watermarkSet;
        @JsonProperty("HeadTailSet")
        private Object[] headTailSet;
        @JsonProperty("MosaicSet")
        private Object[] mosaicSet;
        @JsonProperty("StartTimeOffset")
        private int startTimeOffset;
        @JsonProperty("EndTimeOffset")
        private int endTimeOffset;
    }

    @Data
    public static class Output {
        @JsonProperty("Url")
        private String url;
        @JsonProperty("Size")
        private int size;
        @JsonProperty("Container")
        private String container;
        @JsonProperty("Height")
        private int height;
        @JsonProperty("Width")
        private int width;
        @JsonProperty("Bitrate")
        private int bitrate;
        @JsonProperty("Md5")
        private String md5;
        @JsonProperty("Duration")
        private double duration;
        @JsonProperty("VideoStreamSet")
        private VideoStream[] videoStreamSet;
        @JsonProperty("AudioStreamSet")
        private AudioStream[] audioStreamSet;
        @JsonProperty("Definition")
        private int definition;
        @JsonProperty("DigitalWatermarkType")
        private String digitalWatermarkType;
        @JsonProperty("CopyRightWatermarkText")
        private String copyRightWatermarkText;
        @JsonProperty("VMAF")
        private int vmaf;
    }

    @Data
    public static class TraceWatermark {
        @JsonProperty("Definition")
        private int definition;
        @JsonProperty("DefinitionForBStream")
        private int definitionForBStream;
        @JsonProperty("Switch")
        private String switchStr;
    }

    @Data
    public static class CopyRightWatermark {
        @JsonProperty("Text")
        private String text;
        @JsonProperty("StartTimeOffset")
        private int startTimeOffset;
        @JsonProperty("EndTimeOffset")
        private int endTimeOffset;
    }
}
相关推荐
zhengyquan4 天前
云上盛宴-腾讯云双11活动玩法攻略
服务器·云计算·腾讯云·腾讯云双十一活动
csdn5659738504 天前
一文了解什么是腾讯云开发
云计算·腾讯云·腾讯云开发·轻松上手·云开发开箱挑战赛
粤海科技君6 天前
如何使用腾讯云GPU云服务器自建一个简单的类似ChatGPT、Kimi的会话机器人
服务器·chatgpt·机器人·腾讯云
知孤云出岫7 天前
云上拼团GO指南——腾讯云博客部署案例,双11欢乐GO
云计算·腾讯云
IT技术分享社区7 天前
C#实战:使用腾讯云识别服务轻松提取火车票信息
开发语言·c#·云计算·腾讯云·共识算法
逐星ing8 天前
【AIGC】腾讯云语音识别(ASR)服务在Spring Boot项目中的集成与实践
aigc·腾讯云·语音识别
zhengyquan11 天前
腾讯云计算工程师认证篇--云计算核心技术与分层架构
架构·云计算·腾讯云
数据猿11 天前
腾讯云数据库TDSQL:数据库界的“高架桥”
数据库·云计算·腾讯云
xrl201215 天前
腾讯云或阿里云centos7安装Redis,并解决端口无法访问的问题
redis·阿里云·腾讯云
Devil枫15 天前
腾讯云云开发深度解读:云数据库、云模板与AI生成引用的魅力
数据库·人工智能·腾讯云