Try Live Demo

Ant Media Server operates with different streaming flows. As well as accepting and creating streaming media, it also has the capability of the pull live streams from external sources. Such as; live TV streams, IP camera streams, or other forms of live streams(RTSP, HLS, TS, FLV etc.).  A blog post about pulling IP Camera streams was posted. This was the first part of this concept. Now Ant Media Server pulls not only IP Camera streams but also other forms of live streams. We will first show how to pull live streams with Web Interface and then we will give technical details for developers.

Pull Live Streams with Web Interface

First, log in to the management panel. Click New Live Stream -> Stream Source. Define stream name and URL.

Pull Live Streams by defining URL

Then, Ant Media Server starts to pull streams.

Pulling Live Streams

Now, you can watch it.

Watch Live Streams by pulling from remote

 

Technical Details about Pulling Live Streams for Developers

There are 2 classes to operate and regulate pulling processes:

a) StreamFetcher.java : Includes operating methods, startStream, stopStream, prepare etc

b) StremFetcherManager.java: Includes regulating methods such as checkStreamFetchersStatus,  restartStreamFetchers,  setRestartStreamAutomatically,  scheduleStreamFetcherJob etc.

1. Initialize StreamFetcherManager

/* Constructor */
public StreamFetcherManager(ISchedulingService schedulingService, IDataStore datastore,IScope scope) {
	this.schedulingService = schedulingService;
	this.datastore = datastore;
	this.scope=scope;
}

streamFetcherManager = new StreamFetcherManager(AntMediaApplicationAdapter.this, dataStore,app);

2. Define Settings

streamFetcherManager.setRestartStreamFetcherPeriod(appSettings.getRestartStreamFetcherPeriod());
streamFetcherManager.setStreamCheckerInterval("seconds"));

A developer can define a restart parameter. This is stored in the settings file as  ” settings.streamFetcherRestartPeriod” (in seconds) by using setRestartStreamFetcherPeriod() method. If this parameter is set as 0, the stream fetcher will never restart in other words never save the fetched stream. For example, define this parameter to “1800” to save the fetched stream as a recorded video every 30 minutes. Also, make sure that the “Enable MP4 Recording” option is enabled in the management panel or the “settings.mp4MuxingEnabled ” parameter in the setting file set to true to save the video.

Another parameter is StreamCheckerInterval. This defines the time interval for StreamFetcherManager should check all fetching processes whether they continue to fetch properly or not. The default parameter is 10 seconds. The checkStreamFetchersStatus() method performs these controls.

3. Start Streaming

streamFetcherManager.startStreams(streams);

The parameter “streams” is a list (List<Broadcast> streams) of broadcast objects to be fetched.

4. Customize 

You can also customize the required parameters in StreamFetcher class according to your project’s needs and requirements.

connection timeout:  (defined as “timeout” in ms) Connection timeout interval during connection establishment to the stream source in the first phase.

packet receiving timeout: (defined as “PACKET_RECEIVED_INTERVAL_TIMEOUT” in ms) Checks incoming packets timestamps and defines stream is alive or not.

restart after disconnection: (defined as “restartStream” as boolean) If defined as true, tries to reconnect stream source immediately after disconnected.

buffer time: (defined as “bufferTime” in ms) Stream Fetcher first buffers received packets and then restreams for smooth streaming but of course, it creates a small delay.

Hope this blog post is helpful for you. If you have any questions or comments just send an email to contact at antmedia dot io or fill out the contact form.

Categories: Tutorial

Murat Ugur

Murat is a Software Developer and a Technical Support Engineer at the same time at Ant Media. With a remarkable 15+ years in the IT domain, including 13 years dedicated to Linux System administration, Murat brings a wealth of experience to the table. His expertise is grounded in technologies like bash scripting, python, and puppet.