aliyun视频点播vod
一、阿里云視頻點播技術能力盤點
參考文章:
https://blog.csdn.net/qq_33857573/article/details/79564255
?
視頻點播(ApsaraVideo for VoD)是集音視頻采集、編輯、上傳、自動化轉碼處理、媒體資源管理、分發加速于一體的一站式音視頻點播解決方案。
1、應用場景
- 音視頻網站:無論是初創視頻服務企業,還是已擁有海量視頻資源,可定制化的點播服務幫助客戶快速搭建擁有極致觀看體驗、安全可靠的視頻點播應用。
- 短視頻:集音視頻拍攝、特效編輯、本地轉碼、高速上傳、自動化云端轉碼、媒體資源管理、分發加速、播放于一體的完整短視頻解決方案。目前已幫助1000+APP快速實現手機短視頻功能。
- 直播轉點播:將直播流同步錄制為點播視頻,用于回看。并支持媒資管理、媒體處理(轉碼及內容審核/智能首圖等AI處理)、內容制作(云剪輯)、CDN分發加速等一系列操作。
- 在線教育:為在線教育客戶提供簡單易用、安全可靠的視頻點播服務??赏ㄟ^控制臺/API等多種方式上傳教學視頻,強大的轉碼能力保證視頻可以快速發布,覆蓋全網的加速節點保證學生觀看的流暢度。防盜鏈、視頻加密等版權保護方案保護教學內容不被竊取。
- 視頻生產制作:提供在線可視化剪輯平臺及豐富的OpenAPI,幫助客戶高效處理、制作視頻內容。除基礎的剪切拼接、混音、遮標、特效、合成等一系列功能外,依托云剪輯及點播一體化服務還可實現標準化、智能化剪輯生產,大大降低視頻制作的檻,縮短制作時間,提升內容生產效率。
- 內容審核:應用于短視頻平臺、傳媒行業審核等場景,幫助客戶從從語音、文字、視覺等多維度精準識別視頻、封面、標題或評論的違禁內容進行AI智能審核與人工審核。
2、功能介紹
二、開通視頻點播云平臺
1、選擇視頻點播服務
產品->企業應用->視頻云->視頻點播
2、開通視頻點播
3、選擇按使用流量計費
4、資費說明
https://www.aliyun.com/price/product?spm=a2c4g.11186623.2.12.7fbd59b9vmXVN6#/vod/detail
- 后付費
- 套餐包
- 欠費說明
- 計費案例:https://help.aliyun.com/document_detail/64032.html?spm=a2c4g.11186623.4.3.363db1bcfdvxB5
?
5、整體流程
使用視頻點播實現音視頻上傳、存儲、處理和播放的整體流程如下:
- 用戶獲取上傳授權。
- VoD下發 上傳地址和憑證 及 VideoId。
- 用戶上傳視頻保存視頻ID(VideoId)。
- 用戶服務端獲取播放憑證。
- VoD下發帶時效的播放憑證。
- 用戶服務端將播放憑證下發給客戶端完成視頻播放。
三、視頻點播服務的基本使用
完整的參考文檔
https://help.aliyun.com/product/29932.html?spm=a2c4g.11186623.6.540.3c356a58OEmVZJ
?
1、設置轉碼格式
選擇全局設置 > 轉碼設置,單擊添加轉碼模板組。
在視頻轉碼模板組頁面,根據業務需求選擇封裝格式和清晰度。
或直接將已有的模板設置為默認即可
2、分類管理
選擇全局設置 > 分類管理
?
3、上傳視頻文件
?
選擇媒資庫 > 音視頻,單擊上傳音視頻
?
4、配置域名
音視頻上傳完成后,必須配一個已備案的域名,并完成CNAME綁定
得到CNAME
在購買域名的服務商處的管理控制臺配置域名解析
5、在控制臺查看視頻
此時視頻可以在阿里云控制臺播放
?
6、獲取web播放器代碼
?
?
?
服務端SDK
1、簡介
sdk的方式將api進行了進一步的封裝,不用自己創建工具類。
我們可以基于服務端SDK編寫代碼來調用點播API,實現對點播產品和服務的快速操作。
?
2、功能介紹
- SDK封裝了對API的調用請求和響應,避免自行計算較為繁瑣的 API簽名。
- 支持所有點播服務的API,并提供了相應的示例代碼。
- 支持7種開發語言,包括:Java、Python、PHP、.NET、Node.js、Go、C/C++。
- 通常在發布新的API后,我們會及時同步更新SDK,所以即便您沒有找到對應API的示例代碼,也可以參考舊的示例自行實現調用。
?
二、使用SDK
1、安裝
參考文檔:https://help.aliyun.com/document_detail/57756.html
添加maven倉庫的配置和依賴到pom
<repositories><repository><id>sonatype-nexus-staging</id><name>Sonatype Nexus Staging</name><url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository> </repositories> <dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-core</artifactId><version>4.3.3</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-vod</artifactId><version>2.15.5</version></dependency><dependency><groupId>com.google.code.gson</groupId><artifactId>gson</artifactId><version>2.8.2</version></dependency>?
2、初始化
參考文檔:https://help.aliyun.com/document_detail/61062.html
根據文檔示例創建 AliyunVODSDKUtils.java
package com.atguigu.aliyunvod.util;public class AliyunVodSDKUtils {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;} }3、創建測試類
創建 VodSdkTest.java
package com.atguigu.aliyunvod;public class VodSdkTest {String accessKeyId = "你的accessKeyId";String accessKeySecret = "你的accessKeySecret";}三、創建測試用例
參考文檔:https://help.aliyun.com/document_detail/61064.html
1、獲取視頻播放憑證
根據文檔中的代碼,修改如下
/*** 獲取視頻播放憑證* @throws ClientException*/ @Test public void testGetVideoPlayAuth() throws ClientException {//初始化客戶端、請求對象和相應對象DefaultAcsClient client = AliyunVodSDKUtils.initVodClient(accessKeyId, accessKeySecret);GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();try {//設置請求參數request.setVideoId("視頻ID");//獲取請求響應response = client.getAcsResponse(request);//輸出請求結果//播放憑證System.out.print("PlayAuth = " + response.getPlayAuth() + "\n");//VideoMeta信息System.out.print("VideoMeta.Title = " + response.getVideoMeta().getTitle() + "\n");} catch (Exception e) {System.out.print("ErrorMessage = " + e.getLocalizedMessage());}System.out.print("RequestId = " + response.getRequestId() + "\n"); }2、獲取視頻播放地址
/*** 獲取視頻播放地址* @throws ClientException*/ @Test public void testGetPlayInfo() throws ClientException {//初始化客戶端、請求對象和相應對象DefaultAcsClient client = AliyunVodSDKUtils.initVodClient(accessKeyId, accessKeySecret);GetPlayInfoRequest request = new GetPlayInfoRequest();GetPlayInfoResponse response = new GetPlayInfoResponse();try {//設置請求參數//注意:這里只能獲取非加密視頻的播放地址request.setVideoId("視頻ID");//獲取請求響應response = client.getAcsResponse(request);//輸出請求結果List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();//播放地址for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");}//Base信息System.out.print("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");} catch (Exception e) {System.out.print("ErrorMessage = " + e.getLocalizedMessage());}System.out.print("RequestId = " + response.getRequestId() + "\n"); }?
測試文件上傳
參考文檔:https://help.aliyun.com/document_detail/53406.html
一、安裝SDK
1、配置pom
<dependencies><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-core</artifactId></dependency><dependency><groupId>com.aliyun.oss</groupId><artifactId>aliyun-sdk-oss</artifactId></dependency><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-vod</artifactId></dependency><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-sdk-vod-upload</artifactId></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId></dependency><dependency><groupId>org.json</groupId><artifactId>json</artifactId></dependency><dependency><groupId>com.google.code.gson</groupId><artifactId>gson</artifactId></dependency><dependency><groupId>joda-time</groupId><artifactId>joda-time</artifactId></dependency> </dependencies>2、安裝非開源jar包(說明)
在本地Maven倉庫中安裝jar包:
下載視頻上傳SDK,解壓,命令行進入lib目錄,執行以下代碼
mvn install:install-file -DgroupId=com.aliyun -DartifactId=aliyun-sdk-vod-upload -Dversion=1.4.11 -Dpackaging=jar -Dfile=aliyun-java-vod-upload-1.4.11.jar然后在pom中引入jar包
<dependency><groupId>com.aliyun</groupId><artifactId>aliyun-sdk-vod-upload</artifactId><version>1.4.11</version> </dependency>3.application.properties
#阿里云 vod #不同的服務器,地址不同 aliyun.vod.file.keyid=your accessKeyId aliyun.vod.file.keysecret=your accessKeySecret# 最大上傳單個文件大小:默認1M spring.servlet.multipart.max-file-size=1024MB # 最大置總上傳的數據大小 :默認10M spring.servlet.multipart.max-request-size=1024MB4、logback.xml
?
5.創建常量類
ConstantPropertiesUtil.java
package com.guli.vod.util;@Component //@PropertySource("classpath:application.properties") public class ConstantPropertiesUtil implements InitializingBean {@Value("${aliyun.vod.file.keyid}")private String keyId;@Value("${aliyun.vod.file.keysecret}")private String keySecret;public static String ACCESS_KEY_ID;public static String ACCESS_KEY_SECRET;@Overridepublic void afterPropertiesSet() throws Exception {ACCESS_KEY_ID = keyId;ACCESS_KEY_SECRET = keySecret;} }6. 創建阿里云初始化工具類
package com.guli.vod.util;public class AliyunVodSDKUtils {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;} }7.視頻文件上傳到阿里云
package com.guli.vod.service.impl;@Service public class VideoServiceImpl implements VideoService {@Overridepublic String uploadVideo(MultipartFile file) {try {InputStream inputStream = file.getInputStream();String originalFilename = file.getOriginalFilename();String title = originalFilename.substring(0, originalFilename.lastIndexOf("."));UploadStreamRequest request = new UploadStreamRequest(ConstantPropertiesUtil.ACCESS_KEY_ID,ConstantPropertiesUtil.ACCESS_KEY_SECRET,title, originalFilename, inputStream);UploadVideoImpl uploader = new UploadVideoImpl();UploadStreamResponse response = uploader.uploadStream(request);//如果設置回調URL無效,不影響視頻上傳,可以返回VideoId同時會返回錯誤碼。// 其他情況上傳失敗時,VideoId為空,此時需要根據返回錯誤碼分析具體錯誤原因String videoId = response.getVideoId();if (!response.isSuccess()) {String errorMessage = "阿里云上傳錯誤:" + "code:" + response.getCode() + ", message:" + response.getMessage();log.warn(errorMessage);if(StringUtils.isEmpty(videoId)){throw new GuliException(20001, errorMessage);}}return videoId;} catch (IOException e) {throw new GuliException(20001, "guli vod 服務上傳失敗");}} }8.如果使用到nginx的話需要配nginx
配置nginx上傳文件大小,否則上傳時會有?413 (Request Entity Too Large)?異常
將接口地址加入nginx配置
location ~ /***/ { proxy_pass http://127.0.0.1:****; }配置nginx上傳文件大小,否則上傳時會有 413 (Request Entity Too Large) 異常
打開nginx主配置文件nginx.conf,找到http{},添加
client_max_body_size 1024m;重啟nginx
nginx -s reload9.刪除視頻
@Override public void removeVideo(String videoId) {try{DefaultAcsClient client = AliyunVodSDKUtils.initVodClient(ConstantPropertiesUtil.ACCESS_KEY_ID,ConstantPropertiesUtil.ACCESS_KEY_SECRET);DeleteVideoRequest request = new DeleteVideoRequest();request.setVideoIds(videoId);DeleteVideoResponse response = client.getAcsResponse(request);System.out.print("RequestId = " + response.getRequestId() + "\n");}catch (ClientException e){throw new GuliException(20001, "視頻刪除失敗");} }?
總結
以上是生活随笔為你收集整理的aliyun视频点播vod的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 介绍两个ios手机测试的辅助工具
- 下一篇: 大地坐标系(WGS84)转空间直角坐标系