阿里云OSS视频文件迁移视频点播,并导出媒资excel表

  • 一 介绍
    • 1 OSS 是什么
    • 2 视频点播是什么
    • 3 制作背景
      • 阿里云磁盘(读文件)
      • 阿里云点播(写文件)
      • 阿里云sdk导入依赖
  • 二 流程
    • 1 迁移流程
    • 注意:
    • 解释:
  • 三 代码实现
    • 1 UploadVideoServiceImpl业务代码
    • 2 Suplier供应商表
    • 3 OSS处理工具类OSSUploadVideoDemo

一 介绍

1 OSS 是什么

OSS 相当于硬盘、便宜容量大,存储不经常使用的文件。
官网介绍: https://help.aliyun.com/document_detail/31817.html?spm=a2c4g.11174359.6.544.51ea1ea9aXOD2K

2 视频点播是什么

视频点播相当于存储视频文件的CND,集鉴权、播放、管理于一体的播放系统。
官网介绍: https://help.aliyun.com/document_detail/51236.html?spm=a2c4g.11186623.6.542.1b97152aQrphzw

3 制作背景

与阿里云合作,视频媒资量过于巨大,无法通过阿里云平台上传,只能通过寄OSS硬盘拷贝,然后将OSS寄回阿里,编写OSS迁移到视频点播的代码上传即可。
文档信息

阿里云磁盘(读文件)

                 读文件: https://help.aliyun.com/video_detail/39691.html?spm=5176.10695662.1996646101.searchclickresult.2f2d36b9m7F1K4

阿里云点播(写文件)

             写文件: https://help.aliyun.com/document_detail/64148.html?spm=a2c4g.11186623.6.1066.42976a58M4A9av」

阿里云sdk导入依赖

       <!-- 阿里云同步开始 --><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-core</artifactId><version>4.3.3</version></dependency><dependency><groupId>com.aliyun.oss</groupId><artifactId>aliyun-sdk-oss</artifactId><version>3.1.0</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-vod</artifactId><version>2.15.2</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.28</version></dependency><dependency><groupId>org.json</groupId><artifactId>json</artifactId><version>20170516</version></dependency><dependency><groupId>com.google.code.gson</groupId><artifactId>gson</artifactId><version>2.8.2</version></dependency><dependency><groupId>com.konka.util</groupId><artifactId>aliyun-java-vod-upload</artifactId><version>1.4.12</version></dependency><!-- 阿里云同步结束 --><!-- excel处理 --><dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>3.17</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>3.17</version></dependency>

二 流程

1 迁移流程

注意:

1 确保OSS和视频点播和ECS(自己的云机器)在一个局域网内、走内网不消耗网络流量。

解释:

1 将OSS文件批量查询、并下载到本地ECS服务器
2 将本地下载好的文件上传视频点播(注意配置好转码模板、分类信息等)

三 代码实现

1 UploadVideoServiceImpl业务代码


