How to notify remote URL after MP4 recording completes in Ant Media Server

"Only a life lived for others is a life worthwhile." – Albert Einstein


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 / Where [app name] is the name of the ant media server application(ex: LiveApp).

The setting entry in the file look like this :


To use this setting correctly you need to do the following.

  1. Create a shell script on the server’s file system
  2. Make sure the script has executable permissions : chmod +x
  3. Edit the application’s file : [AMS-DIR]/webapps/[app name]/WEB-INF/
  4. Set the settings.muxerFinishScript property’s value to the absolute path of your shell script
  5. 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 : ~/ /usr/local/antmedia/webapps/LiveApp/streams/test_stream.mp4

Sample Script (Notifies remote URL on MP4 recording completion)


filepath=$(basename -- "$path_to_mp4")

echo $filepath
echo $extension
echo $just_name

curl -d "path=$filepath&name=$filename" -X POST

When the script finishes, AMS logs out an INFO message in the log as shown below:

running muxer finish script: ~/ /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.

  1. Notify a remote server that the recording is complete
  2. Post-process the MP4 to generate other video formats (multiple variants for VOD ABR)
  3. Email the administrator about it
  4. Upload it to the cloud for archived storage
  5. Integrate with a telegram to notify yourself that the recording is ready

The possibilities are up to your creativity!!.