tencent cloud

Feedback

Robot Streaming (TUIRoomKit)

Last updated: 2024-05-30 13:08:27

    Description of the Feature

    TUIRoomKit supports the use of robot push streaming, allowing users to push local or online media files into the room. In some scenarios, meetings may require the push of pre-recorded instructional videos or online video streams to online classrooms for users to watch and learn. TUIRoomKit can meet these needs, achieving automated and efficient video playback.
    
    
    

    Application Scenario

    Watching together, listening together, playing together, and learning together – experiences that previously required offline, face-to-face interaction are increasingly being moved online. The ability to watch movies, listen to music, and then discuss and share opinions with friends thousands of miles away is a magical real-time interactive experience that is loved by young people today, becoming a focus and mainstream direction of current audio and video products.
    TUIRoomKit input media stream feature allows sharing of external media streams within a room. Users can use this feature to share music, movies, lectures, courses, and other media content with other users in the room, engaging in real-time interaction with them. Platforms can leverage this new feature of TUIRoomKit to quickly implement a watch together scenario. In addition to watching movies and listening to music together, the input media stream capability of TUIRoomKit can also bring more innovative possibilities to the platform in scenarios such as interactive classrooms, sports competitions, and web conferences.
    
    
    

    Usage

    Method 1: Using RTMP for streaming (recommended)

    TUIRoomKit supports RTMP standard protocol for streaming. Depending on the situation, you can choose to install OBS, FFmpeg, or other RTMP libraries for streaming. This article will use FFmpeg as an example for introduction. FFmpeg requires specific command configuration parameters for different scenarios, so you should have some experience with FFmpeg. Below are commonly used FFmpeg Command Line options; for more FFmpeg Options, please refer to the FFmpeg official website.

    FFmpeg Command Line

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

    Common FFmpeg Options

    Option
    Description
    -re
    Reads input at native frame rate, generally only used for reading local files
    Among them, the configurable options for output_file_options include:
    Option
    Description
    -c:v
    Video Encoding, recommended to use libx264
    -b:v
    Video bitrate, for example, 1500k means 1500kbps
    -r
    Video Frame Rate
    -profile:v
    Video profile, specifying baseline will not encode B frames, TUIRoomKit backend does not support B frames
    -g
    GOP frame interval
    -c:a
    Audio Encoding, recommended to use libfdk_aac
    -ac
    Number of channels, fill in 2 or 1
    -b:a
    Audio Bitrate
    -f
    Specify format, fixed fill in flv, send to TUIRoomKit using FLV container

    Usage

    The following example uses FFmpeg command to read files and push to TUIRoomKit, note the quotes around the URL.
    ffmpeg -loglevel debug -re -i sample.flv -c:v libx264 -preset ultrafast -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/yourRoomId?userid=yourUserId&sdkappid=xxxxxxxxx&usersig=xxxxxxxxxx'
    The explanations for the parameters in the above command are as follows:
    Parameter
    Meaning
    -i sample.flv
    The media file that needs to be streamed to TUIRoomKit. You can replace sample.flv with the local or online media file you need to stream.
    yourRoomId
    The Room ID you need to stream to. You need to replace yourRoomId with your actual RoomId.
    userId
    The UserID you need to stream with. You need to change the value after "=" to the actual userId.
    sdkappid
    Your sdkappid, which you have previously obtained in Activate Service. You need to change the value after "=" to the actual sdkAppID.
    usersig
    Your usersig, which you have obtained when logging into TUIRoomKit. You need to change the value after "=" to the actual userSig.
    When you need to implement the above feature in code, you can use the relevant FFmpeg library on your platform or invoke FFmpeg through the command line to achieve the above command.

    Method 2: Use the Rest API to push online media streaming

    Interface description

    Push an online media stream to TUIRoomKit.
    API request domain: trtc.tencentcloudapi.com. Prerequisite: You need to purchase the TUIRoomKit package.
    Default API request frequency limit: 20 requests/second.
    

    Input Parameters

    The following request parameter list only provides API request parameters and some common parameters. For the complete common parameter list, see Common Request Parameters.
    Parameter Name
    Required
    Type
    Description
    Action
    Yes
    String
    Common Params. The value used for this API: StartStreamIngest.
    Version
    Yes
    String
    Common Params. The value used for this API: 2019-07-22.
    Region
    Yes
    String
    Common Params. For more information, please see the list of regions supported by the product. This API only supports: ap-bangkok, ap-jakarta, ap-mumbai, ap-singapore.
    SdkAppId
    Yes
    Integer
    TUIRoomKit's SdkAppId, the same as the SdkAppId corresponding to the Record room.
    RoomId
    Yes
    String
    TUIRoomKit's RoomId, the RoomId corresponding to the Record TUIRoomKit room.
    RoomIdType
    Yes
    Integer
    In TUIRoomKit, just fill in 0.
    UserId
    Yes
    String
    UserId of the Pull stream Relay Robot, used to enter the room and initiate the Pull stream Relay Task.
    UserSig
    Yes
    String
    UserSig corresponding to the Pull stream Relay Robot UserId, i.e., UserId and UserSig are equivalent to the Robot's Login password for entering the room. For the specific Calculation method, please refer to the TUIRoomKit UserSig Scheme.
    SourceUrl
    No
    Array of String
    Source URL. This field is required for historical reasons. If it is a video stream, please keep the resolution unchanged. Example value: https://a.b/test.mp4.
    VideoEncodeParams
    No
    Video Codec Parameters. Optional, if not filled, Keep original stream Parameters.
    AudioEncodeParams
    No
    Audio Codec Parameters. Optional, if not filled, Keep original stream Parameters.
    SourceUrl.N
    No
    Array of String
    (This field is obsolete, please use the StreamUrl field) Source stream URL, supports one address. Example value: https://a.b/test.mp4.
    SeekSecond
    No
    Integer
    Start playing the video from a specific timestamp.

    Output Parameters

    Parameter Name
    Type
    Description
    TaskId
    String
    The Task ID of the Pull stream Relay. The Task ID is a unique identifier for a Pull stream Relay lifecycle process, and it loses its meaning when the task ends. The Task ID needs to be saved by the business as a parameter for the next operation on this task.
    RequestId
    String
    The unique request ID, generated by the server, will be returned for every request (if the request fails to reach the server for other reasons, the request will not obtain a RequestId). RequestId is required for locating a problem.

    Sample code

    To initiate an Online Media Streaming Task, input the online media stream "https://a.b/test.mp4" into the TUIRoomKit room. Audio and video encoding will use default values. After successful relay, TaskId is returned.
    Input example
    POST / HTTP/1.1
    Host: trtc.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: StartStreamIngest
    <Common request parameters>
    
    {
    "SdkAppId": 1234567890,
    "RoomId": "room123",
    "UserId": "robot123",
    "UserSig": "xxxxxxxxxxxxxxx",
    "PrivateMapKey": "xxxxxxxxxxxxxxx",
    "RoomIdType": 1,
    "StreamUrl": "https://a.b/test.mp4"
    }
    Sample output
    {
    "Response":{
    "Error":{
    "Code":"xxxxx",
    "Message":"xxxxxxxxxx",
    },
    "RequestId":"b99c5411-9f69-4725-a0e1-e5b5df451fc2"
    }
    }

    Error code

    The error codes listed below are only relevant to the API business logic. For more error codes, refer to Common Error Codes.
    Error code
    Description
    FailedOperation.NotRtmpFunction
    RTMP not activated
    FailedOperation.RestrictedConcurrency
    Single User Concurrency Overload, please contact us to increase the number of concurrent paths to a reasonable value.
    FailedOperation.TaskExist
    Task Already Exists
    InternalError.HttpParseFailed
    HTTP Request parse failed.
    InternalError.InternalError
    Internal error, please try again.
    InvalidParameter.BodyParamsError
    Failed to Parse Body Parameters.
    InvalidParameter.RoomId
    RoomId parameter error.
    InvalidParameter.SdkAppId
    SdkAppId parameter error.
    InvalidParameter.StrRoomId
    StrRoomId parameter error.
    InvalidParameter.TaskId
    TaskId parameter error.
    InvalidParameter.UserSig
    UserSig is expired or incorrect.
    MissingParameter.RoomId
    The `RoomId` parameter is missing.
    MissingParameter.SdkAppId
    The `SdkAppId` parameter is missing.
    MissingParameter.TaskId
    The `TaskId` parameter is missing.
    ResourceInsufficient.RequestRejection
    Insufficient resources.
    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