@Slf4j
@Service
public class UploadVideoServiceImpl implements UploadVideoService {public final static List<Suplier> suplierlist = new ArrayList() {{add(new Suplier("shulang", "供应商1", 8L));add(new Suplier("jiaoyu", "供应商2", 19L));add(new Suplier("huanggang", "供应商3", 6020L));add(new Suplier("yang", "供应商4", 21L));}};@Overridepublic void upload(ABInDTO inDTO) {Integer start = inDTO.getStart();Integer end = inDTO.getEnd();// 1 赛选所有List<OSSObjectSummary> finds = OSSUploadVideoDemo.select();log.info("查询总数为:{}", finds.size());if (start == null) {start = 0;}if (end == null) {end = finds.size();}log.info("开始和结束的数量start:{},end:{}", start, end);Integer count = 0;// 2 遍历上传到视频点播for (int i = 0; i < finds.size(); i++) {// 过滤掉if (start <= i && end >= i) {log.info("开始第:{}个-区间共:{}-{}个,总共:{}", i, start, end, finds.size());OSSObjectSummary s = finds.get(i);try {// 3 上传视频点播log.info("\t-----------------------start");log.info("\tgetKey " + s.getKey());OSSUploadVideoDemo.upload(s.getKey());log.info("\t上传视频点播完毕getBucketName " + s.getBucketName());} catch (Exception e) {log.error("上传视频点播出错了1");log.info("\tgetKey " + s.getKey());}count++;log.info("\t-----------------------end");}}}public static void main(String[] args) throws Exception {OSSUploadVideoDemo.upload(null);}}

2 Suplier供应商表

@Data
public class Suplier {// OSS文件夹名称***private String bucketName;private String nickName;    // 备注名称private Long CateId;    // 分类idpublic Suplier(String bucketName, String nickName, Long cateId) {this.bucketName = bucketName;this.nickName = nickName;CateId = cateId;}
}

3 OSS处理工具类OSSUploadVideoDemo

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.*;
import com.aliyun.vod.upload.resp.UploadVideoResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.*;
import com.operlog.main.model.po.Suplier;
import com.operlog.main.utils.JavaExcelUtils;
import com.operlog.main.utils.JavaListUtils;
import com.operlog.utils.log.service.impl.UploadVideoServiceImpl;
import lombok.extern.slf4j.Slf4j;import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;/*** Created by ji* ji on 2020/4/28.* 阿里云OSS视频下载* https://help.aliyun.com/document_detail/84824.html?spm=a2c4g.11186623.6.800.45466328mEu67v*/
@Slf4j
public class OSSUploadVideoDemo {//账号AK信息请填写(必选) 子账号public static final String accessKeyId = "";//账号AK信息请填写(必选)public static final String accessKeySecret = "";// Bucket名称public static final String bucketName = "kkypf-yixue-media";//        public static final String localUrl = "G:\\office\\test\\";   // 本地public static final String localUrl = "/alidata/server/test/";   // 线上???// Endpoint以上海为例,其它Region请按实际情况填写。
//    public static final String endpoint = "http://oss-cn-shanghai.aliyuncs.com";    // 外网public static final String endpoint = "http://oss-cn-shanghai-internal.aliyuncs.com";    // 内网 -UploadVideoDemo-  request.setApiRegionId("cn-shanghai"); request.setEcsRegionId("cn-shanghai");  要开放
//    public static final String uploadEndpoint = "http://oss-cn-shanghai-internal.aliyuncs.com";    // 视频点播内网/*** 查询路径下所有文件*/public static List<OSSObjectSummary> select() {OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);final int maxKeys = 1000;String nextMarker = null;ObjectListing objectListing;Long count = 0l;List<OSSObjectSummary> sumsOut = new ArrayList<>();do {objectListing = ossClient.listObjects(new ListObjectsRequest(bucketName).withMarker(nextMarker).withMaxKeys(maxKeys));List<OSSObjectSummary> sums = objectListing.getObjectSummaries();sumsOut.addAll(sums);count += sums.size();log.info("最大个数\t" + sums.size());nextMarker = objectListing.getNextMarker();} while (objectListing.isTruncated());// 关闭OSSClient。ossClient.shutdown();log.info("总数为\t" + count);return sumsOut;}/*** OSS下载视频** @param objectName 文件的目标名 例如: lang/人教版3年级下册(3起)-第100讲:Unit 2 My family.mp4*/public static void upload(String objectName) throws Exception {log.info("上传开始objectName:{}", objectName);// 1 OSS下载文件到本地// 创建OSSClient实例。OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);String[] split = objectName.split("/");// 下载OSS文件到本地文件。如果指定的本地文件存在会覆盖,不存在则新建。String fileNameReal = split[split.length - 1];String fileName = localUrl + fileNameReal;  log.info("fileName:{}", fileName);File file = new File(fileName);try {BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));} catch (Exception e) {log.error("下载OSS出错了2objectName:{},msg:{}", objectName, e.getMessage());}ObjectMetadata object = ossClient.getObject(new GetObjectRequest(bucketName, objectName), file);// 关闭OSSClient。ossClient.shutdown();log.info("object.getCacheControl():{}", object.getCacheControl());log.info("object.getContentDisposition():{}", object.getContentDisposition());log.info("object.getContentEncoding():{}", object.getContentEncoding());log.info("object.getContentMD5():{}", object.getContentMD5());log.info("object.getETag():{}", object.getETag());log.info("object.getRequestId():{}", object.getRequestId());log.info("object.getServerSideEncryption():{}", object.getServerSideEncryption());log.info("object():{}", object.toString());// 筛选出是哪个供应商Suplier suplierOut = new Suplier("新建分类zj默认1", "新建分类zj默认1", 1000136023L);for (Suplier suplier : UploadVideoServiceImpl.suplierlist) {if (objectName.contains(suplier.getBucketName())) {suplierOut = suplier;log.info("objectName:{},属于:{}", objectName, suplier.getNickName());break;}}// 2 本地上传到视频点播
//        UploadVideoResponse uploadVideoResponse = UploadVideoDemo.testUploadVideo(accessKeyId, accessKeySecret, fileNameReal.substring(0, fileNameReal.lastIndexOf(".")), fileName);UploadVideoResponse uploadVideoResponse = UploadVideoDemo.testUploadVideo(accessKeyId, accessKeySecret, fileNameReal, fileName, suplierOut.getCateId());log.info("RequestId=" + uploadVideoResponse.getRequestId() + "\n");log.info("VideoId=" + uploadVideoResponse.getVideoId() + "\n");log.info("ErrorCode=" + uploadVideoResponse.getCode() + "\n");log.info("ErrorMessage=" + uploadVideoResponse.getMessage() + "\n");String[] stringOuts = null;// 将文件写入表格中    String[] strings = {"1 第三方介质ID", "2 介质名称", "3 介质格式", "4 播放时长 (秒)", "5 分辨率", "6 播放地址", "7 requestId", "8 videoId", "9 code", "10 message", "11 供应商名称", "12 阿里云分类catId"};if (uploadVideoResponse == null) {stringOuts = new String[]{"", fileNameReal.substring(0, fileNameReal.lastIndexOf(".")),fileNameReal.substring(fileNameReal.lastIndexOf("."), fileNameReal.length()), "4","5", "6","7", "8","9", "返回空指针"};} else {// 获取视频信息GetVideoInfoResponse videoInfo = null; //GetMezzanineInfoResponse mezzanineInfo = null;String str4 = null;String str5 = "1280*720";   // 默认String str6 = "";try {videoInfo = getVideoInfo(uploadVideoResponse.getVideoId());log.info("获取视频信息结束:{},videoInfo:{}", uploadVideoResponse.getVideoId(), videoInfo);GetVideoInfoResponse.Video video = videoInfo.getVideo();log.info("获取视频信息结束:{},videoInfo:{},video:{}", uploadVideoResponse.getVideoId(), videoInfo, video);str4 = video.getDuration() + "";str6 = video.getCoverURL();mezzanineInfo = getMezzanineInfo(uploadVideoResponse.getVideoId());log.info("查询到视频信息videoId:{},mezzanineInfo:{}", uploadVideoResponse.getVideoId(), mezzanineInfo);GetMezzanineInfoResponse.Mezzanine mezzanine = mezzanineInfo.getMezzanine();GetMezzanineInfoResponse.Mezzanine.VideoStream videoStream = mezzanine.getVideoStreamList().get(mezzanine.getVideoStreamList().size() - 1);
//                str5 = mezzanine.getHeight() + "*" + mezzanine.getWidth();str5 = videoStream.getHeight() + "*" + videoStream.getWidth();} catch (Exception e) {log.error("下载OSS出错了3objectName:{},msg:{}", objectName, e.getMessage());}stringOuts = new String[]{uploadVideoResponse.getVideoId(), fileNameReal.substring(0, fileNameReal.lastIndexOf(".")),fileNameReal.substring(fileNameReal.lastIndexOf(".") + 1, fileNameReal.length()), str4,str5, str6,uploadVideoResponse.getRequestId(), uploadVideoResponse.getVideoId(),uploadVideoResponse.getCode(), uploadVideoResponse.getMessage()};}// 3 将信息汇总-写入exceltry {log.info("写入excel开始objectName:{}", objectName);List<String[]> list1 = new ArrayList<String[]>();list1.add(stringOuts);JavaExcelUtils.addOneLine(list1, JavaExcelUtils.TableName.YIXUE);log.info("写入excel完毕objectName:{},stringOuts:{}", objectName, stringOuts);} catch (Exception e) {log.error("写入excel出错了4objectName:{},list1:{},msg:{}", objectName, stringOuts, e.getMessage());}log.info("上传完毕objectName:{}", objectName);log.info("写入excel完毕stringOuts:{}", stringOuts.toString());}/*** OSS下载视频** @param suplier 供应商*/public static void getPalyInfoToExcel(Suplier suplier) throws Exception {log.info("getPalyInfoToExcel开始suplier:{}", suplier);Long catId = suplier.getCateId();// 1 获取分类下面的所有视频List<GetVideoListResponse.Video> videoListAll = null;try {videoListAll = UploadVideoDemo.getVideoListAll(catId);} catch (Exception e) {e.printStackTrace();}if (JavaListUtils.isEmpty(videoListAll)) {System.out.println("videoListAll.size():0");return;}System.out.println("videoListAll.size():" + videoListAll.size());// 2 获取视频详情List<GetPlayInfoResponse> getPlayInfoResponses = new ArrayList<>();for (GetVideoListResponse.Video video : videoListAll) {try {GetPlayInfoResponse playInfo = OSSUploadVideoDemo.getPlayInfo(video.getVideoId());getPlayInfoResponses.add(playInfo);} catch (Exception e) {e.printStackTrace();}}if (JavaListUtils.isEmpty(getPlayInfoResponses)) {System.out.println("getPlayInfoResponses.size():0");return;}// 3 遍历写入excelfor (GetPlayInfoResponse getPlayInfoRespons : getPlayInfoResponses) {String[] stringOuts = null;// 将文件写入表格中  String[] strings = {"1 第三方介质ID", "2 介质名称", "3 介质格式", "4 播放时长 (秒)", "5 分辨率", "6 播放地址", "7 requestId", "8 videoId", "9 code", "10 message"};if (getPlayInfoRespons == null) {stringOuts = new String[]{"1", "2","3", "4","5", "6","7", "8","9", "10"};} else {String str3 = "m3u8";String str5 = "1280*720";   // 默认String str6 = "";GetPlayInfoResponse.VideoBase videoBase = getPlayInfoRespons.getVideoBase();List<GetPlayInfoResponse.PlayInfo> playInfoList = getPlayInfoRespons.getPlayInfoList();if (!JavaListUtils.isEmpty(playInfoList)) {GetPlayInfoResponse.PlayInfo playInfo = playInfoList.get(0); // 取第一个str3 = playInfo.getFormat();str5 = playInfo.getWidth() + "*" + playInfo.getHeight();str6 = playInfo.getPlayURL();}stringOuts = new String[]{videoBase.getVideoId(), videoBase.getTitle(),str3, videoBase.getDuration(),str5, str6,getPlayInfoRespons.getRequestId(), videoBase.getVideoId(),videoBase.getStatus(), videoBase.getCreationTime(),suplier.getNickName(), catId + ""};}// 3 将信息汇总-写入exceltry {log.info("写入excel开始objectName:{}", catId);List<String[]> list1 = new ArrayList<String[]>();list1.add(stringOuts);JavaExcelUtils.addOneLine(list1, JavaExcelUtils.TableName.YIXUE);log.info("写入excel完毕objectName:{},stringOuts:{}", catId, stringOuts);} catch (Exception e) {log.error("写入excel出错了4objectName:{},list1:{},msg:{}", catId, stringOuts, e.getMessage());}log.info("getPalyInfoToExcel完毕objectName:{}", catId);log.info("getPalyInfoToExcel写入excel完毕stringOuts:{}", stringOuts.toString());}log.info("getPalyInfoToExcel写入excel完毕stringOuts:{}");}/*** 获取源文件信息** @return GetMezzanineInfoResponse 获取源文件信息响应数据* @throws Exception*/public static GetMezzanineInfoResponse getMezzanineInfo(String videoId) throws Exception {log.info("查询videoId:{}", videoId);GetMezzanineInfoRequest request = new GetMezzanineInfoRequest();DefaultAcsClient client = initVodClient(accessKeyId, accessKeySecret);  // 发送请求客户端request.setVideoId(videoId);//源片下载地址过期时间request.setAuthTimeout(3600L);return client.getAcsResponse(request);}/*** 初始化 点播视频查询** @param accessKeyId* @param accessKeySecret* @return* @throws ClientException*/public static DefaultAcsClient initVodClient(String accessKeyId, String accessKeySecret) throws ClientException {String regionId = "cn-shanghai";  // 点播服务接入区域DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);DefaultAcsClient client = new DefaultAcsClient(profile);return client;}/*** 获取视频信息** @return GetVideoInfoResponse 获取视频信息响应数据* @throws Exception*/public static GetVideoInfoResponse getVideoInfo(String videoId) throws Exception {log.info("获取视频信息开始:{}", videoId);DefaultAcsClient client = initVodClient(accessKeyId, accessKeySecret);  // 发送请求客户端GetVideoInfoRequest request = new GetVideoInfoRequest();request.setVideoId(videoId);return client.getAcsResponse(request);}/*获取播放地址函数*//*** 转码流地址** @param videoId 视频id* @return* @throws Exception*/public static GetPlayInfoResponse getPlayInfo(String videoId) throws Exception {DefaultAcsClient client = OSSUploadVideoDemo.initVodClient(OSSUploadVideoDemo.accessKeyId, OSSUploadVideoDemo.accessKeySecret);  // 发送请求客户端GetPlayInfoRequest request = new GetPlayInfoRequest();request.setVideoId(videoId);return client.getAcsResponse(request);}

4 视频点播操作UploadVideoDemo

package com.operlog.main.aliyun;import com.alibaba.fastjson.JSONObject;
import com.aliyun.vod.upload.impl.UploadAttachedMediaImpl;
import com.aliyun.vod.upload.impl.UploadImageImpl;
import com.aliyun.vod.upload.impl.UploadM3u8FileImpl;
import com.aliyun.vod.upload.impl.UploadVideoImpl;
import com.aliyun.vod.upload.req.*;
import com.aliyun.vod.upload.resp.*;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.vod.model.v20170321.*;
import com.operlog.main.model.po.Suplier;
import com.operlog.main.utils.JavaListUtils;
import com.operlog.utils.log.service.impl.UploadVideoServiceImpl;
import lombok.extern.slf4j.Slf4j;import java.io.*;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;/*** 视频点播工具类* 以下Java示例代码演示了如何在服务端上传媒资文件至视频点播,媒资类型支持音频、视频和图片。* <p>* 一、音视频上传目前支持4种方式上传:* <p>* 1.上传本地文件,使用分片上传,并支持断点续传,参见testUploadVideo函数。* 1.1 当断点续传关闭时,最大支持上传任务执行时间为3000秒,具体可上传文件大小与您的网络带宽及磁盘读写能力有关。* 1.2 当断点续传开启时,最大支持48.8TB的单个文件,注意,断点续传开启后,上传任务执行过程中,同时会将当前上传位置写入本地磁盘文件,影响您上传文件的速度,请您根据文件大小选择是否开启* <p>* 2.上传网络流,可指定文件URL进行上传,支持断点续传,最大支持48.8TB的单个文件。* 该上传方式需要先将网络文件下载到本地磁盘,再进行上传,所以要保证本地磁盘有充足的空间。参见testUploadURLStream函数。* <p>* 3.上传文件流,可指定本地文件进行上传,不支持断点续传,最大支持5GB的单个文件。参见testUploadFileStream函数。* <p>* 4.流式上传,可指定输入流进行上传,支持文件流和网络流等,不支持断点续传,最大支持5GB的单个文件。参见testUploadStream函数。* <p>* <p>* 二、图片上传目前支持2种方式上传:* 1.上传本地文件,不支持断点续传,最大支持5GB的单个文件,参见testUploadImageLocalFile函数* 2.上传文件流和网络流,InputStream参数必选,不支持断点续传,最大支持5GB的单个文件。参见testUploadImageStream函数。* 注:图片上传完成后,会返回图片ID和图片地址,也可通过GetImageInfo查询图片信息,参见接口文档 https://help.aliyun.com/document_detail/89742.html* <p>* <p>* 三、m3u8文件上传目前支持2种方式:* 1.上传本地m3u8音视频文件(包括所有分片文件)到点播,需指定本地m3u8索引文件地址和所有分片地址。* 2.上传网络m3u8音视频文件(包括所有分片文件)到点播,需指定m3u8索引文件和分片文件的URL地址。* <p>* 注:* 1) 上传网络m3u8音视频文件时需要保证地址可访问,如果有权限限制,请设置带签名信息的地址,且保证足够长的有效期,防止地址无法访问导致上传失败* 2) m3u8文件上传暂不支持进度回调* <p>* <p>* 四、上传进度回调通知:* 1.默认上传进度回调函数:视频点播上传SDK内部默认开启上传进度回调函数,输出不同事件通知的日志,您可以设置关闭该上传进度通知及日志输出;* 2.自定义上传进度回调函数:您可根据自已的业务场景重新定义不同事件处理的方式,只需要修改上传回调示例函数即可。* <p>* <p>* 五、辅助媒资上传目前支持2种方式:* 1.上传本地文件,不支持断点续传,最大支持5GB的单个文件,参见testUploadAttachedMediaLocalFile函数* 2.上传文件流和网络流,InputStream参数必选,不支持断点续传,最大支持5GB的单个文件。参见testUploadAttachedMediaStream函数。* <p>* <p>* 六、支持STS方式上传:* 1.您需要实现VoDRefreshSTSTokenListener接口的onRefreshSTSToken方法,用于生成STS信息,* 当文件上传时间超过STS过期时间时,SDK内部会定期调用此方法刷新您的STS信息进行后续文件的上传。* <p>* <p>* 七、可指定上传脚本部署的ECS区域(设置Request的EcsRegionId参数,取值参考存储区域标识:https://help.aliyun.com/document_detail/98194.html),* 如果与点播存储(OSS)区域相同,则自动使用内网上传文件至存储,上传更快且更省公网流量* 由于点播API只提供外网域名访问,因此部署上传脚本的ECS服务器必须具有访问外网的权限。* <p>* 注意:* 请替换示例中的必选参数,示例中的可选参数如果您不需要设置,请将其删除,以免设置无效参数值与您的预期不符。*/
@Slf4j
public class UploadVideoDemo {public static void main(String[] args) {//         五、查询视频列表GetVideoListResponse videoList = null;try {videoList = getVideoList(1000136018L, 0, 200);} catch (Exception e) {e.printStackTrace();}List<GetVideoListResponse.Video> videos = videoList.getVideoList();System.out.println("videos.size():" + videos.size());// 5.1视频信息List<GetVideoInfoResponse> getVideoInfoResponses = new ArrayList<>();List<GetPlayInfoResponse> getPlayInfoResponses = new ArrayList<>();for (GetVideoListResponse.Video video : videos) {try {GetVideoInfoResponse videoInfo = OSSUploadVideoDemo.getVideoInfo(video.getVideoId());GetPlayInfoResponse playInfo = OSSUploadVideoDemo.getPlayInfo(video.getVideoId());getVideoInfoResponses.add(videoInfo);getPlayInfoResponses.add(playInfo);} catch (Exception e) {e.printStackTrace();}}System.out.println("getVideoInfoResponses.size():" + getVideoInfoResponses.size());// 5.2 视频流信息System.out.println("getPlayInfoResponses.size():" + getPlayInfoResponses.size());//         5.3 获取分类下所有视频列表List<GetVideoListResponse.Video> videoListAll = null;try {videoListAll = getVideoListAll(19L);} catch (Exception e) {e.printStackTrace();}if (JavaListUtils.isEmpty(videoListAll)) {return;}System.out.println("videoListAll.size():" + videoListAll.size());for (Suplier suplier : UploadVideoServiceImpl.suplierlist) {try {OSSUploadVideoDemo.getPalyInfoToExcel(suplier);} catch (Exception e) {e.printStackTrace();}}}public final static Integer pageSizeFix = 100;/*** 获取全部视频列表** @param catId 分类id* @return GetVideoListResponse 获取视频列表响应数据* @throws Exception*/public static List<GetVideoListResponse.Video> getVideoListAll(Long catId) throws Exception {// 1 获取总数List<GetVideoListResponse.Video> videosOut = new ArrayList<>();GetVideoListResponse videoListFind = getVideoList(catId, 1, pageSizeFix);if (videoListFind == null) {System.out.println("获取的返回结果为空,catId:" + catId);return videosOut;}Integer total = videoListFind.getTotal();if (total == null || total <= 0) {System.out.println("获取的总数为空或者小于等于0,total:" + total);return videosOut;}Integer totalPage = total / pageSizeFix + 1;// 2 分页获取全部for (Integer i = 0; i < totalPage; i++) {GetVideoListResponse videoListIn = getVideoList(catId, i + 1, pageSizeFix);if (videoListIn != null && !JavaListUtils.isEmpty(videoListIn.getVideoList())) {videosOut.addAll(videoListIn.getVideoList());}}System.out.println("获取的总数为,videosOut:" + videosOut.size());return videosOut;}/*** 获取分页视频列表   -最多200个** @param catId    分类id* @param pageNo   页数   1开始* @param pageSize 每页数量 最大两百* @return GetVideoListResponse 获取视频列表响应数据* @throws Exception*/public static GetVideoListResponse getVideoList(Long catId, Integer pageNo, Integer pageSize) throws Exception {DefaultAcsClient client = OSSUploadVideoDemo.initVodClient(OSSUploadVideoDemo.accessKeyId, OSSUploadVideoDemo.accessKeySecret);  // 发送请求客户端GetVideoListRequest request = new GetVideoListRequest();// 分别取一个月前、当前时间的UTC时间作为筛选视频列表的起止时间// 视频创建的起始时间,为UTC格式request.setCateId(catId);// 视频状态,默认获取所有状态的视频,多个用逗号分隔// request.setStatus("Uploading,Normal,Transcoding");request.setPageNo(pageNo);request.setPageSize(pageSize);return client.getAcsResponse(request);}/*** 本地文件上传接口** @param accessKeyId* @param accessKeySecret* @param title* @param fileName* @param cateId          分类id*/public static UploadVideoResponse testUploadVideo(String accessKeyId, String accessKeySecret, String title, String fileName, Long cateId) {log.info("accessKeyId:{},accessKeySecret:{},title:{},fileName:{}", accessKeyId, accessKeySecret, title, fileName);UploadVideoResponse response = null;try {UploadVideoRequest request = new UploadVideoRequest(accessKeyId, accessKeySecret, title, fileName);/* 可指定分片上传时每个分片的大小,默认为2M字节 */request.setPartSize(2 * 1024 * 1024L);/* 可指定分片上传时的并发线程数,默认为1,(注:该配置会占用服务器CPU资源,需根据服务器情况指定)*/request.setTaskNum(1);/* 是否开启断点续传, 默认断点续传功能关闭。当网络不稳定或者程序崩溃时,再次发起相同上传请求,可以继续未完成的上传任务,适用于超时3000秒仍不能上传完成的大文件。注意: 断点续传开启后,会在上传过程中将上传位置写入本地磁盘文件,影响文件上传速度,请您根据实际情况选择是否开启*///request.setEnableCheckpoint(false);/* OSS慢请求日志打印超时时间,是指每个分片上传时间超过该阈值时会打印debug日志,如果想屏蔽此日志,请调整该阈值。单位: 毫秒,默认为300000毫秒*///request.setSlowRequestsThreshold(300000L);/* 可指定每个分片慢请求时打印日志的时间阈值,默认为300s*///request.setSlowRequestsThreshold(300000L);/* 是否显示水印(可选),指定模板组ID时,根据模板组配置确定是否显示水印*///request.setIsShowWaterMark(true);/* 设置上传完成后的回调URL(可选),建议您通过点播控制台配置事件通知,参见文档 https://help.aliyun.com/document_detail/55627.html *///request.setCallback("http://callback.sample.com");/* 自定义消息回调设置(可选),参数说明参考文档 https://help.aliyun.com/document_detail/86952.html#UserData */// request.setUserData("{\"Extend\":{\"test\":\"www\",\"localId\":\"xxxx\"},\"MessageCallback\":{\"CallbackURL\":\"http://test.test.com\"}}");/* 视频分类ID(可选) */request.setCateId(cateId);/* 视频标签,多个用逗号分隔(可选) *///request.setTags("标签1,标签2");/* 视频描述(可选) *///request.setDescription("视频描述");/* 封面图片(可选) *///request.setCoverURL("http://cover.sample.com/sample.jpg");/* 模板组ID(可选) */request.setTemplateGroupId("cfafe6e54e9a40"); /* 工作流ID(可选) *///request.setWorkflowId("9577859b0177b");/* 存储区域(可选) *///request.setStorageLocation("in-201703232118266-5sejdln9o.oss-cn-shanghai.aliyuncs.com");/* 开启默认上传进度回调 *///request.setPrintProgress(false);/* 设置自定义上传进度回调 (必须继承 VoDProgressListener) *///request.setProgressListener(new PutObjectProgressListener());/* 设置您实现的生成STS信息的接口实现类*/// request.setVoDRefreshSTSTokenListener(new RefreshSTSTokenImpl());/* 设置应用ID*///request.setAppId("app-1000000");/* 点播服务接入点 */request.setApiRegionId("cn-shanghai");  // 内网上传指定传输
//            /* ECS部署区域*/request.setEcsRegionId("cn-shanghai");  // 内网上传指定传输UploadVideoImpl uploader = new UploadVideoImpl();response = uploader.uploadVideo(request);log.info("RequestId=" + response.getRequestId() + "\n");  //请求视频点播服务的请求IDif (response.isSuccess()) {log.info("VideoId=" + response.getVideoId() + "\n");} else {/* 如果设置回调URL无效,不影响视频上传,可以返回VideoId同时会返回错误码。其他情况上传失败时,VideoId为空,此时需要根据返回错误码分析具体错误原因 */log.info("VideoId=" + response.getVideoId() + "\n");log.info("ErrorCode=" + response.getCode() + "\n");log.info("ErrorMessage=" + response.getMessage() + "\n");}// 上线注释要去除掉File file = new File(fileName);file.delete();} catch (Exception e) {log.info("出错了msg6:{}", e.getMessage());}return response;}}

一起学习,一起进步,有建议请提出。

阿里云OSS视频文件迁移视频点播,并导出媒资excel表相关推荐

  1. 使用阿里云OSS完成文件的上传样例

    使用阿里云OSS完成文件的上传 基础条件: 提前注册过阿里云账户 账户里有余额(文件上传按流量收费) 开通过OSS的基础服务 如果有以上基础条件不满足的小伙伴,去度娘了解一下. 前言 有过基础的小伙伴 ...

  2. 阿里云oss视频上传后,如何获取视频封面

    前言:在阿里云oss视频上传后,我们如何获取视频封面呢?而不是通过上传方式获取封面.其实OSS本身提供了视频截帧功能 OSS提供的视频截帧功能和OSS图片服务功能使用的方式是类似的,都是通过传入x-o ...

  3. 小程序配置阿里云OSS下载文件,在请求头里配置生成强制下载链接,(拿到下载链接可以下载文件至本地)

    小程序配置阿里云OSS下载文件,在请求头里配置生成强制下载链接,(拿到下载链接可以下载文件至本地)(Win10电脑开发环境)**这里只说明小程序端问题**<菜鸡总结大神勿喷!蟹蟹~> 大体 ...

  4. 使用阿里云OSS实现文件上传

    概述场景 文件上传,是程序开发中必须会使用到的一个功能,比如: 添加商品,用户头像,文章封面等需求 富文本编辑(插件文件上传) 文件上传的原理是什么? 我们为什么要实现文件上传,其实就要共享资源,大家 ...

