// Set your own RTSP URL and Facebook key
// Enable/disable StreamDesktop to switch between screen and IP camera as source

private int StreamingEncoderId = -1;

private void btnPlay_Click(object sender, EventArgs e)
{
    bool StreamDesktop = true;

    if (StreamDesktop)
    {
        VideoGrabber1.VideoSource = VidGrab.TVideoSource.vs_ScreenRecording;
        VideoGrabber1.UseNearestVideoSize(1920, 1080, true);
    }
    else
    {
        VideoGrabber1.VideoSource = VidGrab.TVideoSource.vs_IPCamera;
        VideoGrabber1.IPCameraURL = "rtsp://... your URL ";
    }

    VideoGrabber1.AudioSource = VidGrab.TAudioSource.as_Silent;

    StreamingEncoderId = VideoGrabber1.Encoders_CreateInstanceForStreaming(
        "rtmps://live-api-s.facebook.com:443/rtmp/FB-613202114689260-0-Ab068DGkxkj_cbiR2b313");

    if (StreamingEncoderId == -1)
    {
        // Handle error
    }
    else
    {
        VideoGrabber1.Encoder_SetStr(StreamingEncoderId, 
                                     VidGrab.TEncoder_str.Enc_Video_Codec, 
                                     "h264");
        VideoGrabber1.Encoder_SetInt(StreamingEncoderId, 
                                     VidGrab.TEncoder_int.Enc_Video_Enabled_bool, 
                                     1);
        VideoGrabber1.Encoder_SetInt(StreamingEncoderId, 
                                     VidGrab.TEncoder_int.Enc_Audio_Enabled_bool, 
                                     1);
        VideoGrabber1.Encoder_SetInt(StreamingEncoderId, 
                                     VidGrab.TEncoder_int.Enc_Video_BitRate_kb, 
                                     2500);
        VideoGrabber1.Encoder_SetInt(StreamingEncoderId, 
                                     VidGrab.TEncoder_int.Enc_Video_rc_MaxBitRate_kb, 
                                     2500);
        VideoGrabber1.Encoder_SetInt(0, 
                                     VidGrab.TEncoder_int.Enc_Video_rc_BufferSize_kb, 
                                     5000);
        VideoGrabber1.Encoder_SetInt(StreamingEncoderId, 
                                     VidGrab.TEncoder_int.Enc_Video_IDR_Interval, 
                                     50);
        VideoGrabber1.Encoder_SetInt(StreamingEncoderId, 
                                     VidGrab.TEncoder_int.Enc_IsActive_bool, 
                                     1);

        VideoGrabber1.StartPreview();
    }
}
