Skip to content

Instantly share code, notes, and snippets.

@gregersrygg
Last active July 28, 2020 17:01
Show Gist options
  • Save gregersrygg/4e6fe9878dcc1546da37 to your computer and use it in GitHub Desktop.
Save gregersrygg/4e6fe9878dcc1546da37 to your computer and use it in GitHub Desktop.
Use a Raspberry Pi as a baby monitor

What you need:

  • Raspberry Pi RevB
  • Raspberry Pi NoIR camera

Download raspbian and install to SD-card. Here is a good guide on how to install the .img file to the card: https://www.andrewmunsell.com/blog/getting-started-raspberry-pi-install-raspbian

Connect ethernet or wifi, then boot the Raspberry Pi and follow configuration options. Make sure you enable the camera option.

When you get to the command-line:

bash <(curl -s ...)

Test stuff:

raspivid -o - -t 0 -hf -w 800 -h 400 -fps 24 |cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8160}' :demux=h264 raspivid -o - -t 0 -hf -w 800 -h 400 -fps 24 -n |cvlc -vvv stream:///dev/stdin --sout '#std{access=livehttp{seglen=10,delsegs=true,numsegs=5,index=/usr/share/nginx/www/live/stream.m3u8,index-url=http://10.0.0.3/live/stream-########.ts},mux=ts{use-key-frames},dst=/usr/share/nginx/www/live/stream-########.ts}' :demux=h264

raspivid -w 640 -h 480 -n -o - | ffmpeg -y -i - -codec copy test.mp4

<!DOCTYPE html>
<html>
<head>
<title>NilsCam</title>
<meta name="viewport" content="width=405, initial-scale=1.0, user-scalable=no" />
<style>
html,body { margin: 0; padding: 0; }
@media only screen and (max-width: 320px) {
video {
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
border: 1px solid red;
}
}
</style>
</head>
<body>
<video width="720" height="405" autoplay>
<source src="stream.m3u8" type="application/x-mpegURL" />
</video>
</body>
</html>
#!/bin/bash
sudo su
# Add deb-multimedia for precompiled ffmpeg
# Thanks to http://linuxg.net/how-to-install-the-debian-multimedia-repository-on-debian-operating-systems/
echo "deb http://ftp.sunet.se/pub/os/Linux/distributions/debian-multimedia/ stable main" >> /etc/apt/sources.list
echo "deb-src http://ftp.sunet.se/pub/os/Linux/distributions/debian-multimedia/ stable main" >> /etc/apt/sources.list
wget http://www.deb-multimedia.org/pool/main/d/deb-multimedia-keyring/deb-multimedia-keyring_2012.05.10-dmo4_all.deb -O deb-multimedia-keyring.deb
dpkg -i deb-multimedia-keyring.deb
apt-get update
apt-get upgrade
apt-get install nginx vlc
#echo 'raspivid -o - -w 920 -h 540 -t 0 -n | vlc -v -I "dummy" stream:///dev/stdin :sout="#std{access=livehttp{seglen=10,delsegs=true,numsegs=5, index=/var/www/stream.m3u8, index-url=http://10.0.0.3/stream-########.ts}, mux=ts{use-key-frames}, dst=/var/www/stream-########.ts}" :demux=h264' | sudo tee /usr/local/bin/babymon
#chmod a+x /usr/local/bin/babymon
chown -R pi:pi /var/www
cd /usr/src
sudo su
git clone git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg
./configure
make && make install
#ldconfig
apt-get install nginx
/usr/share/nginx/www/
chown -R pi:pi .
exit
mkdir live
nginx
#!/bin/bash
base="/usr/share/nginx/www/live"
cd $base
raspivid -n -w 720 -h 405 -fps 25 -t 0 -b 1800000 -ih -o - \
| ffmpeg -y \
-i - \
-c:v copy \
-map 0:0 \
-f ssegment \
-segment_time 1 \
-segment_format mpegts \
-segment_list "$base/stream.m3u8" \
-segment_list_size 5 \
-segment_wrap 5 \
-segment_list_flags +live \
-segment_list_type m3u8 \
"%08d.ts"
trap "rm stream.m3u8 *.ts" EXIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment