Search code examples
linuxgstreamergstreamer-1.0

mixing multiple rtp audio streams with gstreamer


I am trying to mix multiple audio udp rtp packets which created with following command on some other computers, but after a lot of searching I could not find some proper command to mix received audios.

I use this command to stream audio on other computers to my computer:

gst-launch-1.0 autoaudiosrc ! audioconvert ! rtpL24pay ! udpsink host=<MY_COMPUTER_IP> port=<some_port_number>

and I can receive the stream on my computer with this command:

gst-launch-1.0 -v udpsrc port=<port_number> caps="application/x-rtp,channels=(int)2,format=(string)S16LE,media=(string)audio,payload=(int)96,clock-rate=(int)44100,encoding-name=(string)L24" ! rtpL24depay ! audioconvert ! autoaudiosink sync=false

but I want to mix received streams together and play them as one audio in only one pipeline, how can I do that?


Solution

  • To mix two audio streams you can use GStreamer's audiomixer plugin. Very basic example would be:

    Generator of 2 parallel RTP (over UDP) streams with test audios in different frequencies

    gst-launch-1.0 audiotestsrc freq=523 ! audioconvert ! rtpL24pay ! udpsink host=127.0.0.1 port=5000 \
    audiotestsrc freq=659 ! audioconvert ! rtpL24pay ! udpsink host=127.0.0.1 port=5001
    

    Receiver of 2 different RTP (over UDP) streams that mixes 2 audios carried by streams

    gst-launch-1.0 -v udpsrc port=5000 caps="application/x-rtp,channels=(int)2,format=(string)S16LE,media=(string)audio,payload=(int)96,clock-rate=(int)44100,encoding-name=(string)L24" \
    ! queue ! rtpL24depay ! audioconvert ! audiomixer name=mixer ! autoaudiosink \
    udpsrc port=5001 caps="application/x-rtp,channels=(int)2,format=(string)S16LE,media=(string)audio,payload=(int)96,clock-rate=(int)44100,encoding-name=(string)L24" \
    ! queue ! rtpL24depay ! audioconvert ! mixer.