
How to notify remote URL after MP4 recording completes in Ant Media Server
While working with media servers, one of the most important and necessary features from an integration standpoint is to know when a media recording completes. Every media server implements this feature in its own way. Most servers allow you to develop custom modules/plugins to capture the recording complete event with a handler function and then do something useful in it.
Ant Media Server takes a slightly different path to solve this problem. As of the current version (At the time of writing this article), the Ant media ecosystem hasn’t opened its programming API to developers to work with such things. Instead, there are a lot of predefined functionalities. One such functionality is – User defined Scripts. Ant media server allows you to specify the absolute path of a script that will automatically be executed once the MP4 recording completes. The script configuration is a per-application setting and not a server-wide setting. That means it must be defined on the application that you are using for your broadcast/subscribe operations.
Example: [AMS-DIR] / webapps / [app name] / WEB-INF / red5-web.properties
. Where [app name] is the name of the ant media server application(ex: LiveApp).
The setting entry in the file red5-web.properties look like this :
settings.muxerFinishScript=<PATH-TO-SCHELL-SCRIPT>
To use this setting correctly you need to do the following.
- Create a shell script on the server’s file system
- Make sure the script has executable permissions :
chmod +x scriptFile.sh
- Edit the application’s red5-web.properties file :
[AMS-DIR]/webapps/[app name]/WEB-INF/red5-web.properties
- Set the settings.muxerFinishScript property’s value to the absolute path of your shell script
- Save and restart the server/service for changes to take effect :
sudo service antmedia restart
It is important to note that the media server will invoke the script with the full path to the mp4 file as a parameter.
Example : ~/test_script.sh /usr/local/antmedia/webapps/LiveApp/streams/test_stream.mp4
Sample Script (Notifies remote URL on MP4 recording completion)
#!/bin/bash path_to_mp4=$1 filepath=$(basename -- "$path_to_mp4") extension="${filepath##*.}" just_name="${filepath%.*}" echo $filepath echo $extension echo $just_name curl -d "path=$filepath&name=$filename" -X POST https://example.com/posthandler.php
When the script finishes, AMS logs out an INFO message in the log as shown below:
running muxer finish script: ~/test_script.sh /usr/local/antmedia/webapps/LiveApp/streams/test_stream.mp4
This is a wonderful feature for system integration. You can do many cool things with it such as.
- Notify a remote server that the recording is complete
- Post-process the MP4 to generate other video formats (multiple variants for VOD ABR)
- Email the administrator about it
- Upload it to the cloud for archived storage
- Integrate with a telegram to notify yourself that the recording is ready
The possibilities are up to your creativity!!.