Compare commits

...

3 Commits

7 changed files with 104 additions and 9 deletions

View File

@ -28,6 +28,10 @@ SetupHistory () {
echo "${HISTORY_SETUP}" | sqlite3 "${HISTORY}"
}
WipeHistory () {
rm -f "${HISTORY}"
}
SetupPlayback () {
echo "${PLAYBACK_SETUP}" | sqlite3 "${PLAYBACK}"
}
@ -36,10 +40,20 @@ WipePlayback () {
rm -f "${PLAYBACK}"
}
GetRandom () {
QUERY="SELECT video FROM playback ORDER BY RANDOM() LIMIT 1;"
sqlite3 "${HISTORY}" "${QUERY}"
}
UpdateHistory () {
QUERY="INSERT INTO"
}
PDB () {
sqlite3 "${PLAYBACK}" "${1}"
}
HDB () {
sqlite3 "${HISTORY}" "${1}"
}
}

View File

@ -11,21 +11,34 @@ if [ ${count} == 0 ]; then
exit 1
fi
SCALE="scale=${WIDTH}:${HEIGHT}:force_original_aspect_ratio=decrease,pad=${WIDTH}:${HEIGHT}:(ow-iw)/2:(oh-ih)/2"
SCALE="-filter_complex scale=${WIDTH}:${HEIGHT}:force_original_aspect_ratio=decrease,pad=${WIDTH}:${HEIGHT}:(ow-iw)/2:(oh-ih)/2"
HWENCODE="-hwaccel auto"
SILENT="-loglevel quiet -stats"
if [[ "${BUG}" != "" ]]; then
SCALE="-i ${BUG} -filter_complex [0]scale=${WIDTH}:${HEIGHT}:force_original_aspect_ratio=decrease,pad=${WIDTH}:${HEIGHT}:(ow-iw)/2:(oh-ih)/2,overlay=x=0:y=0[out] -map [out]"
fi
Encode () {
name=$(basename "${1}")
nameNoExt=${name%.*}
now=$(date '+%s')
output="${VIDEOS}/${nameNoExt}_${now}.flv"
if [ -f "${VIDEOS}/${nameNoExt}"*".flv" ]; then
output="${VIDEOS}/${nameNoExt}_${now}.mkv"
#echo $output
if [ -f "${VIDEOS}/${nameNoExt}"*".mkv" ]; then
echo "File ${name} already exists"
return
fi
echo "Encoding ${name}..."
ffmpeg -i "${1}" -c:v libx264 -tune zerolatency -pix_fmt yuv420p -vf "${SCALE}" \
-c:a aac -b:a 190k -ac 2 -ar 44100 \
-f flv "${output}"
if [[ "${name}" == *".jpg" ]] || [[ "${name}" == *".jpeg" ]] || [[ "${name}" == *".png" ]]; then
ffmpeg -nostdin -loop 1 -t 30 -i "${1}" ${SCALE} -c:v libx264 -tune zerolatency -pix_fmt yuv420p -r 30 -t 30 \
-an ${SILENT} \
"${output}"
else
ffmpeg -nostdin ${HWENCODE} -i "${1}" ${SCALE} -c:v libx264 -tune zerolatency -pix_fmt yuv420p \
-c:a aac -b:a 190k -ac 2 -ar 44100 \
-f flv ${SILENT} "${output}"
fi
}
fileList=$(mktemp)

21
nginx-rtmp.conf Normal file
View File

@ -0,0 +1,21 @@
rtmp {
server {
listen 1935;
application live {
# Enable livestreaming
live on;
# Disable recording
record off;
# Allow only this machine to play back the stream
allow play 127.0.0.1;
deny play all;
# Start omxplayer and play the stream out over HDMI
#exec /home/pi/stream.sh $name;
}
}
}

22
playlist.sh Normal file
View File

@ -0,0 +1,22 @@
#!/bin/bash
set -e
source ./common.sh
fileList=$(mktemp)
shuffleList=$(mktemp)
ls -1 "${VIDEOS}/" > "${fileList}"
rm -rf playlist.txt
count=10
for i in $(seq $count); do
cat "${fileList}" | shuf > "${shuffleList}"
while read videoIn; do
echo "file '${VIDEOS}/${videoIn}'" >> playlist.txt
done < "${shuffleList}"
done
rm -f "${fileList}"
rm -f "${shuffleList}"

14
setup_raspi.sh Normal file
View File

@ -0,0 +1,14 @@
#!/bin/bash
################################################
#
# Works with 2020-02-13-raspbian-buster-lite.zip
#
################################################
sudo apt update -y
sudo apt upgrade -y
sudo apt install -y git curl omxplayer nginx libnginx-mod-rtmp
sudo apt autoremove
sudo cat ./nginx-rtmp.conf >> /etc/nginx/nginx.conf

7
stream.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
set -e
source ./common.sh
ffmpeg -re -f concat -safe 0 -stream_loop -1 -i playlist.txt -c copy -f flv "${DESTINATION}"

8
tv.sh
View File

@ -26,7 +26,6 @@ AllFiles () {
echo "${fileList}"
}
SetupHistory
WipePlayback
SetupPlayback
@ -37,11 +36,16 @@ while true; do
files=$(AllFiles)
fileCount=$(cat "${files}" | wc -l)
playbackCount=$(PDB "SELECT COUNT(*) FROM playback")
if [ ${fileCount} -eq 0 ]; then
echo "No files to play :("
break
fi
if [ ${playbackCount} -eq 0 ]; then
WipeHistory
SetupHistory
continue
fi
break
done