Video Capture and Live Streaming

Our Games SDK for PC brings capturing capabilities to your game. This makes it simple to give your players the ability to Live stream their game play to Facebook, as well as capturing and storing memorable in-game moments to share.

System Requirements

Please note that currently we only support games that run on DirectX11. We are working on supporting other graphics APIs soon.

NVidia

  • Operating System: Windows 7 SP1, 8, 10, Server 2008 R2, Server 2012
  • DirectX 11
  • GPU: NVIDIA Quadro, Tesla, GRID or GeForce products with Kepler, Maxwell and Pascal generation GPUs.
  • NVidia Windows display driver: 375.95 or newer
  • SDK: nVidia Video Codec SDK 7.1

AMD

  • Operating System: Windows 7 SP1, 8, 10
  • DirectX 11
  • GPU: AMD GPUs supporting following driver
  • AMD Windows display driver: AMD Radeon Software Crimson 17.1.1 or later
  • SDK: AMD Advanced Media Framework SDK 1.4

Live Streaming from C++

    fbg_Livestream_Create();
    

This will trigger the Live stream dialogs. On the first dialog, the player can select which microphone and camera to use.

The response of this dialog should be handled:

      while ((message = fbg_PopMessage()) != nullptr) {
        switch (fbg_Message_GetType(message)) {
          // ...
          case fbgMessage_Livestream_Create: {      
            auto liveStreamCreateMessage = fbg_Message_Livestream_Create(message);
            char id[512];
            char streamUrl[512];
            char secureStreamUrl[512];

            fbg_Livestream_Create_GetId(liveStreamCreateMessage, id, 512);
            fbg_Livestream_Create_GetStreamUrl(liveStreamCreateMessage, streamUrl, 512);
            fbg_Livestream_Create_GetSecureStreamUrl(liveStreamCreateMessage, secureStreamUrl, 512);

            fbg_Livestream_Publish(id, streamUrl, secureStreamUrl);
    

Now, the player's live stream is published, and you should begin the capture engine to send live stream data to the live stream.

For the capture engine to function, you should pass in your ID3D11Device* to the capture engine, ideally at start up of your game:

      ID3D11Device* myDevice; // from engine
      fbg_Capture_SetGraphicsDeviceD3D11(myDevice);
    

Next, you should forward the selected microphone and camera selected by the player to the capture engine. We'll begin with the microphone selection from the Facebook UI launched by fbg_Livestream_Create():

      bool shouldCaptureMic = fbg_Livestream_Create_ShouldCaptureAudioInput(liveStreamCreateMessage);
      if (!shouldCaptureMic)
      {
      	return;
      }
	  
      int fbUIMicIndex = fbg_Livestream_Create_GetAudioInputIndex(liveStreamCreateMessage);

      char fbUIMicLabel[50];
      if (fbUIMicIndex != -1)
      {
         fbg_Livestream_Create_GetAudioInputLabel(liveStreamCreateMesage, fbUIMicLabel, 50);      	
      }

      // Set up player's chosen microphone    
      if (fbUIMicIndex != -1)
      {
      	// Link the fb UI index to the capture index
      	// You must enumerate the devices in the engine before indexing
      	fbg_Capture_EnumerateMicDevices();      
        fbg_Capture_SetMicDevice(fbUIMicIndex);
      }            
    

Now, forward the camera selection from the Facebook UI launched by fbg_Livestream_Create():

      bool shouldCaptureCamera = fbg_Livestream_Create_ShouldCaptureVideoInput(liveStreamCreateMessage);
      if (!shouldCaptureCamera)
      {
      	return;
      }
	  
      int fbUICameraIndex = fbg_Livestream_Create_GetVideoInputIndex(liveStreamCreateMessage);

      char fbUICameraLabel[50];
      if (fbUICameraIndex != -1)
      {
         fbg_Livestream_Create_GetVideoInputLabel(liveStreamCreateMesage, fbUICameraLabel, 50);      	
      }
            
      // Set up player's chosen camera    
      if (fbUICameraIndex != -1)
      {
      	// Link the fb UI index to the capture index
      	// You must enumerate the devices in the engine before indexing
      	fbg_Capture_EnumerateCameraDevices();      
        fbg_Capture_SetCameraDevice(fbUICameraIndex);
        float cameraOverlayWidthPcnt = 15.0f; // What percent of the screen you want the camera to take
        uint32_t cameraOverlayViewPortTopLeftX = 0; // Position x coord of camera overlay
        uint32_t cameraOverlayViewPortTopLeftY = 0; // Position y coord of camera overlay
        fbg_Capture_SetCameraOverlaySettings(cameraOverlayWidthPcnt, cameraOverlayViewPortTopLeftX, cameraOverlayViewPortTopLeftY);
      }            
    

Now that the camera and microphone ui selections have been forwarded to the capture engine, you can start the capture engine live stream:

      auto liveVideoWidth = 1920;
      auto liveVideoHeight = 1080;
      auto liveVideoFrameRate = 30;
      auto liveVideoBitRate = 5000000;
      auto encodingInitialFlushCycle = 5.0f; // how long in seconds we wait initially to flush live streaming buffer data to the server
      auto encodingSecondaryFlushCycle = 5.0f; // period between flushing live streaming buffer data to the server after the initial flush
      auto is360CaptureTexture = false;
      auto textureNeedsFlipping = true; // depends on how your live stream textures are captured in your graphics engine
      fbg_Capture_SetLiveCaptureSettings(liveVideoWidth, liveVideoHeight, liveVideoFrameRate, liveVideoBitRate, encodingInitialFlushCycle, encodingSecondaryFlushCycle, streamUrl, is360CaptureTexture, textureNeedsFlipping);
      
      // Start capture engine Livestream
      fbg_Capture_StartLiveCapture();
      
    

At this point, the capture engine is running, and is awaiting new textures to capture for the live stream. You should pass in textures you wish to live stream in your engine's update loop:

     
   // ... in game update loop  
   if (...isLiveStreaming...)
   {
   	ID3D11Texture2D* texture = //... from your engine
        FBCAPTURE_STATUS status = fbg_Capture_CaptureTexture(texture);
   	if (status != FBCAPTURE_STATUS_OK)
   	{
   		// Something went wrong, the capture engine is no longer live streaming.
   	}
   }      
    

You can also poll for any internal status changes, which will let you know the live stream is running ok:

     
   // ... in game update loop  
   if (...isLiveStreaming...)
   {
   	FBCAPTURE_STATUS status = fbg_Capture_GetCaptureStatus();
   	if (status != FBCAPTURE_STATUS_OK)
   	{
   		// Something went wrong, the capture engine is no longer live streaming.
   	}
   }      
    

At this point, your engine is now sending data to the live stream capture engine. But it's up to the player to actually go live with the live stream:

Finally, you can stop the player's live stream:

      fbg_Capture_StopCapture();