Jump to content
  • M1GC

Private NGINX/RTMP server live-streaming - Publishing with FFMPEG


M1GC
 Share

Recommended Posts

Publishing with FFMPEG
The easiest way to publish live video streams is by using ffmpeg (or avconv).

It's already installed on most systems and easy to install on others.

RTMP supports only a limited number of codecs.

The most popular RTMP video codecs are H264, Sorenson-H263 (aka flv) and audio codecs AAC, MP3, Nellymoser, Speex.

If your video is encoded with these codecs (the most common pair is H264/AAC) then you do not need any conversion.

Otherwise you need to convert video to one of supported codecs.

We'll stream test file /var/videos/test.mp4 to server with ffmpeg.


Below are some different examples of how to use FFMPEG To Stream Live Video.

Streaming without conversion (given test.mp4 codecs are compatible with RTMP)

ffmpeg -re -i /var/Videos/test.mp4 -c copy -f flv rtmp://localhost/myapp/mystream

Streaming and encoding audio (AAC) and video (H264), need libx264 and libfaac

ffmpeg -re -i /var/Videos/test.mp4 -c:v libx264 -c:a libfaac -ar 44100 -ac 1 -f flv rtmp://localhost/myapp/mystream

Streaming and encoding audio (MP3) and video (H264), need libx264 and libmp3lame

ffmpeg -re -i /var/Videos/test.mp4 -c:v libx264 -c:a libmp3lame -ar 44100 -ac 1 -f flv rtmp://localhost/myapp/mystream

Streaming and encoding audio (Nellymoser) and video (Sorenson H263)

ffmpeg -re -i /var/Videos/test.mp4 -c:v flv -c:a nellymoser -ar 44100 -ac 1 -f flv rtmp://localhost/myapp/mystream

Publishing video from webcam (Linux)

ffmpeg -f video4linux2 -i /dev/video0 -c:v libx264 -an -f flv rtmp://localhost/myapp/mystream

Publishing video from webcam (MacOS)

ffmpeg -f avfoundation -framerate 30 -i "0" -c:v libx264 -an -f flv rtmp://localhost/myapp/mystream

Playing with ffplay

ffplay rtmp://localhost/myapp/mystream

OK NOW LETS  MODIFY OUR CONFIG TO USE FFMPEG TO CONVERT OUR STREAM AND PUBLISH TO OUR PLATFORMS.

Publishing a live stream to Restream.io & Facebook.com using FFMPEG

This config is an example of how we will publish to multi-platforms using FFMPEG...

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application myapp {
            live on;
#FFMPEG COPYING AND SENDING THE STREAM TO LIVEOUT
        exec ffmpeg -re -i "rtmp://127.0.0.1/myapp/YOURSTREAMKEY" -c:v libx264 -crf 0 -c copy -f flv "rtmp://127.0.0.1/liveout/YOURSTREAMKEY";

        }

        application liveout {
            live on;
            record off;

#LIVE OUT RECEIVING THE STREAM FROM ( myapp ) AND SENDING THE COPY OUT TO RESTREAM AND FACEBOOK

#RESTREAM.IO DIRECT
push rtmp://live.restream.io/live/YOUR_STREAM_KEY;

#FACEBOOK DIRECT
push rtmp://live-api-s.facebook.com:80/rtmp/YOUR_STREAM_KEY;


        }
    }
}


Lets explain whats happening in the code above

  • The Live Application (myapp) will import your stream from your streaming software (OBS, XSplit, Wirecast) using ffmpeg.
  • The myapp, will run the stream thru FFMPEG without conversion, using the x264 or x265 encoder, while copying the stream into a .FLV video format file.
  • The .flv file is then sent to the liveout application all in real-time. (liveout),
  • The liveout application (liveout) will receive a copy of your stream, and then pushed / sends your stream to any platform you listed to push too.

That's it. 
ENJOY STREAMING WITH NGINX AND FFMPEG!

  • Thanks 2
Link to comment
Share on other sites

  • M1GC changed the title to Private NGINX/RTMP server live-streaming - Publishing with FFMPEG
  • M1GC locked this topic
Guest
This topic is now closed to further replies.
 Share

  • M1GC

  • Welcome to M1GC

    tenor.gif

    We accept players of all skill levels and help members grow at their own pace.

    We are respectful, determined, and proud to be M1GC members..

  • twitch-logo.gif.6e366685b5d45bf948dad544bc71f521.gif

    Check out M1GC on Twitch

  • Sign up to Restream.io

    M1-Gaming Is Inviting you to Join Restream. The best way to stream video live to 30+ platforms simultaneously for free.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.