PlainTransport, ffmpeg, recording

Hello!
I’m trying to record a video, and I do this:

       const worker = await mediasoup.createWorker(...);
       const router = await worker.createRouter(...);

      const webrtcTransport = ...;
      const producerMap = ...; // audio and video producers by kind

        let rtpTransport = await router.createPlainTransport({
            rtcpMux: false,
            listenInfo: {
                protocol: 'udp',
                ip: '192.168.0.218', // my local IP address
            },
        });

        console.log('rtp tuple: ', rtpTransport.tuple);

        await rtpTransport.connect({
            ip: '192.168.0.218', // my local IP address
            port: rtpTransport.tuple.localPort,
            rtcpPort: rtpTransport.rtcpTuple.localPort
        });

        for (let [kind, producer] of client.producerMap) {
            const codecs = [];
            const routerCodec = router.rtpCapabilities.codecs.find(
                codec => codec.kind === kind,
            );
            codecs.push(routerCodec);

            console.log('codecs: ', codecs);

            await rtpTransport.consume({
                producerId: producer.id, // producer id from WebRtcTransport
                rtpCapabilities: {
                    codecs,
                    rtcpFeedback: [],
                },
            });
        }

I check for a stream through the VLC media player, but nothing shows there. (it doesn’t work in ffmpeg command either.) I read the documentation and various examples. But I can’t figure out why it doesn’t work.
What am I doing wrong?

Why are you assuming that the codecs supported by the mediasoup Router are the codecs that the consuming endpoint support?

Thank you for your fast reply

I thought the consumer work through a transport created by the router, if their codecs are not supported by the router, the transport will also not accept them.
Isn’t it so?

It doesn’t work! Has anyone done this in practice? any help!!

Of course that assuming that your consuming endpoint (VLC media player) supports the exact codecs and codec configurations than the codecs given to the mediasoup Router won’t work. I sent a link above. Please don’t ignore it.

Yes, I read the documentation by link above, and I logged this data:

audio consumer for sdp data

{
localIp: '127.0.0.1',
  localPort: 40874,
  codecs: [
    {
      mimeType: 'audio/opus',
      clockRate: 48000,
      payloadType: 100,
      channels: 2,
      ssrc: 650582774,
      cname: '/obshdcxRX6Lju3w'
    }
  ]

and video consumer sdp data

localIp: '127.0.0.1',
  localPort: 40074,
  codecs: [
    {
      mimeType: 'video/VP8',
      clockRate: 90000,
      payloadType: 101,
      channels: undefined,
      ssrc: 554091003,
      cname: '/obshdcxRX6Lju3w'
    }
  ]

than I created SDP file

v=0
o=- 0 0 IN IP4 127.0.0.1
s=Mediasoup RTP Stream
t=0 0
c=IN IP4 127.0.0.1

m=video 40074 RTP/AVP 101
a=rtpmap:101 VP8/90000
a=framesize:101 640-480
a=ssrc:554091003 cname:/obshdcxRX6Lju3w

m=audio 40874 RTP/AVP 100
a=rtpmap:100 OPUS/48000/2
a=ssrc:650582774 cname:/obshdcxRX6Lju3w

in VCL media play, I can’t play with this SDP.

then I tried through ffmpeg commands. does not work((.

I don’t know what exactly VLC supports but probably you don’t want to have blank lines in the SDP (that’s incorrect) and most probably you want to place the audio section first.

hi media soup demo is disconnected for 2 days giving error in connection and then close()

I definitely couldn’t setting VLC codecs either, so I mainly test in ffmpeg

and updated the SDP as you said

v=0
o=- 0 0 IN IP4 127.0.0.1
s=Mediasoup RTP Stream
t=0 0
c=IN IP4 127.0.0.1
m=audio 40815 RTP/AVP 100
a=rtpmap:100 OPUS/48000/2
a=ssrc:490896972 cname:NtMtvNflfczSLdO3/
m=video 40714 RTP/AVP 101
a=rtpmap:101 VP8/90000
a=framesize:101 640-480
a=ssrc:599134926 cname:NtMtvNflfczSLdO3/

but unfortunately it is not recorded.
below are some commands ffmpeg:

ffmpeg -loglevel debug -protocol_whitelist "file,udp,rtp" -f sdp -i input.sdp -map 0:v:0 -map 0:a:0 -c:v copy -c:a aac output.mp4(or .webm)

ffmpeg -loglevel debug -protocol_whitelist "file,rtp,udp" -i input.sdp -c:v copy -f mpegts output.mp4(or .webm)

ffmpeg -loglevel debug -protocol_whitelist "file,rtp,udp" -fflags nobuffer -flags low_delay -strict experimental -i input.sdp -c:v libx264 -preset ultrafast -crf 23 -an output.mp4(or .webm)

ffmpeg -loglevel debug -protocol_whitelist "file,pipe,rtp,udp" -i input.sdp -c:v libx264 -preset ultrafast output.mp4(or .webm)

I’m afraid I cannot help with ffmpeg things.

1 Like

please tell me how to check if RTP is working correctly?

Fix this, please. You are passing the ip and ports of the transport in mediasoup side instead than the ip and port where VLC or ffmpeg are listening. Read the docs of plainTransport.connect().

1 Like

I really appreciate your help, your patience, and your time. Everything worked out perfectly. Thank you so much! :+1:

Glad to hear that

2 Likes