https://github.com/cmenon12/birdbox-livestream
Collection of Python scripts designed for livestreaming a birdbox from a Raspberry Pi to YouTube!
https://github.com/cmenon12/birdbox-livestream
birdbox livestream pi python raspberry-pi youtube
Last synced: 10 months ago
JSON representation
Collection of Python scripts designed for livestreaming a birdbox from a Raspberry Pi to YouTube!
- Host: GitHub
- URL: https://github.com/cmenon12/birdbox-livestream
- Owner: cmenon12
- License: gpl-3.0
- Created: 2021-12-28T14:42:03.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-08-23T02:20:33.000Z (10 months ago)
- Last Synced: 2025-08-23T04:23:13.864Z (10 months ago)
- Topics: birdbox, livestream, pi, python, raspberry-pi, youtube
- Language: Python
- Homepage: https://www.youtube.com/channel/UCikUXkTwFvyrHlajBRQwvuw/
- Size: 4.74 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# birdbox-livestream
This is a small collection of Python scripts designed for livestreaming a birdbox from a Raspberry Pi to YouTube!
### **[Check out the channel on YouTube!](https://www.youtube.com/channel/UCikUXkTwFvyrHlajBRQwvuw)**
**(unfortunately no birds have shown up yet 😢)**
[
](https://www.youtube.com/channel/UCikUXkTwFvyrHlajBRQwvuw)
[](https://github.com/cmenon12/birdbox-livestream/blob/master/LICENSE)
## The Python Scripts
#### [`yt_livestream.py`](yt_livestream.py)
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.
#### [`motion_detection.py`](motion_detection.py)
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.
#### [`yt_cleanup.py`](yt_cleanup.py)
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](https://developers.google.com/youtube/v3/getting-started#quota) using this tool.
#### [`reauth_token.py`](reauth_token.py)
This is just used to force a reauthorisation with the YouTube API and generate a brand-new refresh token.
## Other Scripts
#### [`stream.sh`](stream.sh)
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](https://choosealicense.com/licenses/gpl-3.0/)
[Nest icon created by iconixar - Flaticon.](https://www.flaticon.com/free-icons/nest) [CCTV icon created by Freepik - Flaticon.](https://www.flaticon.com/free-icons/cctv)