livekit / livekit-server-sdk-python

LiveKit Server SDK for Python
Apache License 2.0
25 stars 6 forks source link

I got issue with RTMP stream #3

Closed nhha1602 closed 1 year ago

nhha1602 commented 1 year ago

Hi,

I'm using this sdk for my backend. My flow at my backend as below:

Livekit server: v1.2.5 livekit-server-sdk-python: 0.4.1

In init.py of livekit-server-sdk-python, I added following code:

class TrackServiceClient: """ Client to access Egress APIs """ def init(self, host: str, api_key: str, api_secret: str): self._client = TwirpEgressServiceClient(host) self._api_key = api_key self._api_secret = api_secret

def _create_context(self, **grant_kwargs):
    grant = VideoGrant(**grant_kwargs)
    access_token = AccessToken(
        self._api_key,
        self._api_secret,
        grant=grant,
        ttl=timedelta(minutes=10),
    )
    return Context(headers={"Authorization": f"Bearer {access_token.to_jwt()}"})

def list_egress(
    self,
    room_name: str
):
    """
    Do list egress.
    """
    ctx = self._create_context(room_admin=True, room=room_name)
    request = ListEgressRequest(room_name=room_name)
    self._client.ListEgress(ctx=ctx, request=request)

def track_egress(
    self,
    room_name: str,
    track_id: str,
    rtmpUrl: str
):
    """
    Do track egress.
    """
    ctx = self._create_context(room_admin=True, room_record=True, room=room_name)
    rtmpOutput = StreamOutput(protocol=1, urls=[rtmpUrl])
    request = TrackCompositeEgressRequest(room_name=room_name, video_track_id=track_id, stream=rtmpOutput)
    self._client.StartTrackEgress(ctx=ctx, request=request)

I called track_egress with rtmpUrl = "rtmp://esw-rtmp.livekit:1935/live/test-room1"

But I got below error at my backend:

raise exceptions.TwirpServerException.from_json(resp.json()) twirp.exceptions.TwirpServerException: the protobuf request could not be decoded

And on livekit server logs:

2023-01-04T09:52:26.579Z INFO livekit service/twirp.go:111 API Egress.StartTrackEgress {"service": "Egress", "method": "StartTrackEgress", "duration": "67.808µs", "status": "400", "error": "the protobuf request could not be decoded", "code": "malformed"}

How can I fixed it ? please advise this.

I fixed it, I called wrong function in track_egress, it should be: StartTrackCompositeEgress

For example: I used livekit-cli for stream request as below and it worked:

{ "room_name": "test-room1", "video_track_id": "TR_VCHQ3DH3JauRdJ", "stream": { "urls": [ "rtmp://esw-rtmp.livekit:1935/live/test" ] } }

nhha1602 commented 1 year ago

close this please