Let’s take a look at the final result:

Above is a composite video of two people. In the middle of the video, one person leaves and then rejoins the room.

1. Business scenarios

The business scenario is as follows: Videos live by multiple users (2-4 people) are combined into one video, during which two conditions must be met:

First: there may be one or more users off-line and re-enter (network poor and manual operation) for an indefinite number of times during recording;

Second: to ensure that the synthesized video and recording effect is the same must be synchronized (can not appear multiple video time mismatch).

Due to the above two conditions, so the implementation of the program is difficult, but fortunately, the author has found a sound network solution, to share with you.

Ii. Solution Overview

The disadvantage of using the interactive live broadcast and server recording of Sonnet is that sonnet does not provide online recording function and users need to deploy the recording server by themselves. The advantage is that the video recorded by sonnet is complete and can be viewed immediately after recording.

In this solution, one or more people can re-enter the room after leaving the room within a certain period of time (5 minutes or self-defined time), and the video recording will not be affected. Moreover, the video is synchronized, and multiple video times cannot be inconsistent.

Third, the recording scheme of sonnet

This section focuses on the video recording and synthesis function.

The recording server of soundnet needs to be configured by itself. First of all, you need to buy a Linux server, which only supports Linux at present, and then set up the server, as described below.

Server Configuration

1. Ubuntu 12.04+ X64 or CentOS 6.5+ X64

2, GCC 4.4+ (general Linux will be installed, use the command: GCC -v check version number)

3. Public IP address

4. Add the domain name qos.agoralab.co to the whitelist

5, 8.9 + NodeJS

NodeJS can be used to record the server, which is also a good thing for developers, after all, it reduces the threshold of application deployment. It is implemented by using: NodeJS Express framework to achieve Restful API invocation, NodeJS calls C++ plug-in, and then calls C++ recording SDK through the plug-in to complete the whole process, as shown in the following figure:

Next, the server deployment is officially started. The steps are as follows:

1. To download the NodeJs deployment program, visit github.com/AgoraIO/Bas… Download the zip and deploy it to your server.

2, download the SDK, recording visit: docs. Agora. IO/cn/Recordin…

3. Unpack the record SDK and copy it to the record/ SRC/SDK directory in the NodeJS deployment directory.

NPM install -g node-gyp;

5. Open the terminal, go to the agora-resting-recording-nodejs /record directory, run the sh file sh build.sh to compile the C++ call, and then the agorasdk.node file is displayed.

For the above operations, you can also check the official website document (English) : t.cn/Eq1ZncK

Once you’ve done that, the real pit is waiting for you. Here’s the point.

[Program deployment pit]

After performing the above operations, the following two Settings are required to record the video normally:

Chmod -r 777 /{your directory}/ agora-resting-recording-nodejs;

2. Set your interactive live streaming client to live streaming mode, because NodeJS has written dead live streaming mode, and the interactive live streaming client has non-live streaming mode by default, so you need to set: SetChannelProfile (1) and setClientRole(1), otherwise the recorded video is a solid color background without content;

Congratulations, you can finally run the video recording after the above configuration, you need to run the NodeJS Express project before starting:

1. On a terminal, switch to the Agora-resting-recording-nodejs /server directory and run NPM install.

2. Run the project using terminal Node app.js;

At this point, the call is done using the Web API.

To start recording, call:

To end recording, call:

【 Use tips 】

Appid parameter configuration of acoustic network In the program, do not pass parameters to reduce the risk of account theft

With the above steps, the program is finished recording, but there are more pits waiting for you in the future, the author sorted out the pits in use, as follows.

[Pit in use]

1, the recorded video cannot be directly returned to the MP4 address, you need to traverse the folder path to find the MP4 format file to return.

2. Set the allowed offline time. The default time for this project is only 10 seconds, which is too short. You can set config.idleLimitSec=300 in the agora-resting-recording-nodejs /record/ SRC /agora_node_ext/ agora_node_recording-cpp file to change the offline duration For 5 minutes.

3, MP4 files sometimes not immediately generated, there will be occasional folder traversal, MP4 files have not produced the situation, this time directly returned to the calling end will lead to program defects, all to create a cycle detection counter, detect MP4 files generated after the return to the calling end, to ensure the stability of the program.

4. The video composited screen can be laid out by itself. In addition to the position of the composited video, you can also customize the video size, but when changing the video size, it must be one of the enumerated values as shown below:


I hope this article can give you a solution to video recording and synthesis ideas, but also hope that you can avoid some pits mentioned in the article in specific use.

The last

Agora SDK experience essay contest essay | the nuggets technology, the campaign is underway