ffmpegvideo-streamingrtsprtsp-server

How to split an incoming stream into multiple streams with different resolutions?


How to split an incoming stream into several streams with different resolutions on the MediaMTX server? There is one incoming stream in rtsp, it needs to be split into several channels with different resolutions. I think in the direction of ffmpeg, but I don't understand how to register this in the mediamtx settings.


Solution

  • Thanks Christoph:

    nano /usr/local/bin/rtsp.sh

    #!/bin/bash
    ffmpeg -use_wallclock_as_timestamps 1 -rtsp_transport tcp -i "rtsp://localhost:8554/mystream" \
    -vf scale=1280:720 -vcodec libx264 -preset:v ultrafast -tune zerolatency -crf 33 -an -rtsp_transport tcp \
    -c:a copy -f rtsp  "rtsp://localhost:8554/mystream720p" &
    
    ffmpeg -use_wallclock_as_timestamps 1 -rtsp_transport tcp -i "rtsp://localhost:8554/mystream" \
    -vf scale=854:480 -vcodec libx264 -preset:v ultrafast -tune zerolatency -crf 33 -an -rtsp_transport tcp \
    -c:a copy -f rtsp  "rtsp://localhost:8554/mystream480p" &
    
    ffmpeg -use_wallclock_as_timestamps 1 -rtsp_transport tcp -i "rtsp://localhost:8554/mystream" \
    -vf scale=640:360 -vcodec libx264 -preset:v ultrafast -tune zerolatency -crf 33 -an -rtsp_transport tcp \
    -c:a copy -f rtsp  "rtsp://localhost:8554/mystream360p"
    

    in mediamtx.yaml

    paths:
      mystream:
         runOnReady: /usr/local/bin/rtsp.sh
         runOnReadyRestart: yes