The ApsaraVideo for Short Video server handles data exchange with the client app and ApsaraVideo VOD, processes business logic, and manages operational data. This topic explains the server-side integration process.
Prerequisites
-
An Alibaba Cloud account is created and identity verification is complete. To create an Alibaba Cloud account, visit the Alibaba Cloud official website. For more information, see Create an Alibaba Cloud account.
-
You have activated ECS and completed the required configurations. For more information, see Activate and configure ECS.
-
You have installed JDK 8 on your ECS instance.
-
You have installed a MySQL 5.7 database on your ECS instance. For more information, see Install and configure a MySQL database. After your service goes live, use ApsaraDB RDS for better stability and performance. For more information, see ApsaraDB RDS.
-
You have activated ApsaraVideo VOD and configured the required templates in the console. For more information, see Activate and configure ApsaraVideo VOD.
Procedure
Upload the source code
-
Download the source code for the AppServer and management console of ApsaraVideo for Short Video. For the download link, see ApsaraVideo for Short Video.
-
On the server where the source file is stored, run the following command to upload the source code package to the ECS instance.
scp <source_code_file> user@<ECS_instance_IP>:<destination_path>
scp ApsaraVideo_QuVideo_v1.4.0_Server_20191226.zip user@10.0.0.0:/home/user/workspace/
ApsaraVideo_QuVideo_v1.4.0_Server_20191226.zip is the source code file, user is the ECS instance username, 10.0.0.0 is the ECS instance IP address, and /home/user/workspace/ is the upload path.
NoteThe source code file, ECS username, ECS instance IP address, and upload path are examples. Replace the sample values with your actual information.
-
Log on to the ECS instance and unzip the source code package.
cd /home/user/workspace
unzip ApsaraVideo_QuVideo_v1.4.0_Server_20191226.zip
NoteIf unzip is not installed, run sudo apt install unzip.
Initialize and configure the database
You can build a self-managed music library.
-
The data structure returned by your service must match the one from the Alibaba Cloud service for music list retrieval; otherwise, the retrieval will fail.
-
If you use a custom data structure, adjust the code logic in the demo layer.
-
Create a database named voddemo.
cd /home/user/workspace/ApsaraVideo_QuVideo_v1.4.0_Server_20191226/sql
mysqladmin -u root -p create voddemo
-
Create a table and an administrator account.
mysql -u root -p voddemo < ./appserver_create_table.sql
NoteIn addition to creating the table, the appserver_create_table.sql script uses an INSERT statement to create a console administrator account with the username
adminand password123456. You can use this account to log on to the demo console as an administrator once the console is integrated. -
Modify the case sensitivity rule of the database.
-
Edit the database configuration file.
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
-
Press the I key and add
lower_case_table_names=1to the end of the file. -
Press Esc, then enter :wq! to save and exit.
-
Restart the database for the change to take effect.
sudo service mysql restart
-
-
Configure the database address.
-
Edit the source code configuration file.
vim /home/user/workspace/ApsaraVideo_QuVideo_v1.4.0_Server_20191226/src/main/resources/application.properties
-
Press I and modify the following parameters.
spring.datasource.url = jdbc:mysql://<Database_IP_address (e.g., 127.0.0.1)>:3306/<Database_name (e.g., voddemo)>?useSSL=false&useUnicode=true&characterEncoding=UTF-8 spring.datasource.username = <Database_username, e.g., admin> spring.datasource.password = <Database_password>Note-
If both the database and the server run on the same ECS instance, you can set the database IP address to 127.0.0.1. Otherwise, use the IP address of the machine where the database is located.
-
The database created during initialization is named voddemo.
-
-
Press Esc, then enter :wq! to save and exit.
-
Configure a RAM role
-
Follow the steps in Create a role. After selecting permissions in Step 6, proceed with the steps below. You can define a custom role name. This topic uses
alivc-demo-roleas an example. -
On the Roles page, click the name of the RAM role you created, for example,
alivc-demo-role, to find its ARN. Record the RAM role name and ARN for later use. -
On the Roles page, click the name of the RAM role you created, for example,
alivc-demo-role. Click the Trust Policy tab, then click Edit Trust Policy and modify the trust policy as follows:{ "Statement": [ { "Action": "sts:AssumeRole", "Effect": "Allow", "Principal": { "Service": [ "ecs.aliyuncs.com" ] } } ], "Version": "1" }This policy defines the role as a service role, which allows the trusted cloud service (ECS) to assume it. If the trust policy is not modified, the RAM role cannot be attached to an ECS instance.
The Instance ID parameter must be set to
["Instance ID"]. -
Attach the RAM role to the ECS instance.
Use the AttachInstanceRamRole API of ECS in the OpenAPI Explorer. For more information, see OpenAPI Explorer.
Note-
RegionId: The ID of the region where your ECS instance is located, for example, China (Shanghai). You can find this in the ECS console.
-
RamRoleName: The name of the RAM role. This example uses
alivc-demo-role. -
InstanceIds: The ID of the server-side ECS instance to which you want to attach the RAM role. You can find this in the ECS console. The ID must be in array format, for example:
["i-bp135jrddxxf9tgo****"].
Click Initiate Call. A successful call returns a success message in the debugging results on the right.
-
-
Run the following command in the ECS terminal to verify that the RAM role is associated with the ECS instance.
curl http://100.100.100.200/latest/meta-data/ram/security-credentials/alivc-demo-role
The following response indicates that the STS temporary authorization was successful, and the RAM role is associated with the ECS instance.
{ "AccessKeyId" : "STS.XXXXXXXXXXXX", "AccessKeySecret" : "XXXXXXXXXXXXXXXX", "Expiration" : "2020-11-20T14:33:31Z", "SecurityToken" : "XXXXXXXXXXXXXXXXXXXXXX", "LastUpdated" : "2020-11-20T08:33:31Z", "Code" : "Success" }NoteEach ECS instance can be attached to only one RAM role. To change the attached RAM role, first call DetachInstanceRamRole in the OpenAPI Explorer to detach the current role from the ECS instance, and then use AttachInstanceRamRole to attach the new RAM role.
-
Configure RAM-related information.
-
Edit the source code configuration file.
vim /home/user/workspace/ApsaraVideo_QuVideo_v1.4.0_Server_20191226/src/main/resources/application.properties
-
Press I and modify the file according to the example below.
roleArn = acs:ram::xxx:role/alivc-demo-role roleSessionName = vod-session roleName = alivc-demo-role# The following block contains outdated examples and should be ignored.Note-
The
REGION_CN_HANGZHOUparameter is deprecated. UseVOD_REGIONIDinstead, as specified in the ApsaraVideo VOD configuration section. -
roleArnspecifies the ARN obtained from the RAM console. -
roleSessionNamespecifies the session name for the temporary token. You can customize this name. -
roleNamespecifies the name of the RAM role obtained from the RAM console. In this example, the name isalivc-demo-role.
-
-
Press Esc, then enter :wq! to save and exit.
-
-
Configure ApsaraVideo VOD.
-
Edit the source code configuration file.
vim /home/user/workspace/ApsaraVideo_QuVideo_v1.4.0_Server_20191226/src/main/resources/application.properties
-
Press I and modify the parameters as needed.
# Transcoding template ID TEMPLATEGROUP_ID = xxx LONGVIDEO_TRANSCODE_TEMPLATEGROUP_ID = xxxxxxxx TAB_TEMPLATEGROUP_ID = xxxxxxxx # Domain name DOMAIN_NAME = http://xxx:8080/ AVATAR_DOMAIN_NAME = http://xxx:8080/resource/ AVATAR_URL = 1.png,2.png VOD_REGIONID = cn-hangzhou # Policy for ApsaraVideo VOD services policy = {"Version": "1", "Statement": [ {"Action": ["vod:*"], "Resource": ["*" ],"Effect": "Allow"}]} # Taihe Music appkey OPEN_API_URL = https://xxxxxxxx.xxxxxxxx.com Q_SOURCE = xxxxxxxx CALLBACK_PRIVETEKEY = VodTest01 CALLBACK_NAME = http://xxx:8080/vodcallback/callback APP_ID = app-1000000 AUDIT_SETTINGS_FLAG = on auth_key = xxxxx live_domain = http://xxxxx.aliyuncs.com package_name = IOS,ANDROID,TEST,com.aliyun.apsara.svideo,com.aliyun.apsaravideo,com.aliyun.solution.longvideoParameter
Required
Description
TEMPLATEGROUP_ID
Yes
The ID of the transcoding template group. For more information, see Transcoding template groups.
LONGVIDEO_TRANSCODE_TEMPLATEGROUP_ID
No
The transcoding template group used for long videos in a publish-before-review workflow.
TAB_TEMPLATEGROUP_ID
No
The ID of the Narrowband HD transcoding template group. After configuration, you can recommend Narrowband HD videos in the console. If this ID is not set, attempts to recommend Narrowband HD videos will fail.
DOMAIN_NAME
Yes
The address of the ECS instance. Example: http://10.10.10.101:8080/.
AVATAR_DOMAIN_NAME
No
The address for avatar resources, which is the static resource address of the ECS instance. Example: http://10.10.10.101:8080/resource/.
AVATAR_URL
No
A comma-separated list of avatar image filenames, such as
1.png,2.png.NotePlace the corresponding avatar image files,
1.pngand2.png, in the /home/user/workspace/ApsaraVideo_QuVideo_v1.4.0_Server_20191226/src/main/webapp/resource directory. If the avatar service is not configured, mobile users will not have avatars, but other functions will not be affected.VOD_REGIONID
Yes
The region where the ApsaraVideo VOD service is located. Example: cn-shanghai.
policy
Yes
A policy that further restricts permissions when the role is assumed. For more information, see Use RAM policies for custom authorization.
CALLBACK_PRIVETEKEY
Yes
The private key for callback authentication. For more information, see Callback Settings.
CALLBACK_NAME
Yes
The callback URL. Example: http://<Public_IP_of_ECS_instance>:8080/vodcallback/callback. This example uses http://10.10.10.101:8080/vodcallback/callback.
AUDIT_SETTINGS_FLAG
Yes
Specifies the content review mode. Default value:
on. Valid values:-
on: review-before-publish.
-
off: publish-before-review.
package_name
Yes
The valid package names for the interceptor. Separate multiple package names with commas. The default value is
IOS,ANDROID,TEST,com.aliyun.apsara.svideo,com.aliyun.apsaravideo,com.aliyun.solution.longvideo.Note-
com.aliyun.apsara.svideois the package name for the Android client in this example. -
If the Bundle Identifier for your iOS client is already registered, the client cannot run. You must use a custom Bundle Identifier, such as
com.<Company_name>.<Project_name>, for the iOS client signature and add it to thepackage_nameparameter to ensure valid access. -
The interceptor allows only mobile apps with valid package names to access the server. Otherwise, requests from the mobile client will be denied with a
403 Forbiddenerror.
-
-
Press Esc, then enter :wq! to save and exit.
-
-
Run the service.
-
Compile and package the code.
cd /home/user/workspace/ApsaraVideo_QuVideo_v1.4.0_Server_20191226
mvn clean package -Dmaven.test.skip=true
Note-
If Maven is not installed, run apt install maven to install it.
-
The packaging time depends on instance bandwidth and performance. In this example, the initial packaging takes about 30 minutes.
After packaging is complete, the
sdk-api-0.0.1-SNAPSHOT.jarfile is generated in the/home/user/workspace/ApsaraVideo_QuVideo_v1.4.0_Server_20191226/target/directory. -
-
Deploy the JAR file and start the service.
cd /home/user/workspace/ApsaraVideo_QuVideo_v1.4.0_Server_20191226/target
nohup java -jar sdk-api-0.0.1-SNAPSHOT.jar &
Note-
When the command is run, a nohup prompt appears. Press Enter to run the program in the background.
-
After the command is executed, a log file named
nohup.outis generated in the current directory. Run the cat nohup.out command to view the log. If the log contains thestart successmessage, the service has started successfully. -
If your ECS instance has a small amount of memory and you need to repackage and deploy the server source code, you can run the jps command to view the process ID of the currently running JAR program, and then run the kill -9 <JAR_process_ID> command to terminate the process before you repackage and deploy again. Otherwise, the packaging process will fail due to insufficient memory.
-
-