Getting Started

Ant Media Server is a software that can stream live and vod videos. It supports adaptive streaming on the fly and records live videos in several formats like HLS, MP4, etc.

Features

  • Receive live streams in RTMP, RTSP and WebRTC
  • Records live streams in MP4, FLV, HLS and Dash Formats
  • Transcodes live streams into lower resolutions on the fly for adaptive streaming
  • Play live streams with RTMP, RTSP, WebRTC, HLS and Dash Formats

Installation

Linux (Ubuntu)

Firstly, start installing Oracle Java 8

Run the below commands to install Oracle’s PPA

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update

It is time to install Java 8

$ sudo apt-get install oracle-java8-installer

Download the Ant Media Server Community Edition from https://antmedia.io

Extract the zip folder. In order to do that first install unzip

$ sudo apt-get install unzip
$ unzip ant-media-server.zip     

Now, there are two methods to run the server,

  • Quick Start is for testing and debugging issues.
  • Running as a Service is for production

Quick Start

If you want to run the server as a service, skip to Running as a Service section below

After you completed above instructions, open a terminal, go to the folder where you extracted the Ant Media Server and run start.sh type

cd path/to/ant-media-server
./start.sh

The server should start a few seconds later.

Running as a Service

If you want to run server as a service in linux machine, the next step is installing Jsvc in order to run media server as a service

$ sudo apt-get install jsvc

Move the ant-media-server directory to /usr/local/antmedia

$ sudo mv ant-media-server /usr/local/antmedia

Copy antmedia file to /etc/init.d and install the service

$ sudo cp /usr/local/antmedia/antmedia /etc/init.d/
$ sudo update-rc.d antmedia defaults
$ sudo update-rc.d antmedia enable

Create antmedia user to system

sudo useradd -d /usr/local/antmedia/ -s /bin/false -r antmedia
sudo chown -R antmedia:antmedia /usr/local/antmedia/

It is time to start the server

$ sudo service antmedia start

To stop the service run the command below

$ sudo service antmedia stop

To see the status of the service, run

$ sudo service antmedia status

Build from Source

Linux (Ubuntu)

A couple of repos should be clone and build with maven so that git and maven should be installed in advance

  • Go to a directory where you clone repos
  • Clone and build Ant-Media-Server-Common
$ git clone https://github.com/ant-media/Ant-Media-Server-Common.git
$ cd Ant-Media-Server-Common
$ mvn clean install -Dmaven.javadoc.skip=true -Dmaven.test.skip=true
$ cd ..
  • Clone and build the Ant-Media-Server-Service
$ git clone https://github.com/ant-media/Ant-Media-Server-Service.git
$ cd Ant-Media-Server-Service
$ mvn clean install -Dmaven.javadoc.skip=true -Dmaven.test.skip=true
$ cd ..
  • Clone and build the Periscope-Producer-API
$ git clone https://github.com/ant-media/Periscope-Producer-API.git
$ cd Periscope-Producer-API/
$ mvn clean install -Dmaven.javadoc.skip=true -Dmaven.test.skip=true
$ cd ..
  • Clone and build the Tomcat Plugin
$ git clone https://github.com/ant-media/red5-plugins.git
$ cd red5-plugins/tomcat/
$ mvn clean install -Dmaven.javadoc.skip=true -Dmaven.test.skip=true
$ cd ../..
  • Clone, build and package Ant-Media-Server
$ git clone https://github.com/ant-media/Ant-Media-Server.git
$ cd Ant-Media-Server
$ mvn clean install -Dmaven.javadoc.skip=true -Dmaven.test.skip=true
$ ./repackage.sh

If everthing goes well, a new packaged Ant Media Server(ant-media-server-x.x.x.zip) file will be created in Ant-Media-Server/target directory

Server Ports

In order to server run properly you need to open some network ports. Here are the ports server uses

  • TCP:1935 (RTMP)
  • TCP:5080 (HTTP)
  • TCP:5554 (RTSP)
  • UDP:5000-65000 (RTP in RTSP)
  • TCP: 8081-8082 (WebSocket)

Forward a Port to an Another

Generally port forwarding is used to forward default ports to the server’s ports in order to have easy of use. For instance let’s forward 80 to 5080, just type the command below.

sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 5080

After running the command above, the request goes to 80 is being forwarded to 5080

Make Port Forwarding Persistent

If you want the server to reload port forwarding after reboot, we need to install iptables-persistent package and save rules like below

sudo apt-get install iptables-persistent

Above command will install iptables-persistent package, after that just run the command below everytime you make a change and want it to be persistent

sudo sh -c "iptables-save > /etc/iptables/rules.v4"
Yes No Suggest edit

How to Try Low Latency 1:N WebRTC Streaming

Ant Media Server 1.2.0+ Enterprise Edition supports adaptive low latency WebRTC streaming.

In addition, Ant Media Server can

  • Record WebRTC streams as MP4 and MKV
  • Convert WebRTC streams to adaptive live HLS
  • Create previews in PNG format from WebRTC streams

Download

Firstly, you need to have Ant Media Server Enterprise Edition. If you are a personal user and just want to try, contact with us at antmedia.io. We will reply back with a link to download Ant Media Server Enterprise.

If you are a professional user and need support, you can buy support at antmedia.io as well

Quick Start

Ant Media Server 1.2.0+ runs on Linux and Mac not on Windows.

Let’s start, we assume that you have got Enterprise Edition somehow and downloaded to your local computer

  1. Extract the downloaded file in to a directory.
  2. Make sure you have installed Oracle Java 8
    • Installation Java 8 on Ubuntu
      $ sudo add-apt-repository ppa:webupd8team/java
      $ sudo apt-get update
      $ sudo apt-get install oracle-java8-installer
      
    • Installation Java 8 on Mac
      • Follow the guide here
  3. Open a terminal and go to directory where you have extracted Enterprise Edition
    cd /path/to/ant-media-server
    
  4. Start the server with start.sh script.
    ./start.sh
    

    It starts by printing some logs to the terminal.

  5. Open the browser(Chrome or Firefox) and go to the http://localhost:5080/WebRTCAppEE. Let browser access your camera and mic unless it cannot send WebRTC Stream to the server

    Open WebRTCAppEE

    WebRTCAppEE stands for WebRTCApp Enterprise Edition

  6. Write stream name or leave it as default and Press Start Publishing button. After you press the button, “Publishing” blinking text should appear

    Press Start Publishing button

  7. Go to the http://localhost:5080/WebRTCAppEE/player.html

    Go to the player.html

  8. Press Start Play button. After you press the button, webrtc stream should be started

    Press Start Playing Button

  9. Open http://localhost:5080/WebRTCAppEE/player.html in other tabs and Press Start Playing button again to check how it plays and what the latency is.

Feedbacks

Please let us know your feedbacks about the latency and streaming or any other issue you have faced so that we can improve and let you try and use.

You can use contact form at antmedia.io or contact at antmedia dot io e-mail to send your feedbacks

Thank you

Ant Media

Yes No Suggest edit

Getting Started

Ant Media Server provides WebSocket interface in publishing and playing WebRTC streams. In this document, we will show both how to publish and play WebRTC streams by using JavaScript SDK.

How to Publish WebRTC stream with JavaScript SDK

Let’s see how to make it step by step

  1. Load the below scripts in head element of the html file
<head>
...
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
<script src="js/webrtc_adaptor.js" ></script>
...
</head>
  1. Create local video element somewhere in the body tag
<video id="localVideo" autoplay muted width="480"></video>
  1. Initialize the WebRTCAdaptor object in script tag
	var pc_config = null;
var sdpConstraints = {
OfferToReceiveAudio : false,
OfferToReceiveVideo : false
};
var mediaConstraints = {
video : true,
audio : true
};
var webRTCAdaptor = new WebRTCAdaptor({
websocket_url : "ws://" + location.hostname + ":8081/WebRTCApp4",
mediaConstraints : mediaConstraints,
peerconnection_config : pc_config,
sdp_constraints : sdpConstraints,
localVideoId : "localVideo",
callback : function(info) {
if (info == "initialized") {
console.log("initialized");
} else if (info == "publish_started") {
//stream is being published 
console.log("publish started");
} else if (info == "publish_finished") {
//stream is finished
console.log("publish finished");
}
},
callbackError : function(error) {
//some of the possible errors, NotFoundError, SecurityError,PermissionDeniedError
console.log("error callback: " + error);
alert(error);
}
});
  1. Call publish(streamName) to Start Publishing

In order to publish WebRTC stream to Ant Media Server, WebRTCAdaptor’s publish(streamName) function should be called. You can choose the call this function in success callback function when the info parameter is having value “initialized”

 if (info == "initialized")  
{  
// it is called with this parameter when it connects to                            
// Ant Media Server and everything is ok 
console.log("initialized");
webRTCAdaptor.publish("stream1");
}
  1. Call stop() to Stop Publishing

You may want to stop publishing anytime by calling stop function of WebRTCAdaptor

webRTCAdaptor.stop()

Sample

Please take a look at the WebRTCApp4/index.html file in order to see How JavaScript SDK can be used for publishing a stream

How to Play WebRTC stream with JavaScript SDK

  1. Load the below scripts in head element of the html file
<head>
...
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
<script src="js/webrtc_adaptor.js" ></script>
...
</head>
  1. Create remote video element somewhere in the body tag
<video id="remoteVideo" autoplay controls></video>
  1. Initialize the WebRTCAdaptor object like below in script tag
  var pc_config = null;
var sdpConstraints = {
OfferToReceiveAudio : true,
OfferToReceiveVideo : true
};
var mediaConstraints = {
video : true,
audio : true
};
var webRTCAdaptor = new WebRTCAdaptor({
websocket_url : "ws://" + location.hostname + ":8081/WebRTCApp4",
mediaConstraints : mediaConstraints,
peerconnection_config : pc_config,
sdp_constraints : sdpConstraints,
remoteVideoId : "remoteVideo",
isPlayMode: true,
callback : function(info) {
if (info == "initialized") {
console.log("initialized");
} else if (info == "play_started") {
//play_started
console.log("play started");
} else if (info == "play_finished") {
// play finishedthe stream
console.log("play finished");
}
},
callbackError : function(error) {
//some of the possible errors, NotFoundError, SecurityError,PermissionDeniedError
console.log("error callback: " + error);
alert(error);
}
});
  1. Call play(streamName) to Start Playing

In order to play WebRTC stream to Ant Media Server, WebRTCAdaptor’s play(streamName) function should be called.

You can choose the call this function in success callback function when the info parameter is having value “initialized”

 if (info == "initialized")  
{  
// it is called with this parameter when it connects to                            
// Ant Media Server and everything is ok 
console.log("initialized");
webRTCAdaptor.play("stream1");
}
  1. Call stop() to Stop Playing

You may want to stop play anytime by calling stop function of WebRTCAdaptor

webRTCAdaptor.stop()

Sample

Please take a look at the WebRTCApp4/player.html file in order to see How JavaScript SDK can be used for playing a stream

Yes No Suggest edit

WebRTC Signalling Server

Ant Media Server can also be used as a signalling server for peer to peer connections. WebSocket is used for connection between peers and Ant Media Server.

In order to use Ant Media Server as a WebSocket you just need to use an app that provides this feature. If you do not know, how to do that drop an email to contact at antmedia dot io

JavaScript SDK

Of course there is a JavaScript SDK in order to make using signalling server straight forward. There is a sample peer.html file in the sample app, you can also try it to understand how to use JavaScript SDK

How to use JavaScript SDK

JavaScript SDK is so easy, just create WebRTCAdaptor object and call join(roomName) function. Let’s see how to make it step by step

Load the below scripts in head element of the html file.

<head>
...
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
<script src="js/webrtc_adaptor.js" ></script>
...
</head>

Create video elements somewhere in the body tag

<video id="localVideo" autoplay muted width="480"></video>
<video id="remoteVideo" autoplay controls width="480"></video>

First video tag is for local video and the second video tag for remote video.

Initialize the `WebRTCAdaptor object in script tag

<script>
var pc_config = null;
var sdpConstraints = 
{
OfferToReceiveAudio : true,
OfferToReceiveVideo : true	
};
var mediaConstraints = {
video: true,
audio: true
};
var webRTCAdaptor = new WebRTCAdaptor({
websocket_url:"ws://" + location.hostname + ":8081/WebRTCApp4",  // url of the WebSocket Signalling Server
mediaConstraints: mediaConstraints, 
peerconnection_config: pc_config,
sdp_constraints: sdpConstraints,
localVideoId: "localVideo",   // id of the local video tag
remoteVideoId: "remoteVideo",  // id of the remote video tag
callback: function(info) {     // *success callback function*
if (info == "initialized")  
{  
// it is called with this parameter when it connects to                            
// signalling server and everything is ok 
console.log("initialized");
}
else if (info == "joined")
{ 
// it is called with this parameter when it joins a room
console.log("joined");
}
else if (info == "leaved")
{
// it is called with this parameter when it leaves from room
console.log("leaved");
}
},
callbackError: function(error) {  
// error callback function it is called when an error occurs
//some of the possible errors, NotFoundError, SecurityError,PermissionDeniedError
console.log("error callback: " + error);
alert(error);
}
});
</script>

Call join function

In order to create a connection between peers, each peer should join the same room by calling join(roomName) function of the WebRTCAdaptor. When there are two peers in the same room, signalling starts automatically and peer to peer connection is established.

For instance, you can call join function in success callback function when the info parameter is having value “initialized”

 if (info == "initialized")  
{  
// it is called with this parameter when it connects to                            
// signalling server and everything is ok 
console.log("initialized");
webRTCAdaptor.join("room1");
}

According to code above, when peer.html file is opened by two peers, they will joined the “room1” and peer to peer connection will be established.

Functions

As shown above, main object is WebRTCAdaptor so that let’s look at its functions

  • join(roomName) :

    Lets peer join to a room specified in the parameter, if operation is successfull then callback function is called with info parameter having “joined” value. When there are two people in the same room, signalling starts automatically and peer to peer connection is established

  • leave():

    Lets peer leave the room it joined previously. If operation is successfull then callback function is called with info parameter having “leaved” value

  • turnOnLocalCamera():

    Lets the local camera turn on and add the video stream to peer connection

  • turnOffLocalCamera():

    Lets the local camera turn off and remove the video stream from peer connection

  • unmuteLocalMic():

    Lets the local mic unmute and add the audio stream to peer connection

  • muteLocalMic():

    Lets the local mic mute and remove the audio stream from peer connection

Sample

Please take a look at the WebRTCApp4/peer.html file in order to see How JavaScript SDK can be used

Yes No Suggest edit

WebRTC WebSocket Messaging Details

This documentation is for developers who needs to implement signalling between Ant Media Server and clients for publishing & playing streams. Let’s make it step by step

Publishing WebRTC Stream

  1. Client connects to Ant Media Server through WebSocket. URL of the WebSocket interface is something like
ws://SERVER_NAME:8081/WebRTCApp4

8081 is the port number of WebSocket and WebRTCApp4 is the name of the app on the server.

  1. Client sends publish JSON command to the server with stream name parameter.
{
command : "publish",
streamName : "stream1",
}
  1. If Server accepts the stream, it replies back with start command
{
command : "start",
}
  1. Client inits peer connections, creates offer sdp and send the sdp configuration to the server with takeConfiguration command
{
command : "takeConfiguration",
streamName : "stream1",
type : "offer",  
sdp : "${SDP_PARAMETER}"
}
  1. Server creates answer sdp and send the sdp configuration to the client with takeConfiguration command
{
command : "takeConfiguration",
streamName : "stream1",
type : "answer",  
sdp : "${SDP_PARAMETER}"
}
  1. Client and Server get ice candidates several times and sends to each other with takeCandidate command
{
command : "takeCandidate",
streamName : "stream1",
label : "${CANDIDATE.SDP_MLINE_INDEX}",
id : "${CANDIDATE.SDP_MID}",
candidate : "${CANDIDATE.CANDIDATE}"
}
  1. Clients sends stop JSON command to stop publishing
{
command : "stop",
}

Playing WebRTC Stream

  1. Client connects to Ant Media Server through WebSocket.
ws://SERVER_NAME:8081/WebRTCApp4

8081 is the port number of WebSocket and WebRTCApp4 is the name of the app on the server.

  1. Client sends play JSON command to the server with stream name parameter.
{
command : "play",
streamName : "stream1",
}
  1. If Server accepts the stream, it replies back with offer command
{
command : "takeConfiguration",
streamName : "stream1",
type : "offer",  
sdp : "${SDP_PARAMETER}"
}
  1. Client creates answer sdp and send the sdp configuration to the server with takeConfiguration command
{
command : "takeConfiguration",
streamName : "stream1",
type : "answer",  
sdp : "${SDP_PARAMETER}"
}
  1. Client and Server get ice candidates several times and sends to each other with takeCandidate command
{
command : "takeCandidate",
streamName : "stream1",
label : "${CANDIDATE.SDP_MLINE_INDEX}",
id : "${CANDIDATE.SDP_MID}",
candidate : "${CANDIDATE.CANDIDATE}"
}
  1. Clients sends stop JSON command to stop playing
{
command : "stop",
}

Peer to Peer WebRTC Stream

  1. Peers connects to Ant Media Server through WebSocket.
ws://SERVER_NAME:8081/WebRTCApp4

8081 is the port number of WebSocket and WebRTCApp4 is the name of the app on the server.

  1. Client sends join JSON command to the server with stream name parameter.
{
command : "join",
streamName : "stream1",
}

If there is only one peer in the stream1, server waits for the other peer to join the room.

  1. When second peer joins the stream, server sends start JSON command to the first peer
{
command : "start",
}
  1. First peer create offer sdp and send to the server with takeConfiguration command,
{
command : "takeConfiguration",
streamName : "stream1",
type : "offer",  
sdp : "${SDP_PARAMETER}"
}

Server relays the offer sdp to the second peer

  1. Second peer creates answer sdp and sends to the server with takeConfiguration command
{
command : "takeConfiguration",
streamName : "stream1",
type : "answer",  
sdp : "${SDP_PARAMETER}"
}

Server relays the answer sdp to the first peer

  1. Each peers get ice candidates several times and sends to each other with takeCandidate command through server
{
command : "takeCandidate",
streamName : "stream1",
label : "${CANDIDATE.SDP_MLINE_INDEX}",
id : "${CANDIDATE.SDP_MID}",
candidate : "${CANDIDATE.CANDIDATE}"
}
  1. Clients sends leave JSON command to leave the room
{
command : "leave",
streamName: "stream1"
}
Yes No Suggest edit
Help Guide Powered by Documentor
Suggest Edit
%d bloggers like this: