Skip to content

Raspberry pi stream to RTMP server. I'm personally using this for for a camera in a birdhouse in my backyard to send a video stream to myearthcam.com

Notifications You must be signed in to change notification settings

jcksnvllxr80/pi_to_rtmp_stream

Repository files navigation

pi_to_rtmp_stream

Image of Stream

alt text

About

  • To use raspberry pi to stream rtmp to (youtube/earthcam) as well as simultaneously taking pictures for a timelapse. I am using this for the birdhouse in my back yard.
  • there are two parts to this application
    1. start the stream and open a socket for a local device to connect and get the video stream
    2. connect to the network stream and send it to the rtmp endpoint using ffmpeg (usage shown below)

  

Installation

(from raspberry pi terminal)

cd /home/pi
git clone https://github.com/jcksnvllxr80/pi_to_rtmp_stream.git
sudo systemctl enable /home/pi/pi_to_rtmp_stream/rtmp_stream.service
sudo systemctl daemon-reload

  

Configuration

Modify the stream.yaml file in the 'pi_to_rtmp_stream/conf' directory to fit your needs

timelapse:
  relative_dir: timelapse
  state: True
  interval: 60
  label_fmt: '%Y%m%d%H%M'
video:
  resolution: (1640, 1232)
  framerate: 24
connection:
  listen_port: 9090

NOTE: if the timelapse relative_dir is changed in the yaml config, make sure to also change it in the pi_to_rtmp.sh where the directory is created if it doesnt already exist.

  

Starting / Stopping / Restarting /Status the Stream

sudo systemctl start rtmp_stream  # start the stream
sudo systemctl stop rtmp_stream  # stop the stream
sudo systemctl restart rtmp_stream  # restart the stream
sudo systemctl status rtmp_stream  # restart the stream

NOTE: the stream will auttomatically start on boot when enabled as a service (line: 3 under the installation instrucitons)

  

Disabling the Streaming Service

sudo systemctl disable rtmp_stream

  

Running as non-service standalone

!! make sure the service is stopped and disabled before running this command

/home/pi/pi_to_rtmp_stream/pi_to_rtmp.sh

NOTE: cntl+c quits the running application when ran from terminal manually as desribed in this subsection (i.e. not as a service)

  

Sending the Stream to Youtube/EarthCam

// from command line

ffmpeg -i 'tcp://localhost:9090?fifo_size=6000000&overrun_nonfatal=1' -crf 30 -preset ultrafast -acodec aac -ar 44100 -ac 2 -b:a 96k -vcodec libx264 -r 25 -b:v 500k -f flv 'rtmp://mia05.contribute.live-video.net/app/<secret_key>'

// with python

cmdline = [
  'ffmpeg',
  '-i',
  'tcp://localhost:9090?fifo_size=6000000&overrun_nonfatal=1',
  '-crf',
  '30',
  '-preset',
  'ultrafast',
  '-acodec',
  'aac',
  '-ar',
  '44100',
  '-ac',
  '2',
  '-b:a',
  '96k',
  '-vcodec',
  'libx264',
  '-r',
  '25',
  '-b:v',
  '500k',
  '-f',
  'flv',
  'rtmp://mia05.contribute.live-video.net/app/<secret_key>'
]
player = subprocess.Popen(cmdline, stdin=subprocess.PIPE) 

// as a service

  • i have provided an example service, 'transmit_stream', that can be used in the same manner as the 'rtmp_stream' service described above

About

Raspberry pi stream to RTMP server. I'm personally using this for for a camera in a birdhouse in my backyard to send a video stream to myearthcam.com

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published