This project documents the development and integration of a custom RTMP (Real-Time Messaging Protocol) server aimed at facilitating video streaming for an AI interview platform. It outlines the motivations behind the decision to build a proprietary solution, the challenges faced with existing services, and the successful implementation of the custom RTMP server.
During an internship at Acencore, the task of developing an AI interview platform was assigned. Among the pivotal requirements was the seamless streaming of video content from the browser to the server. This necessitated the exploration of various streaming solutions.
Initial attempts involved leveraging YouTube's RTMP server, which presented limitations in terms of control over video content. Consequently, transition to Amazon's Interactive Video Service (IVS) was considered. However, the associated costs posed a significant barrier to adoption.
To address the challenges encountered with existing solutions, the decision was made to construct a custom RTMP server tailored to the project's specific requirements. This endeavor involved the development of requisite infrastructure and protocols to ensure smooth and efficient video streaming.
The custom RTMP server was successfully implemented and seamlessly integrated into the project workflow. This solution not only mitigated cost concerns but also provided enhanced control and flexibility over the streaming process. The platform achieved its objectives of real-time video streaming and integration with machine learning analysis.
To ensure the successful implementation of the custom RTMP server, several components and configurations were utilized. Below are the key working parts involved in the process:
EC2 Instance Setup: An EC2 instance was provisioned on AWS to serve as the host for the RTMP server.
OBS Installations: OBS (Open Broadcaster Software) was installed on the EC2 instance to facilitate video streaming. The following commands were executed for installation:
sudo apt install v4l2loopback-dkms
sudo apt install ffmpeg
sudo add-apt-repository ppa:obsproject/obs-studio
sudo apt update
sudo apt install obs-studio
Nginx Installation: Nginx, a high-performance web server, was installed on the EC2 instance to handle RTMP streaming. The installation process involved the following steps:
sudo apt update
sudo apt install nginx
sudo apt install libnginx-mod-rtmp
sudo systemctl start nginx
sudo systemctl enable nginx
sudo vi /etc/nginx/nginx.conf
Configuration of Nginx for RTMP: The Nginx configuration file was edited to include settings specific to RTMP streaming. The following lines were added to the configuration file:
rtmp {
server {
listen 1935;
chunk_size 4096;
allow publish all;
application live {
live on;
record off;
}
}
}
Opening Port 1935: To allow incoming connections on port 1935 for RTMP streaming, the firewall settings were adjusted:
sudo ufw allow 1935/tcp
Starting Nginx Service: The Nginx service was started to enable RTMP streaming:
sudo systemctl restart nginx
Checking 1935 Port: The status of port 1935 was verified to ensure that the RTMP server was running:
ss -antpl | grep 1935
Now I just wrote code and added rtmp url as rtmp://...*/ (IP address of the EC2 instance)
Once your RTMP server is installed and operational, it's crucial to set up the RTMP statistics page to monitor your streaming activities effectively. Follow the steps below to configure the RTMP statistics page:
First, create a directory to store the RTMP stat file using the following command:
mkdir /var/www/html/rtmp
Next, copy the RTMP stat file to the created directory:
cp /usr/share/doc/libnginx-mod-rtmp/examples/stat.xsl /var/www/html/rtmp/stat.xsl
Edit the Nginx default virtual host configuration file:
nano /etc/nginx/sites-available/default
Remove all default lines and replace them with the following configuration:
server {
listen 8080;
server_name _;
# RTMP stat
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /var/www/html/rtmp;
}
# RTMP control
location /control {
rtmp_control all;
}
}
Save and close the file.
Restart the Nginx service to apply the changes:
systemctl restart nginx
Now, open your web browser and navigate to the RTMP stat page using the URL http://your-server-ip:8080/stat
. You should be able to view the RTMP statistics on the displayed page.
Remember to refresh the page every time you stream a video to observe changes in the stream statistics effectively.
These components and configurations collectively enabled the establishment of a custom RTMP server, facilitating seamless video streaming for the AI interview platform.
The development and integration of the custom RTMP server proved instrumental in the success of the AI interview platform at Acencore. This initiative not only addressed the immediate project requirements but also demonstrated innovation and problem-solving capabilities.