Created
April 27, 2020 20:49
-
-
Save RedBlaze42/43eac4c232385d90ebd59ef98c28becc to your computer and use it in GitHub Desktop.
Streaming from a Pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import random | |
path="music/" | |
files = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))] | |
print("Nombre de musiques: {}".format(len(files))) | |
random.shuffle(files) | |
data="\n".join(["file '{}{}'".format(path,file) for file in files]) | |
with open("list.txt","w") as concat_file: | |
concat_file.write(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ================================================================= | |
# Stream configuration file for Raspberry Pi Camera | |
# | |
# @author Russell Feldhausen (russfeldh@gmail.com) | |
# @version 2019-06-05 | |
# Modified by RedBlaze42 | |
# This set of commands should allow you to stream video from your | |
# Raspberry Pi Camera to Twitch and Youtube (and possibly other | |
# RTMP endpoints) with decent quality and performance. | |
# | |
# You may need to install raspivid and/or ffmpeg to use this script. | |
# | |
# This was tested and built on Raspbian 9 installed using Noobs | |
# ================================================================= | |
# Set width and height of output video | |
WIDTH=1296 | |
HEIGHT=972 | |
# Set output framerate | |
FRAMERATE=30 | |
# Set keyframe spacing (must be double the framerate) | |
KEYFRAME=60 | |
# Set bitrate (Twitch recommends 3500000) | |
BITRATE=3000000 | |
# Set stream URL | |
URL=GOOGLE "TWITCH STREAM SERVER URL" | |
# Set stream key | |
KEY=YOUR KEY | |
# Command | |
while : | |
do | |
python3 shuffle.py | |
raspivid -n -t 0 --sharpness 0 -a 8 -ae 32,0xff,0x808000 -a "Bird Cam twitch.tv/redblaze %d/%m %X" -w $WIDTH -h $HEIGHT -fps $FRAMERATE -b $BITRATE -g $KEYFRAME -o - | ffmpeg -f lavfi -i anullsrc -f concat -i list.txt -c:a aac -r $FRAMERATE -i - -g $KEYFRAME -strict experimental -threads 4 -vcodec copy -t 24:00:00 -filter:a "volume=-19dB" -map 1:a -map 2:v -b:v $BITRATE -preset fast -r $FRAMERATE -f flv "${URL}/${KEY}" | |
sleep 60 | |
done | |
#sudo shutdown -r +2 | |
# ================================================================= | |
# Full Documentation of Command Options | |
# | |
# +++ raspivid +++ | |
# -n = no preview window | |
# -t = time to capture (0 to disable, which allows streaming) | |
# -w = video width | |
# -h = video height | |
# -fps = output framerate (max 30 for 1080p, 60 for 720p) | |
# -b = bitrate | |
# -g = keyframe rate (refresh period) | |
# -o - = output to stdout (allows piping to ffmpeg) | |
# | |
# +++ ffmpeg +++ | |
# -f lavfi = use lavfi filter (see note below) | |
# -i anullsrc = grab blank input (see note below) | |
# -c:a aac = set audio codec to aac | |
# -r = output framerate (should match raspivid framerate) | |
# -i - = read input from stdin (piped from ffmpeg) | |
# -g = keyframe rate (refresh period) | |
# -strict experimental = allow nonstandard things | |
# -threads 4 = set number of encoding threads to 4 (# of cores) | |
# -vcodec copy = use video as-is (do not re-encode video) | |
# -map 0:a = use the audio from input 0 (see note below) | |
# -map 1:v = use the video from input 1 (raspivid) | |
# -b:v = bitrate | |
# -preset ultrafast = use the ultrafast encoding preset | |
# -f flv = set output format to flv for streaming | |
# "${URL}/{KEY}" = specify RTMP URL as output for stream | |
# | |
# ** NOTE ** | |
# According to some information online, YouTube will reject a live | |
# stream without an audio channel. So, in the ffmpeg command above | |
# a blank audio channel is included. It was not required for Twitch | |
# in my testing. | |
# ================================================================= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment