Skip to content
Snippets Groups Projects
Commit aaebaa54 authored by Nicolas Pernoud's avatar Nicolas Pernoud
Browse files

feat: calc bitrate according to connection speed

parent 756a468b
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,8 @@ A simple script to turn an headless raspberry pi 4 (with a **good** microphone)
## Setup
Install speedtest-cli : `sudo apt install speedtest-cli`.
Set up the pi to boot in logged in (pi user) console mode with `sudo raspi-config`.
Copy the **start_stream.sh** script into `/home/pi` and make it executable with `chmod +x ./start_stream.sh`.
......
#!/bin/sh
KEY="***PUT YOUR YOUTUBE API KEY HERE***"
sleep 30 # Allow time for the raspberry pi to boot
# Wait for the network to be up
while [ $(cat /sys/class/net/wlan0/operstate) != "up" ]; do
echo "Wifi is down. Waiting..."
sleep 5
done
# Get the upload speed
UPLOAD_SPEED=$(speedtest --csv --no-download | cut -d ',' -f8 | cut -d '.' -f1)
# Take half the speed for bitrate
BITRATE="$(($UPLOAD_SPEED / 2))"
echo "STREAM BOX STARTED - Press [CTRL+C] to stop..."
echo "Bitrate is ${BITRATE}"
while true; do
#Pipe to ffmpeg
......@@ -12,12 +21,14 @@ while true; do
#Audio options
#Video options
#Push to youtube
raspivid -n -o - -t 0 -hf -fps 25 -b 6000000 | ffmpeg -re \
-thread_queue_size 8192 \
-f alsa -i plughw:1,0 \
-thread_queue_size 8192 \
-f h264 -i - -r 25 \
-ac 1 -acodec libmp3lame -ar 44100 -b:a 128k \
-vcodec copy \
-g 50 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/$KEY
raspivid --nopreview --output - -t 0 \
-w 1280 -h 720 -fps 25 -b ${BITRATE} |
ffmpeg -re \
-thread_queue_size 65536 \
-f alsa -i plughw:1,0 \
-thread_queue_size 65536 \
-f h264 -i - -r 25 \
-ac 1 -acodec libmp3lame -ar 44100 -b:a 128k \
-vcodec copy \
-strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/$KEY
done
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment