How to get data from mediasoup-worker consumer

Hello, I’m integrating mediasoup-worker into my graduation project and I’m using transport.consume to get rtp stream but encountered a problem confusing me for a few days. I have read documents but cannot solve the problem.
These are my requests:

==>router.createPlainTransport
publisher write message to mediasoup:
155:{“data”:{“listenIp”:{“ip”:“127.0.0.1”}},“id”:2,“internal”:{“routerId”:“router-test”,“transportId”:“transport-test”},“method”:“router.createPlainTransport”},

mediasoup write message to publisher:
426:{“accepted”:true,“data”:{“comedia”:false,“consumerIds”:[],“dataConsumerIds”:[],“dataProducerIds”:[],“direct”:false,“id”:“transport-test”,“mapRtxSsrcConsumerId”:{},“mapSsrcConsumerId”:{},“maxMessageSize”:262144,“producerIds”:[],“recvRtpHeaderExtensions”:{},“rtcpMux”:true,“rtpListener”:{“midTable”:{},“ridTable”:{},“ssrcTable”:{}},“traceEventTypes”:"",“tuple”:{“localIp”:“127.0.0.1”,“localPort”:15499,“protocol”:“udp”}},“id”:2},

==>transport.produce
publisher write message to mediasoup:
482:{“data”:{“kind”:“video”,“rtpMapping”:{“codecs”:[{“mappedPayloadType”:96,“payloadType”:96}],“encodings”:[{“mappedSsrc”:222222,“rid”:“rid-test”,“ssrc”:111111}]},“rtpParameters”:{“codecs”:[{“clockRate”:48000,“mimeType”:“video/H264”,“payloadType”:96,“rtcpFeedback”:{“type”:“nack”}}],“encodings”:[{“active”:true,“maxBitrate”:100000,“rid”:“rid-test”}]}},“id”:3,“internal”:{“producerId”:“producer-test”,“routerId”:“router-test”,“transportId”:“transport-test”},“method”:“transport.produce”},

mediasoup write message to publisher:
49:{“accepted”:true,“data”:{“type”:“simple”},“id”:3},rIds":[],“dataConsumerIds”:[],“dataProducerIds”:[],“direct”:false,“id”:“transport-test”,“mapRtxSsrcConsumerId”:{},“mapSsrcConsumerId”:{},“maxMessageSize”:262144,“producerIds”:[],“recvRtpHeaderExtensions”:{},“rtcpMux”:true,“rtpListener”:{“midTable”:{},“ridTable”:{},“ssrcTable”:{}},“traceEventTypes”:"",“tuple”:{“localIp”:“127.0.0.1”,“localPort”:15499,“protocol”:“udp”}},“id”:2},

==>router.createPlainTransport
publisher write message to mediasoup: 161:{“data”:{“listenIp”:{“ip”:“127.0.0.1”}},“id”:4,“internal”:{“routerId”:“router-test”,“transportId”:“consume-transport-id”},“method”:“router.createPlainTransport”},

mediasoup write message to publisher:
432:{“accepted”:true,“data”:{“comedia”:false,“consumerIds”:[],“dataConsumerIds”:[],“dataProducerIds”:[],“direct”:false,“id”:“consume-transport-id”,“mapRtxSsrcConsumerId”:{},“mapSsrcConsumerId”:{},“maxMessageSize”:262144,“producerIds”:[],“recvRtpHeaderExtensions”:{},“rtcpMux”:true,“rtpListener”:{“midTable”:{},“ridTable”:{},“ssrcTable”:{}},“traceEventTypes”:"",“tuple”:{“localIp”:“127.0.0.1”,“localPort”:49342,“protocol”:“udp”}},“id”:4},

==>transport.consume
publisher write message to mediasoup:
494:{“data”:{“consumableRtpEncodings”:[{“ssrc”:222222}],“consumerId”:“consumer-test”,“kind”:“video”,“rtpParameters”:{“codecs”:[{“clockRate”:48000,“mimeType”:“video/H264”,“payloadType”:96,“rtcpFeedback”:{“type”:“nack”}}],“encodings”:[{“active”:true,“maxBitrate”:100000,“rid”:“rid-test”,“ssrc”:222222}],“mid”:“1”},“type”:“simple”},“id”:5,“internal”:{“consumerId”:“consumer-test”,“producerId”:“producer-test”,“routerId”:“router-test”,“transportId”:“consume-transport-id”},“method”:“transport.consume”},

mediasoup write message to publisher:
131:{“accepted”:true,“data”:{“paused”:false,“producerPaused”:false,“score”:{“producerScore”:0,“producerScores”:[0],“score”:10}},“id”:5},nsport-id",“mapRtxSsrcConsumerId”:{},“mapSsrcConsumerId”:{},“maxMessageSize”:262144,“producerIds”:[],“recvRtpHeaderExtensions”:{},“rtcpMux”:true,“rtpListener”:{“midTable”:{},“ridTable”:{},“ssrcTable”:{}},“traceEventTypes”:"",“tuple”:{“localIp”:“127.0.0.1”,“localPort”:49342,“protocol”:“udp”}},“id”:4},

When I using commands below to push and pull rtp stream, I failed.
push command:
ffmpeg -re -i test.h264 -vcodec copy -f rtp rtp://127.0.0.1:35195

pull command:
ffmpeg -thread_queue_size 10240 -protocol_whitelist “file,udp,rtp” -i recv_sdp -vcodec copy -y pullVideo.h264

recv_sdp:
v=0
o=urtc-client 1552531492341837152 2 IN IP4 127.0.0.1
s=-
c=IN IP4 127.0.0.1
t=0 0
m=video 19598 RTP/SAVPF 96 97
a=rtpmap:96 H264/90000
a=rtpmap:97 rtx/90000
a=fmtp:97 apt=96
a=rtcp-fb:96 nack
a=setup:active
a=mid:1
a=sendrecv

failed reason:
[udp @ 0x7faea74221c0] bind failed: Address already in use
recv_dsp: Invalid data found when processing input

How should I got rtp stream from mediasoup-worker?Thanks!

I’m not super familiar with the ffmpeg use-case, but I would suggest focusing on the failed reason:
[udp @ 0x7faea74221c0] bind failed: Address already in use

Start by troubleshooting networking issue (see below) and go from there.

Yes, the problem is really here. But the port is obtained by mediasoup, I don’t know which port should I get rtp stream from.

So I think you have mediasoup setup to listen for RTP on both pipetransports. Your push ffmpeg command had a destination set but your pull command does not - presumably it’s setup to listen. So there might be a listen bind conflict between mediasoup and ffmpeg. I would suggest investigating the directionality of your RTP (I’m not too sure how you want this to work).

Thank you! I have solved the problem. I made two mistakes before.
1st: When calling transport.produce, data.rtpParameters.encodings[0] should have field ‘ssrc’, which should be obtained in ffmpeg push command.
2nd: transport.consume’s comedia should be false and then transport.connect ought to be called,which contain the port where mediasoup would send.