Uly.me

cloud engineer

  • Home
  • About
  • Archives
Home/Linux/How to Live Stream Using FFmpeg

January 9, 2017

How to Live Stream Using FFmpeg

FFmpeg is a complete cross-platform command-line tool for recording, converting and streaming audio and video files. FFmpeg is widely used for converting files from one format to another. It also used by some to record videos from the screen or camera. It’s also used by others to live stream a recorded file or camera to a RTMP streaming server such as Wowza, YouTube or Facebook Live.

How to record your camera to a video file.

$ ffmpeg -f avfoundation -i "1:0" -t 00:00:15 -s 1280x720 -r 30 -b:v 3500k -b:a 128k out.mpg
$ ffmpeg -f avfoundation -i "2:0" -t 00:00:15 -s 1280x720 -r 30 -b:v 3500k -b:a 128k out.mpg

$ ffmpeg -f avfoundation -i "1:0" -t 00:00:15 -s 1280x720 -r 30 -b:v 3500k -b:a 128k out.mpg $ ffmpeg -f avfoundation -i "2:0" -t 00:00:15 -s 1280x720 -r 30 -b:v 3500k -b:a 128k out.mpg

-i = “video:audio”
-t = duration
-r = fps
-b:v = video bitrate
-b:a = audio bitrate

How to stream a video file to a RTMP server

$ ffmpeg -re -i input.mp4 -vcodec libx264 -preset veryfast -maxrate 1500k 
  -c:a aac -b:a 128k -ac 2 -ar 44100 -f flv rtmp://yourserver:1935/live/mystream

$ ffmpeg -re -i input.mp4 -vcodec libx264 -preset veryfast -maxrate 1500k -c:a aac -b:a 128k -ac 2 -ar 44100 -f flv rtmp://yourserver:1935/live/mystream

How to live stream your screen monitor to a RTMP server

$ ffmpeg -f avfoundation -i "2:0" -vcodec libx264 -preset ultrafast 
  -pix_fmt yuv420p -s 1280x720 -r 30 -b:v 1500k -bufsize 1500k -maxrate 7000k 
  -c:a aac -b:a 128k -ac 2 -ar 44100 -f flv rtmp://yourserver:1935/live/mystream

$ ffmpeg -f avfoundation -i "2:0" -vcodec libx264 -preset ultrafast -pix_fmt yuv420p -s 1280x720 -r 30 -b:v 1500k -bufsize 1500k -maxrate 7000k -c:a aac -b:a 128k -ac 2 -ar 44100 -f flv rtmp://yourserver:1935/live/mystream

How to stream your camera to a RTMP server

$ ffmpeg -f avfoundation -i "1:0" -vcodec libx264 -preset ultrafast 
  -pix_fmt yuv420p -s 1280x720 -r 30 -b:v 1500k -bufsize 1500k -maxrate 7000k 
  -c:a aac -b:a 128k -ac 2 -ar 44100 -f flv rtmp://yourserver:1935/live/mystream

$ ffmpeg -f avfoundation -i "1:0" -vcodec libx264 -preset ultrafast -pix_fmt yuv420p -s 1280x720 -r 30 -b:v 1500k -bufsize 1500k -maxrate 7000k -c:a aac -b:a 128k -ac 2 -ar 44100 -f flv rtmp://yourserver:1935/live/mystream

To learn details of FFmpeg options, read the documentation.

If you need assistance with the install, please see my previous post.

Filed Under: Linux Tagged With: ffmpeg, rtmp, streaming

Content delivered to your email

About Me

I'm Ulysses, a Cloud Engineer at Cardinal Health based in Columbus, Ohio. I’m a certified AWS Solutions Architect. This website is my way of documenting the things I have learned in the Cloud. When off the grid, I enjoy riding my electric skateboard. I have surfed, snowboarded and played the saxophone in the past. I hope you will find this site helpful. It's powered by WordPress and hosted in AWS LightSail.

  • Cloud
  • Linux
  • Git

Copyright © 2012–2021