Gstreamer Advanced Topics - cu-ecen-aeld/yocto-assignments-base GitHub Wiki
RTMP - (Real-Time Messaging Protocol)
Online video streaming continues to become more popular due to the consistent development of supporting technology. One particular online video streaming technology that has played an important role in the rise of this industry is RTMP.
Introduction
RTMP was used to transmit content between a video player and a hosting server, which is referred to as "RTMP delivery".
In terms of the most modern live streaming setups, RTMP’s primary role is to deliver content from an encoder to an online video host. This RTMP function is referred to as “RTMP ingest.”
RTMP is capable of low-latency streaming, which is a major plus for broadcasters who are streaming major events in real-time. It is also known for its minimal buffering, which truly enhances the user experience.
-
RTMP is a live streaming protocol that transmits video files from an encoder to an online video hosting platform.
-
RTMP has been replaced by HLS for its original role in live streaming, but it now serves another important role.
-
AAC-LC is the best audio codec for RTMP encoding, but AAC is also supported.
-
H.264 is the best video codec for RTMP encoding, but MP4 and x264 are also supported.
-
RTMP ingest supports the use of low-cost encoding tools.
-
Broadcasters prefer using RTMP streaming since that has low latency.
GStreamer with RTMP
GStreamer supports RTMP by providing the below mentioned elements to use with the pipeline construction:
- rtmpsink - Sends FLV content to a server via RTMP
This element delivers data to a streaming server via RTMP. It uses librtmp, and supports any protocols/urls that librtmp supports. The URL/location can contain extra connection or session parameters for librtmp, such as 'flashver=version'.
- rtmpsrc - Reads RTMP streams
This plugin reads data from a local or remote location specified by an URI. This location can be specified using any protocol supported by the RTMP library, i.e. rtmp, rtmpt, rtmps, rtmpe, rtmfp, rtmpte and rtmpts. The URL/location can contain extra connection or session parameters for librtmp, such as 'flashver=version'. Of particular interest can be setting live=1 to certain RTMP streams that don't seem to be playing otherwise.
RTMP plugins are included with the gst-plugins-bad by installing this package to our build will help to use RTMP elements in our pipeline. Alternatively, we can also install only RTMP plugins instead of using the bad-plugins package.
Read more about GStreamer RTMP
Example setup to use RTMP
In this example we are using RTMP with GStremer to provide streaming source to YouTube live streaming engine. A video files stored locally in BeagleBone Black is encoded and sent using RTMP GStreamer pipeline to the YouTube live streaming server.
GStreamer pipeline
$ gst-launch-1.0 -v videotestsrc ! decodebin ! videoconvert \
! x264enc ! video/x-h264 ! h264parse ! flvmux streamable=true name=mux \
! rtmpsink location="rtmp://a.rtmp.youtube.com/live2/stream_key" audiotestsrc \
! voaacenc bitrate=128000 ! mux.
Live streaming setup on YouTube:
- Sign in to YouTube in your browser
- Click on Create -> Go Live in the top-right corner
- Verify your channel (if you haven't already)
- Wait until live streaming is enabled (this may take up to 24 hours)
Read more
Once the streaming page goes live, from the STREAM SETTINGS shown below we can get Stream URL and Stream key required to provide source to the streaming engine.
In the rtmp pipeline given above the rtmpsink location is made up of the stream url and key, which we can get from the stream setting shown above.
rtmpsink location = "STREAM_URL/STREAM_KEY"
Before the streaming engine starts receiving video source data, the streaming window looks like the below:
Once BeagleBone Black starts sending the video source to the YouTube streaming engine, the stream goes live and can be analyzed as shown below:
The Stream can be shared with multiple viewers using the sharing link provided by the YouTube live stream.
Future work
This live streaming setup can also be done using our own streaming engine setup like WOWZA.
Set up live streaming using an RTMP-based encoder in Wowza Streaming Engine