Skip to main content

Streaming IP cameras and External stream sources (HLS, RTMP, RTSP, etc.)

Ant Media Server users can pull IP camera streams easily from the management panel. In other words, you don’t need to write any commands or use a terminal to be able to re-stream external sources.

In order for IP camera re-streaming, the camera should support the ONVIF standard. ONVIF makes it easy to manage IP cameras. All CRUD and PTZ operations are based on well-defined SOAP messages.

Let’s have a look at how to pull a stream from an IP camera.

Adding an IP camera

  • Go to the management panel, Select LiveApp from applications, then click on New Live Stream and select IP Camera.
  • Fill in the camera name, camera username, and camera password. You should add the ONVIF URL of the IP camera. Generally, it is in the following format: IP-ADDRESS-OF-IPCAMERA:8080. If you don't know the ONVIF URL, you can use “Auto Discover” feature. If the IP camera and the server are in the same subnet, Ant Media server can discover them automatically.

If you want to use a domain name instead of an IP address, make sure to prepend with the http(s) e.g.

Watching IP cameras

If IP cameras are accessible and properly configured, Ant Media Server adds their streams as a live stream and begins to pull streams from them. The management panel displays its current status. To watch the stream, click the Play button.

If you don't have an ONVIF URL, you can still pull the IP camera using an RTSP URL. Please see the section on re-streaming external sources in the document below.

Re-streaming external sources

Ant Media Server (AMS) can handle a variety of streaming flows. It can accept and create streaming media as well as pull live streams from external sources such as live TV streams, IP camera streams, and other types of live streams (RTSP, HLS, RTMP, FLV, UDP, etc.).

In order to re-stream from an external source, follow these steps:

  • First, log in to the management panel. Click on New Live Stream > Stream Source. Define stream name, stream URL and stream Id.
  • AMS starts to pull streams.
  • As the stream starts to pull, you can watch it from the AMS panel.

In AMS v2.5.3 and later, the stream auto-fetcher is disabled by default so streams do not start itself after server restart. Change the following flag to true in the Advance application settings so that stream start fetching automatically.

"startStreamFetcherAutomatically": true,

Pull a UDP stream to the Ant Media Server

For other stream sources like HLS, RTMP, etc, you can directly pull it as the stream is already available. But if you want to send a stream to AMS with UDP, then first you have to publish it to the server and then you have to pull it.

You can pull the UDP stream on a server as a Stream Source by following below steps.

  • First, send the stream with UDP to the Ant Media Server IP address using encoder or FFMPEG. In this example, we used FFMPEG command.

    ffmpeg -f lavfi -re -i smptebars=duration=60:size=1280x720:rate=30 -f lavfi -re -i sine=frequency=1000:duration=60:sample_rate=44100 -pix_fmt yuv420p -c:v libx264 -b:v 1000k -g 30 -keyint_min 120 -profile:v baseline -preset veryfast -f mpegts "udp://server-IP:5000?pkt_size=1316"

    You can change the port number as per your requirements. We published the stream on port 5000. Also, make sure that the used port is whitelisted on the firewall.

  • Once the stream starts pushing on the server's IP address, you can pull it (udp:// as a stream source on Ant Media Server.

Add Stream Source and IP Camera using Rest API

Create Stream Source Broadcasts

curl -X POST -H "Content-Type: application/json" "https://IP-address-or-domain:Port/App-Name/rest/v2/broadcasts/create?autoStart=false" -d '{ "type":"streamSource","name":"test",

Create IP Camera Broadcasts

curl -X POST -H "Content-Type: application/json" "https://IP-address-or-domain:Port/App-Name/rest/v2/broadcasts/create?autoStart=false" -d '{
"type":"ipCamera","name":"test","streamId":"test","ipAddr": "","username": "camera-username","password":"camera-password",}'

Check here for more information on the Rest API.

Dynamic Stream Pulling


The Dynamic Stream Pulling feature is available in versions 2.8.3 and up.

Dynamic Stream Pulling offers an efficient bandwidth optimization solution by automatically starting and stopping stream pulling based on user demand.

For example, when a user attempts to view an offline stream with a stream source or IP camera, Ant Media Server automatically initiates stream pulling, enabling the broadcast to go live. Conversely, when viewership declines and there are no remaining viewers, Ant Media Server automatically halts stream pulling, returning the broadcast to an offline state.

This feature proves invaluable for bandwidth optimization, especially when continuous stream recording isn't necessary. By activating stream pulling only when someone tries to watch the stream and ceasing it when there are no viewers, Ant Media Server significantly conserves bandwidth resources.

Auto-stopping the stream with no viewer is valid for all play types (WebRTC, HLS, and DASH).

To use the Dynamic Stream Pulling feature:

  • Go to the Ant Media web panel and create a broadcast with the type Stream Source or IP Camera.

    To enable the feature for the stream, check the Auto Start/Stop Streaming checkbox as shown below.

After creation, Ant Media Server will start pulling the stream automatically and broadcast status will turn to Broadcasting Alternatively, you can also activate Auto Start/Stop Streaming for an existing broadcast by modifying its settings using the REST API.

To do that, send a PUT request using Update Broadcast Rest API.

Here is the Curl Sample:

curl --location --request PUT 'http(s)://AMS_DOMAIN:Port/AppName/rest/v2/broadcasts/streamId' --header 'Content-Type: application/json' --data '{"autoStartStopEnabled":true}'
  • Open a new tab and start watching the live stream using the below URL.

Now the server will start fetching stream.

  • Close the watcher tab. Since there are no viewers anymore, Ant Media Server will stop pulling the stream within a few seconds, and the broadcast status will change to Offline.

Recording IP camera streams

The Ant Media Server can save IP camera and other external stream sources streams in MP4 format. You can see these recorded files on VOD tab in the management panel.

For more information, see Recording Live Streams.