The ApsaraVideo for Short Video server handles data exchange, business logic processing, and operational data management between the ApsaraVideo for Short Video app and ApsaraVideo VOD. This topic describes how to integrate the ApsaraVideo for Short Video server.
Prerequisites
An Alibaba Cloud account is created and real-name verification is complete. To create an Alibaba Cloud account, visit the Alibaba Cloud official website. For more information, see Create an Alibaba Cloud account.
Elastic Compute Service (ECS) is activated and an instance is configured. For more information, see Activate and configure an ECS service.
JDK 8 is installed on the ECS server.
MySQL 5.7 is installed on the ECS server. For more information, see Install and configure a MySQL database. After your service is published, we recommend that you use ApsaraDB RDS. For more information, see ApsaraDB RDS.
ApsaraVideo VOD is activated and the required templates are configured in the console. For more information, see Activate and configure ApsaraVideo VOD.
Procedure
Upload the source code
Download the source code for the ApsaraVideo for Short Video server and management console. For the download URL, see ApsaraVideo for Short Video SDK.
On the server where the source code file is saved, run the following command to upload the source code file to the ECS server.
scp <source_code_file> user@<IP_address_of_the_ECS_server>:<upload_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 username for the ECS server. 10.0.0.0 is the IP address of the ECS server. /home/user/workspace/ is the upload path.
NoteThe sample information, such as the source code file, ECS server username, ECS server IP address, and upload path, is for reference only. Replace the sample information with your actual information.
Log on to the ECS server and decompress the source code file.
cd /home/user/workspace
unzip ApsaraVideo_QuVideo_v1.4.0_Server_20191226.zip
NoteIf unzip is not installed, run the sudo apt install unzip command to install it.
Initialize and configure the database
You can build your own music library.
The data structure of the returned data must be the same as the data structure used to retrieve the music list from the Alibaba Cloud service. Otherwise, the request fails.
If you use a custom data structure, you must adjust the code logic at 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
NoteThe appserver_create_table.sql script not only creates a table but also uses an INSERT statement to create a console administrator account. The username is admin and the password is 123456. After you integrate the console, you can use this account to log on to the demo console as an administrator.
Modify the case sensitivity rule of the database.
Edit the configuration file of the database.
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 the Esc key and enter :wq! to save the file and exit.
Restart the database to complete the configuration.
sudo service mysql restart
Configure the database address.
Edit the configuration file of the source code.
vim /home/user/workspace/ApsaraVideo_QuVideo_v1.4.0_Server_20191226/src/main/resources/application.properties
Press the I key and modify the file as follows.
spring.datasource.url = jdbc:mysql://Database IP address (127.0.0.1):3306/Database name (voddemo)?useSSL=false&useUnicode=true&characterEncoding=UTF-8 spring.datasource.username = Logon username of the database, for example, admin spring.datasource.password = Logon password of the databaseNoteIf the database and the server both run on the 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 that you created during initialization is named voddemo.
Press the Esc key and enter :wq! to save the file and exit.
Configure a RAM role
The general steps are the same as those described in Create a role. After you complete Step 6 in that topic to select permissions, perform the following steps. You can specify a custom role name. This topic uses alivc-demo-role as an example.
On the Role Management page, click the name of the RAM role you created, such as alivc-demo-role, to query its Alibaba Cloud Resource Name (ARN). We recommend recording the RAM role name and ARN for later use.
On the Role Management page, click the name of your RAM role, such as alivc-demo-role. Click the Trust Policy tab and then click Edit Trust Policy. Modify the trust policy as follows:
{ "Statement": [ { "Action": "sts:AssumeRole", "Effect": "Allow", "Principal": { "Service": [ "ecs.aliyuncs.com" ] } } ], "Version": "1" }This indicates that the role is a service role and can be assumed by the trusted Alibaba Cloud service (ECS). If you do not modify the trust policy, the RAM role cannot be attached to the ECS instance.
Set the instance ID parameter to
["Instance ID"].Attach the RAM role to the ECS instance.
Call the AttachInstanceRamRole API operation of ECS in OpenAPI Explorer. For more information, see OpenAPI Explorer.
NoteRegionId: The ID of the region where the ECS instance is located, such as China (Shanghai). You can query the region ID in the ECS console.
RamRoleName: The name of the RAM role. In this example, the name is alivc-demo-role.
InstanceIds: The ID of the server-side ECS instance to which you want to attach the RAM role. You can query the instance ID in the ECS console. The ID must be in an array format, such as ["i-bp135jrddxxf9tgo****"].
Click Invoke. If the call succeeds, a success message is displayed in the debug results on the right.
Run the following command in the ECS terminal to check whether the RAM role is associated with the ECS instance.
curl http://100.100.100.200/latest/meta-data/ram/security-credentials/alivc-demo-role
If the following information is displayed, the temporary authorization from Security Token Service (STS) is returned, which indicates that 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" }NoteYou can attach only one RAM role to an ECS instance. To change the RAM role, call the DetachInstanceRamRole operation in OpenAPI Explorer to detach the RAM role from the ECS instance. Then, call AttachInstanceRamRole to attach a new RAM role.
Configure RAM information.
Edit the configuration file of the source code.
vim /home/user/workspace/ApsaraVideo_QuVideo_v1.4.0_Server_20191226/src/main/resources/application.properties
Press the I key and modify the file as shown in the following example.
roleArn = XXXXXXX:role/alivc-demo-role roleSessionName = vod-role roleName = alivc-demo-role
NoteREGION_CN_HANGZHOU indicates the region where the ApsaraVideo VOD service is located, such as cn-shanghai for China (Shanghai).
roleArn indicates the ARN retrieved from the RAM console.
roleSessionName indicates the session name of the temporary token. You can specify a custom name.
roleName indicates the name of the RAM role retrieved from the RAM console. In this example, the name is alivc-demo-role.
Press the Esc key and enter :wq! to save the file and exit.
Configure ApsaraVideo VOD.
Edit the configuration file of the source code.
vim /home/user/workspace/ApsaraVideo_QuVideo_v1.4.0_Server_20191226/src/main/resources/application.properties
Press the I key and modify the file as follows.

