Broadcast to YouTube/Twitch 🔗



This feature is part of OpenVidu PRO and ENTERPRISE editions.

You can easily broadcast your OpenVidu sessions to YouTube Live, Twitch or any other live ingestion service.

How does broadcasting work 🔗

To start the broadcast of your OpenVidu session you just need to call the appropriate method passing the identifier of the session to broadcast and the URL of the ingestion service. These URLs usually start with rtmp:// or rtmps://.

OpenVidu openvidu = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET);
Session session = openvidu.createSession();

// After some participant starts publishing to the session...
openvidu.startBroadcast(session.getSessionId(), "rtmp://live.twitch.tv/app/{STREAM_KEY}");

See JavaDoc


To stop the broadcast of your OpenVidu session:

openvidu.stopBroadcast(session.getSessionId());

See JavaDoc



Customize your broadcast 🔗


The broadcast service uses the same underlying module than the COMPOSED recording service. This means that you can use the same properties to customize the broadcast as you would do with a COMPOSED recording:

OpenVidu openvidu = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET);
Session session = openvidu.createSession();

// After some participant starts publishing to the session...
RecordingProperties properties = new RecordingProperties.Builder()
  .recordingLayout(RecordingLayout.BEST_FIT)
  .resolution("1280x720")
  .frameRate(15)
  .build();
openvidu.startBroadcast(session.getSessionId(), "rtmp://live.twitch.tv/app/{STREAM_KEY}", properties);

See JavaDoc


The actual recording properties that take effect when applied to a broadcast are a subset of the recording properties, which includes:

  • hasAudio
  • hasVideo
  • resolution
  • frameRate
  • recordingLayout
  • customLayout
  • shmSize
  • mediaNode

You can read a complete description of them in the REST API docs.

Custom broadcast layouts 🔗

The default layout used when broadcasting an OpenVidu Session will evenly distribute each published stream in the available space. But you can implement your own custom layout with HTML/CSS/JS. This is exactly the same and works in the same way as explained in this COMPOSED recording section: Custom recording layouts. Everything that is explained there for the custom layouts of COMPOSED recordings applies equally to the custom layouts of the broadcasts.

NOTE: in order to use custom layouts when broadcasting, it is necessary to setup property OPENVIDU_RECORDING=true in the OpenVidu deployment configuration.



Scalable broadcasting 🔗

By default the broadcast module runs in the same Media Node hosting the broadcasted Session (see OpenVidu Pro architecture). Hosting the broadcast in the same Media Node as its session is the optimal and default choice, as the media doesn't need to be sent across different Media Nodes, saving network traffic. But you can decide to start the broadcast of a particular session in a different Media Node, if your specific use case can take advantage of it:

RecordingProperties properties = new RecordingProperties.Builder()
    .mediaNode("media_i-1234567890abcdef0") // The string being the unique ID of an existing Media Node
    .build();
openvidu.startBroadcast(session.getSessionId(), "rtmp://live.twitch.tv/app/{STREAM_KEY}", properties);

See JavaDoc


If the provided Media Node does not exist or its status is not valid for starting a broadcast, then a 400 BAD_REQUEST response is returned. The active broadcasts that are hosted by a Media Node at any given time are available in the Media Node object of the REST API, in attribute broadcasts.



Use your own RTMP server 🔗

OpenVidu broadcasting API allows you to live-stream your OpenVidu sessions to any kind of RTMP ingestion service. This includes not only popular services such as YouTube or Twitch, but also custom RTMP servers. For example, NGINX offers an RTMP module that easily allows setting up a live-streaming server for your OpenVidu sessions to be consumed by thousands of users: NGINX RTMP.