Search code examples
streamstreamingvideo-streamingrtmphttp-live-streaming

Single RTMP to adaptative streaming with a free media server and control panel


this is what i am doing right now:

i'm sending a live tv channel with a teradek vidiu that sends the video via RTMP to an AWS EC2 instance with nimble streamer server, configured months ago with wmspanel (in the trial period). The nimble server transcode the rtmp and gives me an HLS (m3u8) that i play in the webpage with peer5 (jwplayer). The problem with this is that the live video is only in HD and the clients with low speed connections can't see the video, or sometimes it stutter.

What i want:

I want an adaptative stream that everybody can connect to, low speed see a lower bitrate video, and high speed see an HD video. I know i can do this with servers like wowza and others, the problem is the price, i would like a free server with free control panel. Nimble server is free but wmspanel is not, and now i can't change or do anything to nimble because the trial period on wmspanel is over!.

Please help me with this!


Solution

  • Everything you're asking can be done with nginx, the nginx-rtmp module and ffmpeg, all free software. I have a setup similar to yours (BlackMagic H264 Pro instead of Teradek, but otherwise the same) transmitting a couple of TV channels.

    The only issue is that you would need to compile nginx yourself with the rtmp module and if you need a control panel of some kind, you'd have to write it yourself.

    My setup works like this:

    1.- BM H264 Pro on local server connected to the live switcher sends an HD stream to an EC2 instance with Fedora 23.

    2.- Nginx-rtmp takes the input and invokes ffmpeg to create six different HLS live streams (180p,240p,360p,480p,720p,1080p) which are then served through CloudFront CDN to ensure speed.

    It works really well and I haven't had any issues, CloudFront picks up the streams directly from the EC2 instance and the speed is amazing. You do need a rather powerful instance (I use an m4.4xlarge) for the parallel encoding.

    With PHP (or any other language actually, I just like PHP for this) you can have a control panel and other niceties. For example, I track all views, pauses, do some geoIP and other metrics with this setup.

    --------Update August 04--------

    Here's my conf file for nginx:

    application live-video {
      access_log              /webdata/logs/access/publish.log;
      live                    on;
      record                  all;
      wait_key                on;
      record_path             /webdata/batch/video;
      record_unique           on;
      drop_idle_publisher     2s;
      interleave              on;
      allow play              all;
      allow publish           all;
      notify_method           get;
      exec_push               /usr/bin/ffmpeg -y -re -i rtmp://localhost:1935/live-video/$name -keyint_min 30 -x264opts "keyint=30:min-keyint=30:no-scenecut" -g 30 -r:v 30 -s 320x180 -b:v 256k -c:v libx264 -preset ultrafast -pix_fmt yuv420p -profile:v baseline -level 3.0 -c:a libfaac -ac 1 -ar 48000 -b:a 96k -f flv rtmp://localhost:1935/stream-video/240p -keyint_min 30 -x264opts "keyint=30:min-keyint=30:no-scenecut" -g 30 -r:v 30 -s 640x360 -b:v 512k -c:v libx264 -preset ultrafast -pix_fmt yuv420p -profile:v baseline -level 3.0 -c:a libfaac -ac 1 -ar 48000 -b:a 96k -f flv rtmp://localhost:1935/stream-video/360p -keyint_min 30 -x264opts "keyint=30:min-keyint=30:no-scenecut" -g 30 -r:v 30 -s 854x480 -b:v 1024k -c:v libx264 -preset ultrafast -pix_fmt yuv420p -profile:v baseline -level 3.0 -c:a libfaac -ac 1 -ar 48000 -b:a 96k -f flv rtmp://localhost:1935/stream-video/480p -c:a libfaac -ac 1 -ar 48000 -b:a 64k -f flv rtmp://localhost:1935/stream-video/aacp;
      access_log              off;
    }
    
    application stream-video {
      live                    on;
      access_log              /webdata/logs/access/stream-video.log;
      hls                     on;
      hls_fragment            10s;
      hls_playlist_length     5m;
      hls_path                /webdata/html/live/video;
    }
    

    The live stream is published to rtmp://server:1935/live-video/stream?token=TOK; this calls up ffmpeg for on-the-fly transcoding to four qualities and publishes it to the "stream-video" app. So, you publish to "live-video" and your users watch "stream-video".