Overview
TrackComposite combines a video and an audio tracks together, outputing as a MP4, HLS, or RTMP stream. In order to resolve encoding differences from the WebRTC session, TrackComposite will transcode input streams to an encoding that's suitable for the output container.
TrackComposite Egress handles tricky scenarios such as synchronization, or if one of the tracks has been muted by the user.
Currently, TrackComposite is the method to use in order to export a single participant's audio and video together.
Usage
In order to use a TrackComposite, you need to know the TrackID of an audio and video track. This can be obtained either from the client SDK, or the TrackPublished webhook.
const output = {fileType: EncodedFileType.MP4,filepath: 'livekit-demo/track-composite-test.mp4',s3: {accessKey: 'aws-access-key',secret: 'aws-access-secret',region: 'aws-region',bucket: 'my-bucket'}};const info = await egressClient.startTrackCompositeEgress('my-room', output, audioTrackID, videoTrackID);const egressID = info.egressId;
request := &livekit.TrackCompositeEgressRequest{RoomName: "my-room",AudioTrackId: audioTrackID,VideoTrackId: videoTrackID,Output: &livekit.TrackCompositeEgressRequest_File{File: &livekit.EncodedFileOutput{FileType: livekit.EncodedFileType_MP4,Filepath: "livekit-demo/track-composite-test.mp4",Output: &livekit.EncodedFileOutput_S3{S3: &livekit.S3Upload{AccessKey: "aws-access-key",Secret: "aws-access-secret",Region: "aws-region",Bucket: "my-bucket",},},},},}info, err := egressClient.StartTrackCompositeEgress(ctx, request)egressID := info.EgressId
# require a special type for arrays, which enforces type# RTMP simulcast is supportedurls = Google::Protobuf::RepeatedField.new(:string, ['rtmp://url1', 'rtmps://url2'])info = egressClient.start_track_composite_egress('room-name',LiveKit::Proto::StreamOutput.new(protocol: LiveKit::Proto::StreamProtocol::RTMP,urls: urls),audio_track_id: 'TR_XXXXXXXXXXXX',video_track_id: 'TR_XXXXXXXXXXXX')puts info
LivekitEgress.EncodedFileOutput output = LivekitEgress.EncodedFileOutput.newBuilder().setFileType(LivekitEgress.EncodedFileType.MP4).setFilepath("livekit-demo/track-composite-test.mp4").setS3(LivekitEgress.S3Upload.newBuilder().setAccessKey("access-key").setSecret("secret").setBucket("bucket").setEndpoint("https://my.s3.endpoint").build()).build();Call<LivekitEgress.EgressInfo> call = client.startTrackCompositeEgress("roomName",output,"audioTrackId","videoTrackId");try {LivekitEgress.EgressInfo egressInfo = call.execute().body();// handle engress info} catch (IOException e) {// handle error}
{"room_name": "my-room","audio_track_id": "TR_XXXXXXXXXXXX","video_track_id": "TR_XXXXXXXXXXXX","file": {"file_type": "MP4","filepath": "livekit-demo/track-composite-test.mp4","s3": {"access_key": "aws-access-key","secret": "aws-access-secret","region": "aws-region","bucket": "my-bucket"}}}
livekit-cli start-track-composite-egress --request request.json
Egress started. Egress ID: EG_XXXXXXXXXXXX
Supported Outputs
TrackComposite supports the same output methods as RoomComposite: RTMP, MP4, and HLS. Refer to RoomComposite examples for additional details.