Skip to content

Instantly share code, notes, and snippets.

@ryankrage77
Created May 8, 2022 12:48
Show Gist options
  • Save ryankrage77/d1d38467bcf4360da4e33233326390af to your computer and use it in GitHub Desktop.
Save ryankrage77/d1d38467bcf4360da4e33233326390af to your computer and use it in GitHub Desktop.
raspivid stream to RTMP server with ffmpeg
raspivid -t 0 -o - -b 2500000 --profile high --level 4.2 -md 4 -fps 25 -br 60 -fli 50hz -n | ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16l e -f s16le -ac 2 -i /dev/zero -f h264 -i - -vcodec copy -acodec aac -ab 128k -f flv rtmp://[your RTMP server]:[port]/live/streamkey
#RASPIVID OPTIONS
#-t 0
#run forever. change 0 to a time in milliseconds to only stream for a limited time.
#-o -
#output to stdout
#-b 2500000
#bitrate in bits/s. Shouldn't need to go above 6mbps.
#--profile high --level 4.2
#encoding profile. Not 100% sure what this does, but it improves the image quality a bit
#-md 4
#sets the raspi camera mode. mode 4 should use the whole sensor & bin down for lower resolutions, but it doesn't seem to work. left in as it doesn't hurt.
#-fps 25
#framerate, maximum 30fps.
#-br 60
#set the brightness, 0-100. Useful for static dark scenes.
#-fli 50hz
#reduces flicker from lights running at 50Hz. Can also be set to 60Hz.
#-n
#don't show a preview window.
#FFMPEG OPTIONS
#-re -ar 44100 -ac 2 -acodec pcm_s16l e -f s16le -ac 2 -i /dev/zero
#create a dummy audio stream from /dev/zero. Some RTMP servers require audio.
#-i -
#read from stdin? (I don't know much about stdout/stdin). You could replace the - with a pre-recorded h264 file.
#-vcodec copy
#just copy the video stream, don't re-encode it
#-acodec aac
#encode audio in aac format
#-ab 128k
#audio bitrate
#-f flv
#output format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment