LiveStreaming
Social media is a vital part of our life. Social media platforms are the most convenient and efficient approach to reach the people.
Ant Media Server may publish live streams to third-party APIs. In other words, Ant Media Server may publish live streams to several social media platforms at the same time, including YouTube, Facebook, Periscope,Twitch and other generic RTMP endpoints.
In this blog post, we will demonstrate how a developer can leverage this functionality on Ant Media Server.
We can do a lot with Ant Media Server using REST API. The following is an abstract Ant Media Server API list of available methods in REST API.
CRUD(Create/Read/Update/Delete) Operations.
Streams
Stream Sources
IP Camera
Add/Remove RTMP Endpoints to the Streams
Authorize/Revoke Social Endpoints
For ant media REST API, please visit the https://antmedia.io/rest
All REST methods define the app's binding rest path. Ant Media Server Community Edition includes LiveApp and WebRTCApp by default. The LiveApp REST methods (for example, application's get method) are as follows:
http://localhost:5080/LiveApp/rest/v2/application/{userId}
To create user in applicationn we have to call above restfull api endpoint which will create user into application.
Also, Read Stream In Java 8 and Its Features
Now we can create the all the broadcast using below restfule api endpoint for users
http://localhost:5080/LiveApp/rest/v2/broadcast/{id}
We can pass a Broadcast object as a parameter in JSON format. Ant Media Server returns the created broadcast object in JSON format again. The most important field in the returned response is the streamId field in JSON. In order to receive broadcasts, we use the streamId.
Getting a broadcast is easier. Simply add the streamId as a query parameter to the streamId variable, as seen below.
http://localhost:5080/LiveApp/rest/broadcast/650320906975923279669775.
4) How to Publish Live Stream on Youtube
You can publish live streams on your YouTube channel. Simply click the Create button and pick Go Live.
Just Click the Go button on the Streaming Software tab.Then copy the Stream URL and Stream Key.
Your Youtube RTMP Endpoint URL that you will use in Ant Media Server should be like this: <StreamURL>/<StreamKey>
rtmp://a.rtmp.youtube.com/live2/dq1j-waph-e322-waxd-dxzd
Simply add your YouTube RTMP Endpoint URL to the Ant Media Server stream RTMP Endpoint tab. Or you can add YouTube RTMP Endpoint URL to the ant media using restfull API.
Also, Read How To Make ERP Systems More Resistant To Continuity Breaks
5) How to Add/Remove RTMP Endpoint with Ant Media Stream
You have two options for adding and removing RTMP endpoints.
One of them is Add/Remove RTMP Endpoint using Dashboard. It's intended for general users.
Another method is to add/remove RTMP endpoints via REST API. This option is for advanced users. You can add and remove RTMP endpoints programmatically. REST API usage is quite simple.
1) Add/Remove RTMP Endpoint with Dashboard.
This option is for general users. You just need to click the broadcast properties tab and click Edit RTMP Endpoint
2) Add/Remove RTMP Endpoint with REST API
This option is for developers. Simply request the rtmp-endpoint REST API.
http://localhost:5080/LiveApp/rest/v2/broadcasts/streamId/rtmp-endpoint"
6) Conclusion
After adding an RTMP Endpoint, you must publish a live stream.Finally, checkthe social media account to view the live broadcast.