unit Unit1;

interface

uses
  System.SysUtils, System.Classes, Vcl.Controls, Vcl.Forms, Vcl.StdCtrls,
  // Add any other required units here, for example the unit that contains VidGrab definitions
  VidGrab;

type
  TForm1 = class(TForm)
    btnPlay: TButton;
    VideoGrabber1: TVideoGrabber;  // Adjust the component type as needed
    procedure btnPlayClick(Sender: TObject);
  private
    { Private declarations }
    StreamingEncoderId: Integer;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btnPlayClick(Sender: TObject);
var
  StreamDesktop: Boolean;
begin
  // Set your own RTSP URL and Facebook key here
  // Enable/disable StreamDesktop to switch between screen and IP camera as source
  StreamDesktop := True;

  if StreamDesktop then
  begin
    VideoGrabber1.VideoSource := VidGrab.TVideoSource.vs_ScreenRecording;
    VideoGrabber1.UseNearestVideoSize(1920, 1080, True);
  end
  else
  begin
    VideoGrabber1.VideoSource := VidGrab.TVideoSource.vs_IPCamera;
    VideoGrabber1.IPCameraURL := 'rtsp://... your URL ';
  end;

  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 then
  begin
    // Handle error here
  end
  else
  begin
    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;
  end;
end;

end.
