当前位置:网站首页>Subscription and use of Alibaba cloud video on demand service
Subscription and use of Alibaba cloud video on demand service
2022-07-27 19:10:00 【Xiao Li, who loves traveling】
The opening and use of Alibaba cloud video on demand service
List of articles
- The opening and use of Alibaba cloud video on demand service
- Preface : What is Alibaba cloud video on demand service ?
- One 、 Open Alibaba cloud VOD service
- Two 、 Basic operation of console
- 3、 ... and 、JAVA JDK Operate Alibaba cloud video on demand service
- Four 、 actual combat
- ** First step : establish service_vod engineering , Introduce dependencies **
- ** The second step : Initialize object **
- ** The third step : Get video address **
- ** Step four : Get video credentials **
- Step five : Upload videos locally to Alibaba cloud
- Step six : Alicloud installation depends on local maven Warehouse
- Xiaobai conclusion
Preface : What is Alibaba cloud video on demand service ?

video on demand (ApsaraVideo
VoD, abbreviation VoD) It's video collection 、 edit 、 Upload 、 Media resource management 、 Automatic transcoding ( Narrowband HD TM)、 Video audit analysis 、 A one-stop audio and video on demand solution with distribution acceleration .
One 、 Open Alibaba cloud VOD service
1 Enter alicloud's official website . Find the VOD service entry in the product category , Click to enter

2 Click open now 
3 I choose to pay by traffic 
4 Here you can view the charging details of Alibaba cloud video on demand service , You can see that the charging of video on demand service is quite cheap .

5 This page is the console homepage of Alibaba cloud video on demand service 
Two 、 Basic operation of console
1 Upload audio and video : Click Add tone / video 
2 Select a file to upload 
3 Click Start upload 
4 Refresh the page , You can find that the video uploaded just now has been uploaded successfully 
5 You can click to see the uploaded video 
6 Add transcoding template group 
7 Set the user-defined template group as the default template Group , Now upload an audio 
8 You can see the wind .mp3 It was transcoded 
9 For more detailed operations, please refer to Alibaba cloud official documents
3、 ... and 、JAVA JDK Operate Alibaba cloud video on demand service
1 Click SDK file 
2 find JAVA SDK
3 Open in the help document center 
4 JAVA SDK home page 
Two terms :
API: Alibaba cloud provides fixed addresses , Just call this fixed address , Want to pass parameters by value , Realization function . Used HttpClient technology
SDK: It's right API Encapsulation , Call the classes or interfaces provided by Alibaba cloud to realize video functions
It is highly recommended by the government SDK instead of API
5 install SDK
(1) add to maven Warehouse
<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>
(2) introduce jar Packet dependency
<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>
Four 、 actual combat
First step : establish service_vod engineering , Introduce dependencies
pom.xml
<dependencies>
<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>
</dependencies>
The second step : Initialize object
Interpretation of official documents : https://help.aliyun.com/document_detail/61062.html?spm=a2c4g.11186623.6.908.11153815MJ9vxr
InitObject.java
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
@SuppressWarnings("all")
public class InitObject {
public static DefaultAcsClient initVodClient(String accessKeyId, String accessKeySecret) throws ClientException {
String regionId = "cn-shanghai"; // On demand service access area
DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
DefaultAcsClient client = new DefaultAcsClient(profile);
return client;
}
}
The third step : Get video address
Be careful :initVodClient() The two parameters of the method are Alibaba cloud user security information management AccessKey and AccessSecret
Accessible https://usercenter.console.aliyun.com/#/manage/ak Set relevant settings in
TestVod.java
/** * Get video Url Address * @throws ClientException */
public static void getPlayUrl() throws ClientException {
//1 According to the video ID Get the video playback address
//1.1 Create initialization object
DefaultAcsClient client = InitObject.initVodClient("accessKey", "accessSecret");
//1.2 Create get video address request and response
GetPlayInfoRequest request = new GetPlayInfoRequest();
GetPlayInfoResponse response = new GetPlayInfoResponse();
//1.3 towards request Set the video in the object ID
request.setVideoId("c833930e3e804a768af63826a862eeab");
//1.4 Call the method in the initialization object , Pass on request, get data
response = client.getAcsResponse(request);
List<GetPlayInfoResponse.PlayInfo> infoList = response.getPlayInfoList();
for (GetPlayInfoResponse.PlayInfo playInfo : infoList) {
System.out.println("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");
}
//Base Information
System.out.println("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");
}
The effect is as shown in the picture

Step four : Get video credentials
When the audio is encrypted , Cannot access directly through address , At this time, you can access through video credentials , The video voucher is provided by Alibaba cloud API Generate
/** * Get video credentials * @throws ClientException */
public static void getPlayAuth() throws ClientException {
//1 According to the video ID Get the video playback address
//1.1 Create initialization object
DefaultAcsClient client = InitObject.initVodClient("accessKey", "accessSecret");
//1.2 Create initialization object
GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();
//1.3 towards request Object settings video ID value
request.setVideoId("c833930e3e804a768af63826a862eeab");
//1.3 Call the method in the initialization object to get the voucher
response = client.getAcsResponse(request);
String playAuth = response.getPlayAuth();
System.out.println("playAuth: " + playAuth);
}
The effect is as shown in the picture 
Step five : Upload videos locally to Alibaba cloud
First, load a new Jar package ( I stepped on a pit here , The original dependency cannot be loaded into maven, So I had to import one manually jar package ,maven Dependence is replaced by the first step of dependence )
Almost doubted life !
This jar Bag is aliyun-java-vod-upload-1.4.12.jar I found it in the official documents
Address :
https://help.aliyun.com/document_detail/53406.html?spm=a2c4g.11186623.6.1066.64fd7bdcEUIU0T
Be careful !!! The official document explains as follows :
Be careful : Some dependencies are listed below jar The version of the package , You can directly add maven rely on , Can also be VODUploadDemo-java-1.4.12.zip Everything in the bag jar Packages are introduced into your project for use . among **,aliyun-java-vod-upload-1.4.12.jar Not officially open source yet , Please introduce jar Package into your project for use .**
That is to say jar The package is not at all maven Warehouse , All cannot pass directly maven download , You need to install this dependency manually !!!

