Skip to content

Collection of Python scripts designed for livestreaming a birdbox from a Raspberry Pi to YouTube!

License

Notifications You must be signed in to change notification settings

cmenon12/birdbox-livestream

Repository files navigation

Logo cartoon of birdbox with CCTV inside

birdbox-livestream

This is a small collection of Python scripts designed for livestreaming a birdbox from a Raspberry Pi to YouTube!

(unfortunately no birds have shown up yet 😢)

Photo of wooden birdbox on a red brick wall with a CCTV warning on the side

GitHub license

The Python Scripts

This script has the livestreaming capability. When run directly, it connects to the YouTube API and creates a livestream with a RTMP URL. Once it detects that you've started sending data to the livestream, it schedules broadcasts for every six hours. These have complete titles, descriptions, tags, etc., and are arranged into weekly playlists. Each broadcast is started & stopped on schedule.

The YouTube class manages the connection to the API. The YouTubeLivestream class inherits YouTube, and provides the full livestreaming functionality. This separation allows other scripts to use the YouTube API without directly managing any livestreams.

This runs indefinitely, and will send an email if any errors occur. Fluctuations in your internet connection (e.g. those that might cause some sort of IOError) are handled with a delay & retry.

This script performs motion detection on the completed broadcasts. Once a broadcast completes (new broadcasts are polled for regularly) it's downloaded in 144p, motion detection is run on it, and the result is appended to the video's title & description. If any motion is detected, the timestamps are added to the description and emailed to the user.

This script relies on yt_livestream.py for connecting to the YouTube API and sending error emails.

This script is used to clean up old videos and weekly playlists, either by deleting them or making them private. It can clean up a subset of them between two specified dates. Be careful not to exceed the daily YouTube API quota using this tool.

This is just used to force a reauthorisation with the YouTube API and generate a brand-new refresh token.

Other Scripts

This little bash script runs the livestreaming. It asks for the RTMP URL, and then starts capturing video with raspivid, piping that into ffmpeg where it's combined with an audio file and output to the RTMP URL. If the command exits for any reason (e.g. some sort of IO error because the internet drops) it restarts after 30 seconds.

License & Attributions

GNU GPLv3

Nest icon created by iconixar - Flaticon. CCTV icon created by Freepik - Flaticon.