To facilitate your integration of TRTC, we support publishing and playback over the standard protocol RTMP. You can install OBS, FFmpeg, or other RTMP libraries to publish streams with TRTC. OBS is a third-party open-source tool for live streaming. It’s easy to use and free of charge, and it supports OS X, Windows, and Linux. OBS can be used in a wide range of scenarios and is capable of meeting most live streaming needs without requiring additional plugins. You can download its latest version at the OBS website.
This feature will end its beta testing starting from February 15, 2023. To use it, you need to purchase a TRTC Standard or Pro Monthly Packages. Applications (SdkAppID) that have been enabled before this time can be used for free until April 1, 2023 (buffer period). An RTMP stream will be considered a user in a TRTC room, which will incur call duration fees. For more information, please refer to the Billing of Audio and Video Duration. Transcoding operations will be performed during the process of connecting RTMP streams, thereby incurring transcoding fees. For more information, please refer to the Billing of On-Cloud MixTranscoding.
Use Cases
Scenario
Description
Online education
Use the desktop edition of OBS or FFmpeg to publish learning materials (most media formats are supported) over RTMP to a TRTC room. Students in the room can play the stream via the TRTC SDK and see the same learning materials as the teacher controls the playback progress/speed or switches between chapters. Excellent synchronization across multiple devices ensures better teaching quality.
Sports watching
Sports event organizers provide content in the form of RTMP streams. You can publish the streams to TRTC rooms so that users in the rooms can watch the event with ultra-low latency. With TRTC’s interaction capability, users can also audio/video chat with each other throughout an event.
Others
You can also use the RTMP publishing feature to implement other real-time interactive applications based on streaming.
Architecture
An RTMP client is a module of TRTC and can communicate with other TRTC clients. The interconnection delay is less than 600ms under normal circumstances. It can also use TRTC capabilities such as recording and relaying. The network architecture is shown in the figure below.
Replace "Room ID", "Application ID", "User ID", and "Signature" with their actual values.
For the sake of simplicity, we support only string-type room IDs. A room ID can contain numbers, letters, and underscores and cannot exceed 64 characters.
Warning:
To play an RTMP stream on other TRTC clients, when entering the room, make sure you use a string-type room ID.
For how to generate UserSig, see UserSig. Make sure your signature is within the validity period.
Because RTMP does not support B-frames, set the video encoding parameters as follows to remove B-frames.
1. Go to Controls > Settings > Output.
2. Select Advanced for Output Mode. The recommended Keyframe Interval is 1 or 2. For CPU Usage Preset, select ultrafast. For Profile, select baseline. For Tune, select zerolatency. And for x264 Options, enter threads=1, and then click OK.
Warning:
You need to remove the B-frames in RTMP streams, otherwise the connection will be disconnected after pushing. To achieve this, select baseline for Profile.
Step 4. Set video parameters
You can set video resolution and frame rate under the Video section of Settings. Resolution determines the clarity of video shown to audience members. The higher the resolution, the clearer the video. Frame rate (frames per second) determines playback smoothness. Typical frame rate falls in the range of 24 fps to 30 fps. Playback may stutter if frame rate is lower than 16 fps. Video games require higher frame rate and tend to stutter at a frame rate lower than 30 fps.
Step 5. Configure advanced settings
To reduce end-to-end delay, we recommend you do not enable Stream Delay.
Keep Automatically Reconnect enabled and make Retry Delay as short as possible so that the publisher can be reconnected quickly after a disconnection occurs due to network jitter.
Step 6. Publish the stream
1. In the Controls panel at the bottom, click Start Streaming.
2. If streaming is successful, the bottom bar will show streaming statistics, and the entry of a user will be recorded by the TRTC monitoring dashboard.
Step 7. Play the stream on other clients
As mentioned above in Set publishing parameters, to play the RTMP stream on other TRTC clients, you need to use a string-type room ID when entering the room. The screenshot below is an example of playing the RTMP stream on a browser. (ps : You can go to the Demo pageand enter the room on any client-side to view the stream .)
Using FFmpeg to publish streams
To publish RMTP streams using FFmpeg commands or other RTMP libraries, you need to use the full URL, the H.264 video codec, and the AAC audio codec. For the container format, FLV is recommended. For GOP, one or two seconds is recommended.
The configuration of FFmpeg parameters varies with different scenarios, so you need to have some knowledge of FFmpeg in order to use it to publish streams. The table below lists some common FFmpeg commands. For more options, see FFmpeg documentation.