Streaming to multiple RTMP servers with ffmpeg with minimal resources

16,417
ffmpeg -listen 1 -i rtmp://127.0.0.1:5555 -c copy -f flv rtmp://twitch -c:v libx264 -preset medium -maxrate 3500k -bufsize 6000k -r 30 -pix_fmt yuv420p -g 60 -c:a aac -b:a 160k -ac 2 -ar 44100 -f flv rtmp//:facebook
  • Don't use -re with live input streams. Documentation says that it may cause packet loss.

  • I changed -g 50 to -g 60 to better fit your 30 fps.

  • See the fifo muxer if you want to add options to attempt to recover the output in case of failure.

Share:
16,417

Related videos on Youtube

Dustin
Author by

Dustin

Updated on September 18, 2022

Comments

  • Dustin
    Dustin over 1 year

    Using OBS and ffmpeg, I'm attempting to stream to both Facebook and Twitch at the same time. My current setup works, however the issue is it's a tad resource hungry.

    FACEBOOK_KEY="123?ds=1\&s_l=1\&a=ggnore"
    TWITCH_KEY="live_123_aBcEdFg"
    
    ARGS="-c:v libx264 -preset medium -maxrate 3500k -bufsize 6000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 160k -ac 2 -ar 44100 -f flv"
    
    CMD="ffmpeg -re -listen 1 -i rtmp://127.0.0.1:5555"
    CMD="$CMD $ARGS rtmp://live.twitch.tv/app/$TWITCH_KEY"
    CMD="$CMD -r 30 $ARGS rtmp://rtmp-api.facebook.com:80/rtmp/$FACEBOOK_KEY"
    
    eval $CMD
    

    OBS settings are straight forward:

    Video: 720p, 2500k bitrate, x264 encoding, 60FPS

    Audio: 160k AAC.

    I have two goals I'm trying to accomplish with the setup.

    1. For Twitch, ffmpeg should simply just be copying the source stream from OBS to Twitch without any conversion, as Twitch accepts what I'm passing from OBS.
    2. For Facebook, it should convert the FPS from 60 to 30, again with the minimal resource usage as Facebook accepts everything coming from OBS other then the FPS.
  • Dustin
    Dustin almost 7 years
    Fantastic! Thanks. Would you do anything else to the Facebook stream to reduce CPU usage? Anything you feel isn't needed?
  • Elisa Cha Cha
    Elisa Cha Cha almost 7 years
    @Dustin Output 30 fps from OBS and then feed that to both Facebook and Twitch without re-encoding.