MetaCDN - StreamShark

How to Live Stream Using FFmpeg

Overview

StreamShark's Live Streaming product is compatible with FFmpeg. Let's outline the steps required to get you streaming your live event with FFmpeg and StreamShark.

FFmpeg (http://www.ffmpeg.org/) is a popular free software utility used for recording, streaming and transcoding multimedia data.  It can be compiled under most operating systems, including Mac OS X, Linux and Windows.  Please refer to the FFmpeg documentation on their website for installation instructions.  Most Linux distributions contain a pre-packaged installation option.

This is an advanced guide and is provided "as-is" by StreamShark.

Broadcasting your live stream with FFmpeg

Below is a working script to publish one live stream using the default video and audio capture device on a Ubuntu machine, you need to adjust the parameters to make it suitable for your capturing devices.

ffmpeg -f alsa -i default -f v4l2 -i /dev/video0 -s 320x240 -ar 11025 -f flv -r 30.0 "rtmp://publish.live.streamshark.io/2050C7/jumbwywy/livestreamdemo_328?mypassword"

The value of rtmp url can be retrieved from StreamShark console. Login to your StreamShark account and go to the live streaming page and choose (or create new) live stream. The rtmp url will be the FMS URL prefix value + / + Stream 1 URL value.

A higher bandwidth example.  ~500kbps, 1280x720@25fps.  Tested using a Logitech webcam and an i7 workstation.  It is a good idea to use the x264 encoder instead of vp6 for most applications - it provides better quality with a lower bitrate.

ffmpeg -re -threads 4 -f alsa -ac 1 -ar 22050 -i hw:2,0 -f v4l2 -vcodec mjpeg -s 1280x720 -r 25 -i /dev/video0 -s 1280x720 -ar 11025 -ac 1 -b:a 32000 -f flv -vcodec libx264 -bufsize 512000 -maxrate 512000 -r 25 <your publish url>

 

Audio only (transcoding using aac encoder libfaac, 256kbit and a mp3 source file)

ffmpeg -re -threads 4 -i ~/Dropbox/MetalBALLZ/Helm\ \(2013\)\ III/06\ -\ Drag\ the\ anchor.mp3 -f flv -ar 44100 -ac 2 -c:a libfaac -b:a 256k <your publish url>

 

The below example sends multiple streams from a webcam (/dev/video0), using the webcam's inbuilt mono mic (hw:2,0 on my pc).  My stream name was 'ffmpeg' and my password was 'trebor'.  The stream was HLS enabled.  The container to use is flash (flv), the encoder is libx264 and the audio encoder is aac (libfaac).

The configuration is matched to our recommended 16:9 stream configuration setting.

Live stream configuration: 

  • Stream 1- 200 kbps, 416 * 234
  • Stream 2- 600 kbps, 640 * 360
  • Stream 3- 1200 kbps, 640 * 360

ffmpeg -re -threads 0 -f alsa -ac 1 -i hw:2,0 -f v4l2 -vcodec mjpeg -s 1280x720 -r 25 -i /dev/video0 \
-s 416x234 -ac 2 -f flv -vcodec libx264 -profile:v baseline -maxrate 200000 -bufsize 200000 -r 25 -ar 44100 -c:a libfaac -b:a 128k "rtmp://publish.live.streamshark.io/2050C7/juidbonc/ffmpeg_200?trebor&adbe-live-event=ffmpeg" \
-s 640x360 -ac 2 -f flv -vcodec libx264 -profile:v baseline -maxrate 600000 -bufsize 600000 -r 25 -ar 44100 -c:a libfaac -b:a 128k "rtmp://publish.live.streamshark.io/2050C7/juidbonc/ffmpeg_600?trebor&adbe-live-event=ffmpeg" \
-s 640x360 -ac 2 -f flv -vcodec libx264 -profile:v baseline -maxrate 1200000 -bufsize 1200000 -r 25 -ar 44100 -c:a libfaac -b:a 128k "rtmp://publish.live.streamshark.io/2050C7/juidbonc/ffmpeg_1200?trebor&adbe-live-event=ffmpeg"

Have more questions? Submit a request