TestUploadVod.java
import com.aliyun.vod.upload.impl.UploadVideoImpl;
import com.aliyun.vod.upload.req.UploadVideoRequest;
import com.aliyun.vod.upload.resp.UploadVideoResponse;
public class TestUploadVod {
public static void main(String[] args) {
String accessKeyId = "accessKeyId";
String accessKeySecret = "accessKeySecret";
String title = "100.mp4"; // File name after upload
String fileName = "G:\\1.mp4"; // Local file path and name
uploadVideoLocal(accessKeyId, accessKeySecret, title, fileName);
}
/** * * @param accessKeyId ID * @param accessKeySecret Secret key * @param title The file name after uploading * @param fileName Local file path before uploading */
public static void uploadVideoLocal(String accessKeyId, String accessKeySecret, String title, String fileName){
// How to upload video
UploadVideoRequest request = new UploadVideoRequest(accessKeyId, accessKeySecret, title, fileName);
/* You can specify the size of each slice when uploading slices , The default is 2M byte */
request.setPartSize(2 * 1024 * 1024L);
/* You can specify the number of concurrent threads during fragment upload , The default is 1,( notes : This configuration will occupy the server CPU resources , It needs to be specified according to the situation of the server )*/
request.setTaskNum(1);
UploadVideoImpl uploader = new UploadVideoImpl();
UploadVideoResponse response = uploader.uploadVideo(request);
if (response.isSuccess()) {
System.out.print("VideoId=" + response.getVideoId() + "\n");
} else {
/* If the callback is set URL Invalid , Does not affect the video upload , Can return VideoId At the same time, the error code will be returned . In other cases, the upload fails ,VideoId It's empty , At this time, you need to analyze the specific error reason according to the returned error code */
System.out.print("VideoId=" + response.getVideoId() + "\n");
System.out.print("ErrorCode=" + response.getCode() + "\n");
System.out.print("ErrorMessage=" + response.getMessage() + "\n");
}
}
}
Console output after successful operation 
View background , I found that the upload was successful ( Wasted a night of events ), Celebrate !

Step six : Alicloud installation depends on local maven Warehouse
Ali cloud, aliyun-java-vod-upload-1.4.12.jar There is no official open source , So I can only put this jar Pack into local warehouse
maven command
Get into jar Package directory , Input :
mvn install:install-file -DgroupId=com.aliyun -DartifactId=aliyun-sdk-vod-upload -Dversion=1.4.12 -Dpackaging=jar -Dfile=aliyun-java-vod-upload-1.4.12.jar
As shown in the figure , This Jar The package is successfully installed locally Maven The warehouse !
Xiaobai conclusion
1. Alibaba cloud is a leading technology in China and even in the world , I have studied Alibaba cloud before OSS service , Today I learned about Alibaba cloud's video on demand service , Later, I will learn about Alibaba cloud's SMS service .
2. Pay attention to official documents !!!

边栏推荐
- Greedy method, matroid and submodular function (refer)
- 200行代码快速入门文档型数据库MonogoDB
- C interface knowledge collection suggestions collection
- PHP string operation
- `this.$ Emit ` the child component passes multiple parameters to the parent component
- Big enemies, how to correctly choose the intended enterprises in the new testing industry?
- Code interview of Amazon
- Latex use - subfigure vertical graphics
- Sentinel1.8.4 persistent Nacos configuration
- The great idea of NS2
猜你喜欢

Docker - docker installation, MySQL installation on docker, and project deployment on docker

MySQL 04 advanced query (II)

2022备战秋招10W字面试小抄pdf版,附操作系统、计算机网络面试题

Nacos的基本使用(1)——入门

Leetcode first day of question brushing

如何用自动化测试搞垮团队

mysql学习笔记(1)——变量

Sentinel1.8.4 persistent Nacos configuration

JDBC MySQL 01 JDBC operation MySQL (add, delete, modify and query)

Express get/post/delete... Request
随机推荐
正则表达式的扩展
express get/post/delete...请求
Latex使用-控制表格或者图形的显示位置
WPS turns off annoying advertisements
专项测试之「 性能测试」总结
Ruiji takeout notes
The great idea of NS2
又有一个Repeater的例子
What if idea successfully connects to the database without displaying the table
Automatic testing of Web UI: Selenium syntax explanation is the most complete in the history
Leetcode brushes questions the next day
IDEA连接数据库时区问题,报红Server returns invalid timezone. Need to set ‘serverTimezone‘ property.
2022备战秋招10W字面试小抄pdf版,附操作系统、计算机网络面试题
Kinect for Unity3D——BackgroundRemovalDemo学习
Electromagnetic field learning notes - vector analysis and field theory foundation
Big enemies, how to correctly choose the intended enterprises in the new testing industry?
Ruiji takeout SQL table
log4j. Properties log details
An experience
MySQL 02 initial experience