tencent cloud


Publishing over RTMP

Last updated: 2022-04-02 16:39:46


    To facilitate your integration of TRTC, we support publishing over the standard protocol RTMP. You can install OBS or FFmpeg 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 is currently in beta and is free of charge (we will notify you in advance if the beta status changes). However, an RTMP stream is considered a user in a TRTC room, which is subject to TRTC’s billing rules. For details, see Billing Overview. If you want to try this feature, contact us at xunchenliu@tencent.com to add your account to our allowlist (you need to provide your SDKAppID).


    You cannot play streams from TRTC over RTMP. To relay streams to CDNs for playback, see CDN Relayed Live Streaming.

    Use Cases

    Use CaseDescription
    Online education Using the desktop edition of OBS or FFmpeg, a teacher can publish a video of learning materials (most media formats are supported) over RTMP to a TRTC room. Students in the room can play the video via the TRTC SDK and see the learning materials as the teacher controls the playback progress/speed or switches between chapters. Excellent synchronization across multiple devices ensures better teaching quality.
    Watching sports events Sports event organizers provide content in the form of RTMP streams. You can publish the streams to TRTC rooms to allow audience members to watch the events with ultra-low latency. With TRTC’s interaction capability, audience members can also audio/video chat with each other throughout the event.
    Others You can also use the RTMP publishing feature to implement other real-time interactive applications based on streaming.

    Configuring OBS for Publishing


    You have installed OBS.

    Step 1. Select a source

    In the Sources panel at the bottom, click +, and select a source based on your needs. Common sources include the following:

    Source Description
    Image Publishing a single image
    Image Slide Show Publishing multiple images (you can determine the order of playback and whether to loop the playback)
    Scene Insertion of an entire scene as the source to enable various streaming effects
    Media Source Publishing a local file
    Text Adding real-time text to your stream
    Window Capture Capturing and publishing the window you select in real time
    Video Capture Device Capturing and publishing the images captured by a camera in real time
    Audio Input Capture Audio live streaming (audio input device)
    Audio Output Capture Audio live streaming (audio output device)

    Step 2. Set publishing parameters

    1. In the Controls panel at the bottom, click Settings.
    2. Click Stream and select Custom for Service.
    3. Enter rtmp://rtmp.rtc.qq.com/push/ for Server.
    4. Enter a stream key in the following format:
      Room ID?sdkappid=Application&userid=User ID&usersig=Signature

    Replace “Room ID”, “Application”, “User ID”, and “Signature” with the actual values, for example:

    - To simplify the parameters, TRTC supports only string-type room IDs. A room ID cannot exceed 64 characters and can contain only digits, letters, and underscores. To play an RTMP stream via TRTC, users must **use a string-type room ID to enter the room the stream is published to**.
    - For how UserSig is generated, see [UserSig](https://intl.cloud.tencent.com/document/product/647/35166). **Make sure your signature is within the validity period**.
    - The URL made up of the above server address and stream key can also be used for publishing with FFmpeg or other RTMP libraries.

    Step 3. Set the output

    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, enter 1 or 2 for Keyframe Interval, and click OK.

    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 disconnection due to network jitter.

    Step 6. Start publishing

    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 monitoring dashboard of the TRTC console.

    Step 7. Play

    As mentioned in Set publishing parameters, to play an RTMP stream, other users must use a string-type room ID to enter the TRTC room the stream is published to. Playing an RTMP stream on the web looks like this:

    Configuring FFmpeg

    To publish streams using the command line or other RTMP libraries, you can use the RTMP publishing URL made up of the server address and stream key in Set publishing parameters. Use H.264 for video encoding, AAC for audio encoding, and FLV for the container format, and we recommend 2s or 1s for GOP.
    The configuration of FFmpeg parameters varies with scenarios, so you need to have some knowledge of FFmpeg in order to publish using the software. The table below lists some common commands for FFmpeg. For more options, see FFmpeg documentation.

    FFmpeg command line

    ffmpeg [global_options] {[input_file_options] -i input_url} ... {[output_file_options] output_url} 

    Common FFmpeg options

    -reRead input at native frame rate. This is usually used to read local files.

    Options for output_file_options include:

    is recommended.

    -c:vVideo encoding library. libx264
    -b:vVideo bitrate. For example, 1500k means 1500 Kbps.
    -rVideo frame rate
    -profile:vVideo profile. Set it to baseline, which means not to encode B-frames. The TRTC backend does not support B-frames.
    -gGOP (keyframe interval)
    -c:aAudio encoding library. libfdk_aac is recommended.
    -acNumber of sound channels. Valid values: 1, 2
    -b:aAudio bitrate
    -fContainer format. Set it to flv. The FLV container format is required to publish to TRTC.
    Below is an example of reading a local file and publishing it to TRTC.
    ffmpeg -loglevel info -re -i sample.flv -c:v libx264 -preset fast -profile:v baseline -g 30 -sc_threshold 0 -b:v 1500k -c:a libfdk_aac -ac 2 -b:a 128k -f flv 'rtmp://rtmp.rtc.qq.com/push/hello-string-room?userid=rtmpForFfmpeg&sdkappid=140xxxxxx&usersig=xxxxxxxxxx'

    Demo: play from web

    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support