查询已上传华为云视频的时长,大小等基础信息

1.首先添加相应的依赖

        
            com.aliyun
            dysmsapi20170525
            2.0.4
        
        
            com.aliyun
            aliyun-java-sdk-core
            4.5.16
        

2.Service定义的需要在配置文件里面去配置

// 日志打印
import com.btn.common.exception.ErrorCodeEnum;
import com.cloud.sdk.ServiceException;
import com.huawei.mpc.client.MpcClient;
import com.huawei.mpc.client.MpcConfig;
import com.huawei.mpc.model.ObsObjInfo;
import com.huawei.mpc.model.extract.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;



/**
 * @author 93
 * @version 1.0
 */
@Component
public class VideoExtractTaskService {

    private static final Logger logger = LoggerFactory.getLogger(VideoExtractTaskService.class);

    @Value("${huaweiObs.mpcendPoint}")
    private String mpcendPoint;

    @Value("${huaweiObs.ak}")
    private String ak;

    @Value("${huaweiObs.projectId}")
    private String projectId;

    @Value("${huaweiObs.sk}")
    private String sk;

    @Value("${huaweiObs.bucketName}")
    private String bucketName;


    /**
     * 获取视频时长
     * @return
     */
    public MetaData queryVideoDuration(String url) {
        try {
            //1.MPC配置信息设置
            MpcConfig mpcConfig = new MpcConfig();
            mpcConfig.setEndPoint(mpcendPoint);
            mpcConfig.setProjectId(projectId);
            mpcConfig.setSk(sk);
            mpcConfig.setAk(ak);
            //2.初始化MPC客户端
            MpcClient mpcClient = new MpcClient(mpcConfig);
            //3. ObsObjInfo 信息配置
            ObsObjInfo input = new ObsObjInfo();
            input.setBucket(bucketName);
            input.setLocation("cn-east-3");
            //对路径进行截取                                                                                                       
 input.setObject(url.substring(url.lastIndexOf("/",url.lastIndexOf("/",url.lastIndexOf("/")-1)-1) + 1));
            CreateExtractTaskReq req = new CreateExtractTaskReq();
            req.setInput(input);
            // MPC客户端创建视频解析请求并返回
            CreateExtractTaskRsp extractTask = mpcClient.createExtractTask(req);
            MetaData metadata = extractTask.getMetadata();
            return metadata;
        }catch (ServiceException exception){
            throw new com.btn.common.exception.ServiceException(ErrorCodeEnum.FAIL.getErrorCode(),"视频解析任务异常-->"+ exception.getErrorMessage());
        }
    }
}

你可能感兴趣的:(华为云&阿里云,华为云,java,后端)