quotes-rss (Videos from RSS-Feeds)

Der Anstoss für dieses RPiOS-Projekt kam von Adafruit Quotes, das ist mehr ein Demo-Projekt für diverse Apps und Geräte. Eine deutsche Variante musste her, und auch ein bisschen strukturierter, da ich Zitat und Autor getrennt haben wollte, um gestaltungstechnisch mehr Möglichkeiten zu haben. Und ich wollte Video_looper verwenden, um die Videos automatisch abzuspielen.
Mein Feed liegt hier:http://cargologo.com/feed/quotes/data_rss.xml. Und er lässt sich auch in einen RSS-Viewer einfügen, wie NetNewsWire oder Vienna.
Das Skript lädt den Feed runter, wählt einen Eintrag zufällig aus und erstellt ein Video (anhand eines Hintergrund-Videos und einer Schrift, siehe Assets-Folder). Das Hintergrund-Video (input.mp4) bestimmt die Länge und die Bild-Grösse der erstellten Video-Datei und es könnte auch Bild-Elemente beinhalten. Meine Testumgebung hier ist das ArgonPod-Video-Case mit RPi Zero 2, der ganz gut kleine FFMPEG-Aufgaben erledigen kann, im Gegensatz zum RPi Zero 1. Die Bildschirmgrösse und die Videobildgrösse hier ist 640×480, durch entsprechende Einstellungen bei FFMPEG kann man auch HD-Videos für andere Ausgabegeräte erstellen.
Extension: mit dem Command-Argument ./quotes-rss latest kann man den letzten Eintrag forciert anzeigen lassen.
BTW: jeder andere Feed, der title- und description-entries enthält, geht natürlich auch.


#!/bin/bash
# Usage: ./quotes-rss.sh [latest]

# Home Dir
cd /home/pi/quotes-rss/

# Delete old file
#rm ./data_rss.xml* 2> /dev/null

# Download the latest quotes file
wget http://cargologo.com/feed/quotes/data_rss.xml

# Clean up old videos in video_looper Master Dir
#rm /home/pi/video/*_output.mp4 2> /dev/null

# -- Variables
newstimescreen=$(date '+%A %H-%M')
newstimefile=$(date '+%H%M%S')
modificationtime=$(stat ./data_rss.xml | grep "Modify" | sed 's/Modify:/XML Last Modified/g' | cut -c 1-29 | sed 's/:/\\:/g')

# -- Extraction
xml_file="data_rss.xml"
temp_file=$(mktemp)

# Extract quotes and authors using awk
awk '
BEGIN { RS=""; FS="\n" }
// {
title=""; description=""
for(i=1; i<=NF; i++) { if ($i ~ //) {<br /> sub(".*<title>[ \t]*", "", $i)<br /> sub("[ \t]*.*", "", $i)
title=$i
}
if ($i ~ //) {
sub(".*[ \t]*", "", $i)
sub("[ \t]*
.*", "", $i)
gsub("", "", $i)
description=$i }
}
if (title && description) {
print title "|" description >> "'"$temp_file"'"
last_title = title
last_author = description
}
}
END {
if (last_title && last_author) {
print last_title "|" last_author > "'"$temp_file"'.latest"
}
}
' "$xml_file"

# Verify that temp_file is populated
num_items=$(wc -l < "$temp_file") if [ "$num_items" -eq 0 ]; then echo "No items found with both title and description." rm "$temp_file" exit 1 fi # Choose latest or random quote if [[ "$1" == "latest" ]]; then echo "Showing latest entry..." latest_item=$(cat "$temp_file.latest") random_item=$latest_item else # Load lines from temp_file into an array mapfile -t items < "$temp_file" rm "$temp_file" # Select a random item random_index=$((RANDOM % num_items)) random_item=${items[$random_index]} fi # Split title and description quote=$(echo "$random_item" | cut -d'|' -f1) author=$(echo "$random_item" | cut -d'|' -f2) # Format text with line breaks (2 line breaks between title & author) This is ! formatted_text=$(echo -e "$quote\n\n$author" | fold -s -w 30) # Escape special characters and preserve newlines for ffmpeg ! This is ! # this creates \u0027 formatted_text_escaped=$(echo "$formatted_text" | sed "s/'/\\\u0027/g; s/:/\\\\:/g; s/\n/\\\x0A/g") # create video with ffmpeg ffmpeg -i ./Assets/input.mp4 -vf \ "drawtext=text='${formatted_text_escaped}':fontfile='./Assets/NotoSans_Condensed-Black.ttf':fontcolor=white:fontsize=42:x=10:y=20:box=1:boxcolor=black@0.5:boxborderw=15, \ drawtext=text='${modificationtime}':fontfile='./Assets/NotoSans_Condensed-Black.ttf':fontcolor=yellow:fontsize=30:x=10:y=420" \ -codec:a copy "${newstimefile}_output.mp4" # Debug Output echo "Formatted Text: $formatted_text_escaped" # echo "Modification Time: $modificationtime" # Move file to video folder mv *_output.mp4 /home/pi/video/

