Real Time Messaging Protocol (RTMP) is used for high-speed transmission of audio, video, and data between a player and a server. You can make RTMP streaming to media servers with an MFWriter or an MWriter object.
Usually, a media server is used for RTMP streaming. So, MFormats's encoder will stream to the media server, and the media server will deliver the stream to end users.
Some of the media servers used for RTMP streaming are:
- Wowza Media Server
- Adobe Media Server
- YouTube
- Akamai Entry Point
- Justin TV
Some media servers, including Wowza and Adobe, support FLV H.263 video. But the more common encoding format is H.264.
To configure your MFWriter object you should select RTMP streaming format and select required audio and video codecs. Result configuration looks like:
format='flv' protocol='rtmp://' video::codec='n264' audio::codec='libmp3lame' audio::ar='44100'
If your target server is external one (YouTube, Akamai etc) you should add video::g='60' to your configuration to make streaming stable.
Implementing RTMP streaming in the code
Here's an example on how to configure RTMP streaming:
MFormats SDK:
MFWriter myWriter = new MFWriter(); string myConfiguration = @" format='flv' protocol='rtmp://' video::codec='n264' audio::codec='libmp3lame' audio::ar='44100'"; string destinationURL = @"rtmp://192.168.0.6:1935/live/myStream"; myWriter.WriterSet(destinationURL, 1, myConfiguration);
and then you can use myWriter object as a receiver to put frames to make RTMP streaming:
// a frame object MFFrame myFrame; // grab a frame ((IMFSource)myLiveSource).SourceFrameGet(-1, out myFrame, ""); // send to receiver ((IMFReceiver)myWriter).ReceiverFramePut(myFrame, -1, "");
MPlatform SDK
// Set up your source object, for example a device // ... // Start your source object myLiveSource.ObjectStart(null); // Initialize a new instance of MWriter object myWriter = new MWriterClass(); // Set destination URL and capturing configuration myWriter.WriterNameSet(myTargetURL, @"
format='flv' protocol='rtmp://' merge_tracks='true' video::codec='n264' audio::codec='libmp3lame' audio::ar='44100'"); // Start a streaming process myWriter.ObjectStart(myLiveSource);
Destination URL structure
The destination URL for RTMP streaming looks like this:
rtmp://[media server IP]:[port number]/[application name]/[stream_ID]
Where:
- media server IP - is the IP of your media server (if you use Wowza Media Server or Adobe Media Server it is the IP of the machine where the server is installed);
- port number - is the port number for streaming (by default it is "1935");
- application name - is the name of the server's application (for example, "live");
- stream ID - is the ID of your stream to the media server.
If you use external media servers (such as YouTube), all these parameters will be provided to you upon setting your channel upon the server's side.
Implementing secure streaming
RTMP streaming in MFormats and MPlatform SDKs is FFmpeg-based so there are different approaches in streaming to a protected server (it depends on server configuration). So please try using one of the following approaches for target URL:
rtmp://[LOGIN]:[PASSWORD]@[media server IP]:[port number]/[application name]/[stream_ID]
or
rtmp://[media server IP]:[port number]/[application name] flashver=FMLE/3.0\20(compatible;\20FMSc/1.0) live=true pubUser=[LOGIN] pubPasswd=[PASSWORD] playpath=[stream_ID]
or
rtmp://[media server IP]:[port number]/[application name]?username=password/[stream_ID]
Trying RTMP streaming with Writer Sample
1. Run the Writer sample, configure your source and select RTMP Streaming as encoding format:
2. Choose the video and audio codecs.
3. Paste the destination URL into the URL field and start streaming by clicking "Start Record" button.
Required bitrates for the best quality streaming
According to this NVidia article[link], these are the best values to stream with Nvidia encoder. You can approximately use these values to understand what bitrate you need to set with other encoders.
Upload Speed |
Bitrate |
Resolution |
Framerate |
3 Mbps |
2,500 |
1024x576 |
30 |
4 Mbps |
3,500 |
1280x720 |
30 |
6 Mbps |
5,000 |
1280x720 |
60 |
8-15 Mbps |
6,000 |
1920x1080 |
60 |
15+ Mbps |
12,000 (Youtube) |
1920x1080 |
60 |
20+ Mbps |
15,000+ (Youtube) |
2560x1440 |
60 |
40+ Mbps |
30,000+ (Youtube) |
3840x2160 |
60 |