Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
raspberry pi livestream to YouTubeLive
/boot/run.sh
/boot/youtube.sh
/etc/rc.local
additional line to /etc/fstab
# Add this line to /etc/fstab
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
package main
import (
"fmt"
"log"
"time"
"github.com/tetsu-koba/go-i2c"
)
const (
// values for calibration
x0 = -189
y0 = 14
z0 = 186
)
// Read acceleration sensor ADXL345 and write 0, 90, 180 or 270 to stdout.
func main() {
i2c, err := i2c.NewI2C(0x53, 1)
if err != nil {
log.Fatal(err)
}
defer i2c.Close()
/* start measuring */
err = i2c.WriteRegU8(0x2d, 0x08)
if err != nil {
log.Fatal(err)
}
time.Sleep(200 * time.Millisecond)
x, err := i2c.ReadRegS16LE(0x32)
if err != nil {
log.Fatal(err)
}
y, err := i2c.ReadRegS16LE(0x34)
if err != nil {
log.Fatal(err)
}
z, err := i2c.ReadRegS16LE(0x36)
if err != nil {
log.Fatal(err)
}
a := angle(int(x - x0), int(y - y0), int(z -z0))
fmt.Printf("%d\n", a)
}
func angle(x, y, z int) int {
if iabs(x) > iabs(z) && iabs(x) > iabs(y) {
if x > 0 {
return 90
} else {
return 270
}
}
if iabs(y) > iabs(z) && iabs(y) > iabs(x) {
if y > 0 {
return 180
} else {
return 0
}
}
return 270
}
func iabs(x int) int {
if x > 0 {
return x
} else {
return -x
}
}
#!/bin/sh -e
#[ -x /boot/run.sh ] && (cd /boot; ./run.sh 2>&1 > /tmp/run.sh.log) &
[ -x /boot/run.sh ] && (cd /boot; ./run.sh ) &
exit 0
#!/bin/sh
green_led=/sys/class/leds/led0
led_green_ok(){
echo timer > $green_led/trigger
# pi zero seems to swap on and off
echo 3000 > $green_led/delay_off
echo 200 > $green_led/delay_on
}
led_green_error(){
echo timer > $green_led/trigger
echo 50 > $green_led/delay_on
echo 50 > $green_led/delay_off
}
mount -o remount,ro /
mount -o remount,ro /boot
while true; do
led_green_ok
./youtube.sh
led_green_error
sleep 10
done
#!/bin/sh
STREAM_KEY=your_stream_key
AFIFO=/tmp/afifo.$$
ping -c 5 a.rtmp.youtube.com || exit $?
rm -f $AFIFO
mkfifo $AFIFO
ROT=`/home/pi/axd`
raspivid -o - -t 0 -rot $ROT -fps 30 -b 4500000 | \
ffmpeg -loglevel warning -re -f aac -i $AFIFO -r 30 -f h264 \
-i - -vcodec copy -acodec copy -bsf:a aac_adtstoasc \
-f flv rtmp://a.rtmp.youtube.com/live2/$STREAM_KEY &
while true; do
cat /boot/audio/*.aac
done >> $AFIFO
#!/bin/sh
STREAM_KEY=your_stream_key
ping -c 5 a.rtmp.youtube.com || exit $?
raspivid -o - -t 0 -rot 270 -fps 30 -b 4500000 | \
ffmpeg -re \
-ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero \
-r 30 -f h264 -i - -vcodec copy -acodec aac -ab 128k \
-f flv rtmp://a.rtmp.youtube.com/live2/$STREAM_KEY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.