Files: Download quotes-rss and Assets

Raspiaudio+ V2

Das DAC V2 (orange) von Raspiaudio wird nicht mehr vertrieben, stattdessen gibt es jetzt die Variante V3 (blau). Die Installation ist gleich wie bei V2, siehe Forum, in meinem Fall will ich das Videolooper-Setup dokumentieren.
Hier die Auszüge aus der /boot/video_looper.ini, hw_device ist nicht nötig, aber sound = alsa muss eingeschaltet sein.


# ALSA hardware device to use for sound output. This consists of the card
# number and subdevice number separated by a comma, e.g. '1,0'. Run
# 'aplay -l' to list available devices. If empty, the default output device is
# used.
hw_device =
#hw_device = 1,0
...
# Sound output for omxplayer, either hdmi, local, both or alsa. When set to
# hdmi the video sound will be played on the HDMI output, and when set to local
# the sound will be played on the analog audio output. A value of both will
# play sound on both HDMI and the analog output. A value of alsa will play
# sound through ALSA, using the device specified in the [alsa] section above.
# The both value is the default.
#sound = both
#sound = hdmi
#sound = local
sound = alsa

In der /boot/config.txt ist nur der hifiberry-Zusatz wichtig und Onboard-Audio aus.


# Enable audio (loads snd_bcm2835)
# dtparam=audio=on

# dac
dtoverlay=hifiberry-dac

Damit ist Audio über den Miniklinken-Ausgang eingeschaltet.

Player „Universal“ (Audio/Video)

Complete Image (with Button on Pin 11 and 9):
http://rootfriend.com/videolooper-masterimage

Manual (Audio):

1. Connect Speaker or Head-Phones at the Audio-Connector
2. The Loop will start automatically after Power-On (Audio-Files need to be MP4 or M4A)
3. Re-Start the Audio-Loop with the Button on the Front

Manual: (Video)

1. Connect Screen at the HDMI-Connector
2. The Loop will start automatically after Power-On (Video-Files need to be MP4)
3. Re-Start the Video-Loop with the Button on the Front

ArgonPOD-Screen and VideoLooper (Zero 1 W/Zeros 2 W)

ARGON POD Display 2.8 inch

Legacy-Version required: 32-bit-version

Installer-Script:

#!/bin/bash
sudo apt-get update
sudo apt-get install -y git
sudo rm -rf LCD-show
git clone https://github.com/goodtft/LCD-show.git
chmod -R 755 LCD-show
cd LCD-show/
sudo ./LCD28-show
echo "2.8” RPi Display (MPI2801) ... finished"

Die offizielle Anleitung befindet sich hier: https://cdn.shopify.com/s/files/1/0556/1660/2177/files/ARGON_POD_MANUAL.pdf
Backup

VideoLooper: Timer

Play one file at full hour and change back to normal one („b.mp4“) 🙂
timer.sh

#/bin/bash
mv /home/pi/video/b.mp4 /home/pi/video_off
mv /home/pi/video_off/a.mp4 /home/pi/video
# videoduration a.mp4
sleep 300
mv /home/pi/video/a.mp4 /home/pi/video_off
mv /home/pi/video_off/b.mp4 /home/pi/video

crontab

0 13 * * * /bin/bash /home/pi/timer.sh >> /home/pi/timer.log 2>&1
0 14 * * * /bin/bash /home/pi/timer.sh >> /home/pi/timer.log 2>&1
0 15 * * * /bin/bash /home/pi/timer.sh >> /home/pi/timer.log 2>&1
0 16 * * * /bin/bash /home/pi/timer.sh >> /home/pi/timer.log 2>&1

Videolooper Netvideo: play videos from SMB-Sources

„Netvideo“ ist eine elegante Erweiterung, um Videos nicht von USB-Stick oder dem internen Verzeichnis abzuspielen, sondern über das Netzwerk. Vorteil: jede Änderung in dem Netzwerkverzeichnis wird unmittelbar erkannt und die Datei oder die Dateien werden ganz easy, vom Schreibtisch aus gesteuert, abgespielt. Macht richtig viel Sinn für mittlere und grosse Ausstellungsflächen.
Continue reading „Videolooper Netvideo: play videos from SMB-Sources“

Start/Stop Videolooper

To permanently disable video looper, i.e. to prevent it from ever starting on boot again, you can run a small script included with the video looper code. Connect to the Raspberry Pi in a terminal/SSH session and navigate to the folder where video_looper was downloaded, usualy the directory with this path /home/pi/pi_video_looper.
Continue reading „Start/Stop Videolooper“