Actually, both Facebook Live and YouTube streamings are RTMP streaming. And both require H.264 encoded video. Here you can find information about H.264 encoding options:
https://support.medialooks.com/hc/en-us/articles/360000210192-H-264-encoding-options
Note please, that this information is valid for many external streaming services, like Twitch, Azure Media etc.
Encoding settings
Here is a Google guide about bitrate settings that perfectly suits for Facebook too:
https://support.google.com/youtube/answer/2853702?hl=en&ref_topic=6136989
Note that at the moment YouTube supports up to 4K streaming whereas Facebook works fine with an HD720 format.
For example, to stream 720 50p video an encoding configuration looks like:
format='flv' protocol='rtmp://' merge_tracks='true' video::codec='n264' video::b='3M' video::maxrate='4M' video::g='100' audio::codec='libmp3lame' audio::ar='44100'
Note the video::g attribute. It is a key frame interval value. According to FFmpeg guide about streaming sites, you should use a 2-seconds interval, so simply multiply your output frame rate * 2. For example, if your input framerate is 50, then use video::g='100'.
You should use a server name and a stream name provided by YouTube (or Facebook) on a channel configuration page. In common case, it has the following structure:
rtmp://[server_name]/[stream_name]
Both server_name and stream_name parameters are available on your streaming configuration page on YouTube or Facebook.
Note: you can stream on YouTube and Facebook at the same time with the 'second encoder'.
RTMP streaming process
Actually, the streaming process is similar to common RTMP streaming to any media server like Wowza. You should configure and initialize your source object and then start streaming with MWriter (or MFWriter) object.
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' video::b='3M' video::maxrate='4M' video::g='60' audio::codec='libmp3lame' audio::ar='44100'"); // Start a streaming process myWriter.ObjectStart(myLiveSource);
MFormats SDK
Configure an MFWriter object:
myWriter = new MFWriter(); string myConfiguration = @" format='flv' protocol='rtmp://' video::codec='n264' audio::codec='libmp3lame' audio::ar='44100'"; string destinationURL = @"rtmp://192.168.0.1935/live/myStream"; myWriter.WriterSet(destinationURL, 1, myConfiguration);
Start sending MFFrame objects with this object:
// a frame object MFFrame myFrame; // grab a frame ((IMFSource)myLiveSource).SourceFrameGet(-1, out myFrame, ""); // send to receiver ((IMFReceiver)myWriter).ReceiverFramePut(myFrame, -1, "");
HLS streaming process
To use the HLS protocol, you need to select the appropriate stream key in the Youtube stream settings and get the stream URL:
MPlatform SDK
Set up your source object, set stream URL and capturing configuration:
string myTargetURL = @"https://a.upload.youtube.com/http_upload_hls?cid=qb02-4yjc-w1c4-qq2p-7dpr©=0&file=live.m3u8";
m_objWriter.WriterNameSet(myTargetURL, @"format='hls' video::codec='n264' audio::codec='aac'");
m_objWriter.ObjectStart(m_objLive);
MFormats SDK
Configure an MFWriter object and start sending MFFrame objects:
m_objWriter = new MFWriter();
string myConfiguration = @"format='hls' video::codec='mpeg4' audio::codec='aac'";
string destinationURL = @"https://a.upload.youtube.com/http_upload_hls?cid=qb02-4yjc-w1c4-qq2p-7dpr©=0&file=live.m3u8";
m_objWriter.WriterSet(destinationURL, 1, myConfiguration);
MFFrame myFrame;
((IMFSource)myLiveSource).SourceFrameGet(-1, out myFrame, "");
((IMFReceiver)myWriter).ReceiverFramePut(myFrame, -1, "");