Parameter name
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 the publish-before-review feature for long videos.
TAB_TEMPLATEGROUP_ID
No
The ID of the Narrowband HD transcoding template group. Configure this parameter to recommend Narrowband HD videos in the console. If this parameter is not specified, an error occurs when you recommend Narrowband HD videos.
DOMAIN_NAME
Yes
The address of the ECS server. In this example, the address is http://10.10.10.101:8080/.
AVATAR_DOMAIN_NAME
No
The address of profile picture resources, which is the static resource address of the ECS server. In this example, the address is http://10.10.10.101:8080/resource/.
AVATAR_URL
No
A list of profile picture filenames, such as 1.png,2.png.
NotePlace the corresponding profile picture files 1.png and 2.png in the /home/user/workspace/ApsaraVideo_QuVideo_v1.4.0_Server_20191226/src/main/webapp/resource directory. If the profile picture service is not configured, mobile client users will not have profile pictures. This does not affect other features.
VOD_REGIONID
Yes
The region where the VOD service is located. In this example, the region is cn-shanghai.
policy
Yes
An extra permission restriction to add when a role is assumed. For more information, see Use RAM policies for custom authorization.
CALLBACK_PRIVETEKEY
Yes
The authentication key in the callback authentication configuration. For more information, see Callback Settings.
CALLBACK_NAME
Yes
The callback URL, which is http://<Public IP address of the ECS instance>:8080/vodcallback/callback. In this example, the URL is http://10.10.10.101:8080/vodcallback/callback.
AUDIT_SETTINGS_FLAG
Yes
The review setting. The default value is on. Valid values:
on: review-before-publish.
off: publish-before-review.
package_name
Yes
The valid package names in 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.
Notecom.aliyun.apsara.svideo is the package name of the Android client in this example.
If the Bundle Identifier for the iOS client is already registered, the client fails to run. You must customize a Bundle Identifier, such as com.<Company name>.<Project name>, use it to sign the iOS client, and add it to the package_name parameter to ensure valid access.
The interceptor allows only mobile apps with valid package names to access the server. Otherwise, requests from the mobile client fail. For example, the error message "Request failed: forbidden (403)" is returned.
Press the Esc key, enter :wq!, and press Enter to save your changes and exit.
Run the service.
Compile and package.
cd /home/user/workspace/ApsaraVideo_QuVideo_v1.4.0_Server_20191226
mvn clean package -Dmaven.test.skip=true
NoteIf Maven is not installed, run apt install maven to install it.
The time required for packaging depends on the server bandwidth and performance. In this example, the first packaging takes about 30 minutes.
After packaging is complete, the sdk-api-0.0.1-SNAPSHOT.jar file is generated in the /home/user/workspace/ApsaraVideo_QuVideo_v1.4.0_Server_20191226/target/ directory.
Deploy the JAR package 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 &
NoteWhen the command runs, a nohup prompt appears. Press Enter to run the program in the background.
After the command runs, the nohup.out log file is generated in the current directory. Run the cat nohup.out command to view the log. If the log contains
start success, the service has started successfully.If your ECS instance has low memory and you need to repackage and deploy the server-side source code, run the jps command to find the process ID (PID) of the current JAR program. Then, run kill -9 <PID> to terminate the process. You can then repackage and deploy the source code. Otherwise, the packaging process may fail due to insufficient memory.