Streaming via RTMP

January 1, 2023 ยท 4 minute read

With second quarter in 2022 I joined Bitmovin, an awesome Austrian company dedicated to build streaming experiences and deliver the highest quality video fast and on every device possible. Amazing company, really interesting field, and a modern stack. So, I am mostly back to modern C++, a bit Java and Kotlin, contributing on their encoder and backend mostly for live streaming. I also got a chance to expand my frontend knowledge and dive into React properly. And, of course, I got to learn a lot about encoding and media streaming domain. I plan to write a few blog entries, little introductions to technologies I am dealing with.

Let me start here with the first one I got in touch with at Bitmovin:

RTMP, or Real-Time Messaging Protocol, is a widely-used protocol for streaming audio, video, and data over the internet. It was developed by Macromedia (now Adobe) and was most commonly used to stream live video and audio content to Flash players on web pages - at least until Flash was discontinued and later blocked. But the protocol is still popular and sees a lot of usage. One of the key features of RTMP is its low latency, which allows for real-time interactions between the streamer and the viewer. This makes it ideal for live events, online gaming, and other applications that require real-time communication.

To use RTMP to stream video, you will need a few things:

  • A video source: Some input, for example a camera, a pre-recorded video file, or a screen capture.
  • An encoder: This is a piece of software that takes your video source and converts it into a format that can be streamed over the internet.
  • A streaming server: This is a server that receives the encoded video from the encoder and sends it to viewers.
  • A player: Some client or web page that can play the video on the viewer’s device.

Common free and open source tools to provide inputs are FFmpeg and OBS.

Ffmpeg is a command-line tool that can be used to generate RTMP streams. To use ffmpeg to create an RTMP stream, you will need to first install it on your computer. Once ffmpeg is installed, you can use the following command to start streaming:

ffmpeg -i [input_file] -c:v libx264 -c:a aac -f flv rtmp://[server_url]/[stream_name]

In this command, input_file is the path to the video file or device you want to stream, server_url is the address of the RTMP server, and stream_name is the name you want to give to your stream. The -c:v libx264 and -c:a aac options specify the codecs to be used for the video and audio, respectively. The -f flv option tells ffmpeg to output the stream in FLV format, which is the only format supported by RTMP.

Another option to stream RTMP is, as I mentioned earlier, called OBS. OBS, or Open Broadcaster Software, is an open-source software program for video recording and live streaming. It is available for Windows, Mac, and Linux and is widely used by gamers, content creators, and live streamers to broadcast their content on platforms such as Twitch, YouTube, Facebook or Bitmovin.

OBS allows you to capture video from a variety of sources, including your screen, webcam, and external devices such as cameras and microphones. It also includes a variety of tools for adjusting video and audio settings, adding overlays, and more.

To start an RTMP stream with OBS, you will first need to set up a streaming server or use a third-party service such as Bitmovin. Once you have set up your server or chosen a service, you will need to create a “stream key” which is a unique code that allows you to connect to the server.

  • Open OBS and go to the “Settings” menu.
  • Select the “Stream” tab and choose either “Custom” or your chosen streaming service (if available).
  • Enter the server URL and stream key provided by your service or server.
  • In the “Sources” section, add the sources you want to use for your stream, such as your webcam, screen, or audio devices.
  • Customize your stream settings and hit the “Start Streaming” button.

OBS allows you to use custom RTMP server and stream keys, this way you can stream to your own server, a CDN or any other custom destination.

Cheers.