Search in sources :

Example 1 with MediaMeta

use of com.mizhousoft.cloudsdk.vod.MediaMeta in project cloud-sdk by mizhousoft.

the class QCloudVODServiceImpl method buildMediaMeta.

private MediaMeta buildMediaMeta(String fileId, MediaBasicInfo basicInfo, MediaMetaData metaData, MediaTranscodeInfo transcodeInfo) {
    MediaMeta midiaMeta = new MediaMeta();
    midiaMeta.setFileId(fileId);
    if (null != basicInfo) {
        midiaMeta.setName(basicInfo.getName());
        midiaMeta.setType(basicInfo.getType());
        midiaMeta.setMediaUrl(basicInfo.getMediaUrl());
        midiaMeta.setCoverUrl(basicInfo.getCoverUrl());
    }
    if (null != metaData) {
        midiaMeta.setDuration(metaData.getDuration().intValue());
        midiaMeta.setMediaFileSize(metaData.getSize());
        MediaVideoStreamItem[] videoStreams = metaData.getVideoStreamSet();
        if (!ArrayUtils.isEmpty(videoStreams)) {
            MediaVideoStreamItem videoStream = videoStreams[0];
            String codec = videoStream.getCodec();
            midiaMeta.setCodec(codec);
        }
    }
    if (null != transcodeInfo) {
        MediaTranscodeItem[] list = ArrayUtils.nullToEmpty(transcodeInfo.getTranscodeSet(), MediaTranscodeItem[].class);
        for (int i = list.length - 1; i >= 0; --i) {
            MediaTranscodeItem item = list[i];
            MediaVideoStreamItem[] videoStreams = item.getVideoStreamSet();
            if (ArrayUtils.isEmpty(videoStreams)) {
                continue;
            }
            MediaVideoStreamItem videoStream = videoStreams[0];
            String codec = videoStream.getCodec();
            if (MediaCodecEnum.H264.isSelf(codec)) {
                midiaMeta.setCodec(codec);
                midiaMeta.setDuration(item.getDuration().intValue());
                midiaMeta.setMediaFileSize(item.getSize());
                midiaMeta.setMediaUrl(item.getUrl());
                break;
            }
        }
    }
    return midiaMeta;
}
Also used : MediaTranscodeItem(com.tencentcloudapi.vod.v20180717.models.MediaTranscodeItem) MediaMeta(com.mizhousoft.cloudsdk.vod.MediaMeta) MediaVideoStreamItem(com.tencentcloudapi.vod.v20180717.models.MediaVideoStreamItem)

Example 2 with MediaMeta

use of com.mizhousoft.cloudsdk.vod.MediaMeta in project cloud-sdk by mizhousoft.

the class QCloudVODServiceImpl method convertToEvent.

private VodEvent convertToEvent(EventContent content) {
    String eventId = content.getEventHandle();
    String eventType = content.getEventType();
    if ("NewFileUpload".equals(eventType)) {
        FileUploadTask uploadTask = content.getFileUploadEvent();
        MediaMeta mediaMeta = buildMediaMeta(uploadTask.getFileId(), uploadTask.getMediaBasicInfo(), uploadTask.getMetaData(), null);
        return new VodNewFileUploadEvent(eventId, mediaMeta);
    } else if ("ProcedureStateChanged".equals(eventType)) {
        ProcedureTask precTask = content.getProcedureStateChangeEvent();
        boolean completed = "FINISH".equals(precTask.getStatus());
        return new VodStateChangedEvent(eventId, precTask.getFileId(), completed);
    } else if ("FileDeleted".equals(eventType)) {
        FileDeleteTask deleteTask = content.getFileDeleteEvent();
        return new VodFileDeletedEvent(eventId, deleteTask.getFileIdSet());
    } else {
        return new VodEvent(eventId);
    }
}
Also used : VodFileDeletedEvent(com.mizhousoft.cloudsdk.vod.event.VodFileDeletedEvent) FileUploadTask(com.tencentcloudapi.vod.v20180717.models.FileUploadTask) FileDeleteTask(com.tencentcloudapi.vod.v20180717.models.FileDeleteTask) ProcedureTask(com.tencentcloudapi.vod.v20180717.models.ProcedureTask) VodNewFileUploadEvent(com.mizhousoft.cloudsdk.vod.event.VodNewFileUploadEvent) MediaMeta(com.mizhousoft.cloudsdk.vod.MediaMeta) VodStateChangedEvent(com.mizhousoft.cloudsdk.vod.event.VodStateChangedEvent) VodEvent(com.mizhousoft.cloudsdk.vod.event.VodEvent)