  5. 前后端分离项目知识汇总(阿里云Oss,EasyExcel,视频点播,SpringCloud,Redis,Nuxt)

    整合篇一 前言 整合CRUD 前后端对接流程 添加路由 点击路由显示页面 在api文件夹创建js文件,定义接口地址和参数 创建vue页面引入js文件,调用方法实现功能 多条件查询 删除功能 增加功能 ...

  6. wget下载阿里云oss的文件报错403

    问题 在实际工作中,我们为了方便,会将一些脚本储存在云端(阿里云OSS),这样方便我们使用和下载,但是在实际的使用过程中,我们会遇到一些问题. 示例链接:https://djxlsp.oss-cn-s ...

  7. 利用阿里云OSS对文件进行存储,上传等操作

    --pom.xml加入阿里OSS存储依赖 <!--阿里云OSS存储--> <dependency><groupId>com.aliyun.oss</group ...

  8. Java调用阿里云OSS下载文件

    1.准备工作 具体细节参考Java调用阿里云oss_迷途知返-的博客-CSDN博客_java使用阿里云oss. 2.项目需求 我这里只需要根据文件名称把文件从oss下载下来即可,参考阿里云官网指导:下 ...

  9. 阿里云 oss多文件上传

    平时在做 oss 上传时,通过都是单个文件上传,但是前几天工作时涉及到多个文件的上传,在所有文件都上传完成后才能再做后续的代码执行.于是在原有的oss上传基础上添加for循环去挨个上传. 介绍一下,o ...

最新文章

  1. 没事抽空学——常用界面组件属性
  2. 通配符及输入输出重定向、管道符和作业控制
  3. Linux下C高手成长过程----经典书籍推荐
  4. Android 自定义view的知识梳理。
  5. element-ui表单校验
  6. 关于ssm框架的全部整合(一) 2021.05.09
  7. 零基础学sql要多久_成人零基础学习钢琴,要多久能学会?
  8. 放弃微博,继续回来写月经
  9. 苹果Mac测试及维护工具:​​​​​​​​Techtool Pro
  10. 华三交换机配置基础及讲解
  11. 云网融合个人浅析(一)
  12. MATLAB的卡尔曼滤波函数与实例
  13. 实用工具系列 - Pycharm安装下载使用
  14. 数据结构 —— 队列
  15. “室友靠这个拿到了华为50万年薪,太牛逼了…”
  16. 《计算机操作系统》重点知识笔记整理(一)
  17. ChatGPT of Siri 快捷指令语音免魔法3.5版+网页版 - TDChat
  18. springboot项目导入idea中环境配置相关问题解决
  19. day26-多进程多线程
  20. python 代码转程序_如何用pyinstaller把自己编写的python源代码转换成可执行程序?...

热门文章

  1. java中double数据保留有效位数
  2. 《Servlet、JSP和Spring MVC初学指南》——第2章 会话管理 2.1URL重写
  3. 浏览器缓存和vue-cli缓存策略
  4. Vue2.0 Vue路由_路由的几个注意点
  5. 轻松一下:程序员经典表情包
  6. 附参考文献丨艾美捷Cholesterol胆固醇说明书
  7. MathType与Office 2019的兼容问题解决方法
  8. 人口流向数据_人口流向图正在悄然改写,谁会是新的机遇之城?
  9. Linux中POSIX文件锁的实现
  10. docker安装和操作