Example 3 with MediaMeta

use of com.mizhousoft.cloudsdk.vod.MediaMeta in project cloud-sdk by mizhousoft.

the class QCloudVODServiceImpl method getVideoMeta.

/**
 * {@inheritDoc}
 */
@Override
public MediaMeta getVideoMeta(String fileId) throws CloudSDKException {
    try {
        String[] fileIds = { fileId };
        DescribeMediaInfosRequest req = new DescribeMediaInfosRequest();
        req.setFileIds(fileIds);
        DescribeMediaInfosResponse resp = vodClient.DescribeMediaInfos(req);
        MediaInfo[] mediaInfos = resp.getMediaInfoSet();
        if (null != mediaInfos && 1 == mediaInfos.length) {
            MediaInfo mediaInfo = mediaInfos[0];
            MediaMeta meta = buildMediaMeta(fileId, mediaInfo.getBasicInfo(), mediaInfo.getMetaData(), mediaInfo.getTranscodeInfo());
            return meta;
        } else {
            return null;
        }
    } catch (TencentCloudSDKException e) {
        throw new CloudSDKException(e.getErrorCode(), e.getMessage(), e);
    }
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) MediaInfo(com.tencentcloudapi.vod.v20180717.models.MediaInfo) MediaMeta(com.mizhousoft.cloudsdk.vod.MediaMeta) DescribeMediaInfosRequest(com.tencentcloudapi.vod.v20180717.models.DescribeMediaInfosRequest) DescribeMediaInfosResponse(com.tencentcloudapi.vod.v20180717.models.DescribeMediaInfosResponse)

Example 4 with MediaMeta

use of com.mizhousoft.cloudsdk.vod.MediaMeta in project cloud-sdk by mizhousoft.

the class TestQCloudVODServiceImpl method getVideoMeta.

@Test
public void getVideoMeta() {
    try {
        MediaMeta mediaMeta = vodService.getVideoMeta("5285890786997530566");
        Assert.assertNotNull(mediaMeta);
    } catch (CloudSDKException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) MediaMeta(com.mizhousoft.cloudsdk.vod.MediaMeta) Test(org.junit.Test)

Aggregations

MediaMeta (com.mizhousoft.cloudsdk.vod.MediaMeta)4 CloudSDKException (com.mizhousoft.cloudsdk.CloudSDKException)2 VodEvent (com.mizhousoft.cloudsdk.vod.event.VodEvent)1 VodFileDeletedEvent (com.mizhousoft.cloudsdk.vod.event.VodFileDeletedEvent)1 VodNewFileUploadEvent (com.mizhousoft.cloudsdk.vod.event.VodNewFileUploadEvent)1 VodStateChangedEvent (com.mizhousoft.cloudsdk.vod.event.VodStateChangedEvent)1 TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)1 DescribeMediaInfosRequest (com.tencentcloudapi.vod.v20180717.models.DescribeMediaInfosRequest)1 DescribeMediaInfosResponse (com.tencentcloudapi.vod.v20180717.models.DescribeMediaInfosResponse)1 FileDeleteTask (com.tencentcloudapi.vod.v20180717.models.FileDeleteTask)1 FileUploadTask (com.tencentcloudapi.vod.v20180717.models.FileUploadTask)1 MediaInfo (com.tencentcloudapi.vod.v20180717.models.MediaInfo)1 MediaTranscodeItem (com.tencentcloudapi.vod.v20180717.models.MediaTranscodeItem)1 MediaVideoStreamItem (com.tencentcloudapi.vod.v20180717.models.MediaVideoStreamItem)1 ProcedureTask (com.tencentcloudapi.vod.v20180717.models.ProcedureTask)1 Test (org.junit.Test)1