Compare commits
12 Commits
8ed533a172
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 00d0c2aa3f | |||
| 19727f2f13 | |||
| 7ee08128f8 | |||
| 58e5638e67 | |||
| efcd9f0d1e | |||
| 9cf4e5142b | |||
| 1fb8f9c427 | |||
| 4cd449d7ba | |||
| f3f37a9166 | |||
| ec19cf1d3c | |||
| 948d68aa85 | |||
| a439cbe171 |
@@ -0,0 +1,3 @@
|
|||||||
|
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.webm filter=lfs diff=lfs merge=lfs -text
|
||||||
|
demo* !filter !diff !merge -text
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
# Überblick
|
|
||||||
Diese Codebase wured 08/09 2024 von Tim Schilling entwickelt um ein alltes gerät im Lechfeldmuseum der Stadt Königsbrunn zu ersetzten. Das Script ist für die Verwendung auf einen Raspberry Pi gedacht.
|
|
||||||
Dieses Script verwendet für das Spielen von Videos VLC bzw die Commandline variante '''cvlc''', das Scipt weches für das Automatische Abspeielen der Videos sowie der wechsel zwischen den zwei Videos ist in Pyhton geschrieben.
|
|
||||||
|
|
||||||
## Abhängigkeiten
|
|
||||||
- vlc -> Video Lan Client, anwendung zum Abspielen von Videos
|
|
||||||
- python3-rpi.gpio -> Python Bibliothek welche für die Verwendung der GPIO gebraucht wird.
|
|
||||||
|
|
||||||
## Skripte
|
|
||||||
Zusätzlich wurden für die Leichte Installation des Systems sowie für die Kontrolle im betrieb einige Shellskipts angelegt welche folgende Aufgaben haben:
|
|
||||||
|
|
||||||
- setup.sh -> Setup Script welches mehrere aufgaben erfüllt, dies führt (in Reienfolge der Ausführtung)
|
|
||||||
1. Fragt den Nutzer ob für diesen der Autostart dienst Verwendet werden soll.
|
|
||||||
2. Fragt den Nutzer ob die GPIO Shutdown funktion des Raspberry Pi verwendet werden soll.
|
|
||||||
3. Führt ein Systemupdate über den APT aus
|
|
||||||
4. Installiert die Abhängigkeiten
|
|
||||||
5. Herunterladen der Aktuellen Scripte aus dem GitHub Repo
|
|
||||||
6. Herunterladen der Videos aus dem GitHub Repo (**ACHTUNG: Wenn sich die Datein im Repo Geänder haben müssen die Datein im Skript entsprechend Angepasst werden.**)
|
|
||||||
7. Festlegen von SystemD dienst Datein Inhalt
|
|
||||||
8. Erstellen der System D Service Datein und Einschalten dieser je nach vorheriger Nutzerauswahl
|
|
||||||
9. Einfügen der zeile in /boot/config.txt für GPIO Shutdown
|
|
||||||
|
|
||||||
- video.py -> Script welches die Videos Abspielt
|
|
||||||
- start.sh -> Skript zum starten der Wiedergabe, schaltet gleichzeitig den Autostart der Anwendung über einen SystemD dienst **EIN**
|
|
||||||
- stop.sh -> Skript zum stoppen der Wiedergabe, schaltet gleichzeitig den Autostart der Anwendung über einen SystemD dienst **AUS**
|
|
||||||
- reload.sh -> Skript zum Neustarten der Wiedergabe, stop diese über System D und startet diese wieder
|
|
||||||
|
|
||||||
## Dateistrucktur
|
|
||||||
```
|
|
||||||
- PiVideo/
|
|
||||||
|- videos/
|
|
||||||
| |- loop.mp4
|
|
||||||
| |- trigger.mp4
|
|
||||||
|- video.py
|
|
||||||
|- start.sh
|
|
||||||
|- stop.sh
|
|
||||||
|- reload.sh
|
|
||||||
```
|
|
||||||
@@ -1,29 +1,39 @@
|
|||||||
# PiVideo
|
# Überblick
|
||||||
|
|
||||||
## TO-DO
|
Diese Codebase wurde 08/09 2024 von Tim Schilling entwickelt um ein altes gerät im Lechfeld Museum der Stadt Königsbrunn zu ersetzten. Das Skript ist für die Verwendung auf einen Raspberry Pi 4 gedacht unter verwendung von PiOS version 12 (Bookworm).
|
||||||
-~~ Add GPIO Shutdown and Start option to Script [see](https://raspberrypi.stackexchange.com/questions/117013/raspberry-pi-4-b-gpio-boot-and-shutdown-buttons) ~~
|
Dieses Skript verwendet für das Spielen von Videos VLC bzw. die Kommandozeilen variante ```cvlc```. Im Normalzustnad wir ein demobild (siehe ./videos/thumb.jpg) angezeigt, bei betätigung einses GPIO Knopfes wird ein Kurzfilm (ca. 15 minuten) abgespielt. Dannach wird wieder das bild angezeigt. Der Knopf schließt ```GPIO 17``` (PIN 11) auf ```GND``` (PIN 9) kurz.
|
||||||
- Remove old files when reinstalling
|
|
||||||
|
|
||||||
## Overview
|
Das Skript wird Automatische bei jedem Reboot über einen SystemD dienst gestartet, soffern dies nicht vorher abgeschalten wurde.
|
||||||
This is a collection of scripts which run a video in a loop until a Button connected to GPIO is Pressed.
|
|
||||||
Then another video is played once.
|
|
||||||
|
|
||||||
## Installation
|

|
||||||
For installation download and run setup.sh. This will install the nesecary dependencys, create the needed folder structure and download the Script.
|
|
||||||
It will also create a SystemD service to automaticly start the program when the Pi is booted.
|
|
||||||
|
|
||||||
**CAUTION: IF THE VIDEO FILES IN THE REPO HAVE CHANGED PLEASE CHECK THE SCRIPT IF THEY ARE CORRECT!**
|
## Abhängigkeiten
|
||||||
|
|
||||||
```bash
|
- vlc -> Video Lan Client, anwendung zum Abspielen von Videos
|
||||||
wget -L "https://raw.githubusercontent.com/miT-nib-hcI/PiVideo/main/setup.sh" &&
|
- python3-rpi.gpio -> Python Bibliothek welche für die Verwendung der GPIO gebraucht wird.
|
||||||
chmod 755 setup.sh &&
|
- fbi -> Frame Buffer Imageviewer, anwendung für das einzeigen von Bildern über den Framebuffer
|
||||||
./setup.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
## Configuration
|
## Skripte
|
||||||
Since it is a realativly simple Python script you can modify as needed.
|
|
||||||
The videos which are played are in the videos folder, as the nameing of the files suggests the loop.mp4 is played on loop and the trigger.mp4 is played once when the GPIO button has been pressed.
|
Es wurden mehrer Skripte für das Aufsetzen und die Bedienung geschreiben, weiteres wird hier beschrieben.
|
||||||
You can replace the files as needed with your own files. The files included right now are just for demonstration.
|
|
||||||
|
- setup.sh -> Setup Script welches mehrere aufgaben erfüllt, dies führt (in Reienfolge der Ausführtung)
|
||||||
|
1. Fragt den Nutzer ob für diesen der Autostart dienst Verwendet werden soll.
|
||||||
|
2. Fragt den Nutzer ob die GPIO Shutdown funktion des Raspberry Pi verwendet werden soll.
|
||||||
|
3. Führt ein Systemupdate über den APT aus
|
||||||
|
4. Installiert die Abhängigkeiten
|
||||||
|
5. Herunterladen der Aktuellen Scripte aus dem GitHub Repo
|
||||||
|
6. Herunterladen der Videos aus dem GitHub Repo (**ACHTUNG: Wenn sich die Datein im Repo Geänder haben müssen die Datein im Skript entsprechend Angepasst werden.**)
|
||||||
|
7. Festlegen von SystemD dienst Datein Inhalt
|
||||||
|
8. Erstellen der System D Service Datein und Einschalten dieser je nach vorheriger Nutzerauswahl
|
||||||
|
9. Einfügen der zeile in /boot/config.txt für GPIO Shutdown
|
||||||
|
|
||||||
|
- video.py -> Script welches die Videos Abspielt
|
||||||
|
- start.sh -> Skript zum starten der Wiedergabe, schaltet gleichzeitig den Autostart der Anwendung über einen SystemD dienst **EIN**
|
||||||
|
- stop.sh -> Skript zum stoppen der Wiedergabe, schaltet gleichzeitig den Autostart der Anwendung über einen SystemD dienst **AUS**
|
||||||
|
- reload.sh -> Skript zum Neustarten der Wiedergabe, stop diese über System D und startet diese wieder
|
||||||
|
|
||||||
|
## Dateistrucktur
|
||||||
|
|
||||||
```
|
```
|
||||||
- PiVideo/
|
- PiVideo/
|
||||||
@@ -35,5 +45,3 @@ You can replace the files as needed with your own files. The files included righ
|
|||||||
|- stop.sh
|
|- stop.sh
|
||||||
|- reload.sh
|
|- reload.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
The button to trigger the video switch is by default conected to GPIO 17 and GND, you can change this in the Scipt itself if needed.
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 205 KiB |
@@ -59,7 +59,7 @@ check_error "Failed to update packages."
|
|||||||
|
|
||||||
|
|
||||||
echo -e "${GREEN}======== Installing dependencies =========${NOCOLOR}"
|
echo -e "${GREEN}======== Installing dependencies =========${NOCOLOR}"
|
||||||
sudo apt install -y vlc python3-rpi.gpio git
|
sudo apt install -y vlc python3-rpi.gpio git fbi
|
||||||
check_error "Failed to install dependencies."
|
check_error "Failed to install dependencies."
|
||||||
|
|
||||||
|
|
||||||
@@ -93,20 +93,14 @@ echo -e "${GREEN}======== Downloading videos ========${NOCOLOR}"
|
|||||||
cd videos/
|
cd videos/
|
||||||
|
|
||||||
# Download video files
|
# Download video files
|
||||||
download_file "videos/loop.mp4"
|
download_file "videos/thumb.jpg"
|
||||||
download_file "videos/trigger.webm"
|
download_file "videos/trigger.mp4"
|
||||||
|
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
# Create the systemd service for autologin and video control
|
# Create the systemd service for autologin and video control
|
||||||
echo -e "${GREEN}======== Creating systemd service ========${NOCOLOR}"
|
echo -e "${GREEN}======== Creating systemd service ========${NOCOLOR}"
|
||||||
|
|
||||||
# Autologin service content
|
|
||||||
AUTOLOGIN_SERVICE_CONTENT="[Service]
|
|
||||||
ExecStart=
|
|
||||||
ExecStart=-/sbin/agetty --autologin $CURRENT_USER --noclear tty1 linux
|
|
||||||
"
|
|
||||||
|
|
||||||
# Video control service content
|
# Video control service content
|
||||||
SERVICE_CONTENT="[Unit]
|
SERVICE_CONTENT="[Unit]
|
||||||
Description=Video Control Script
|
Description=Video Control Script
|
||||||
@@ -119,6 +113,10 @@ StandardOutput=inherit
|
|||||||
StandardError=inherit
|
StandardError=inherit
|
||||||
Restart=always
|
Restart=always
|
||||||
User=$CURRENT_USER
|
User=$CURRENT_USER
|
||||||
|
TTYPath=/dev/tty1
|
||||||
|
StandardInput=tty
|
||||||
|
RemainAfterExit=yes
|
||||||
|
Type=simple
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
@@ -126,11 +124,10 @@ WantedBy=multi-user.target
|
|||||||
|
|
||||||
# If the user opted for autostart, create the service files
|
# If the user opted for autostart, create the service files
|
||||||
if [ $SYSD -eq 0 ]; then
|
if [ $SYSD -eq 0 ]; then
|
||||||
# Creating Service file for Autologin of the Current User
|
# Disableing Login Promt for TTY1
|
||||||
echo "$AUTOLOGIN_SERVICE_CONTENT" | sudo tee /etc/systemd/system/getty@tty1.service.d/override.conf > /dev/null
|
sudo systemctl disable getty@tty1.service
|
||||||
check_error "Failed to create autologin service."
|
|
||||||
|
|
||||||
# Craating Service file for Video Playback
|
# Creating Service file for Video Playback
|
||||||
echo "$SERVICE_CONTENT" | sudo tee /etc/systemd/system/$SERVICE_NAME > /dev/null
|
echo "$SERVICE_CONTENT" | sudo tee /etc/systemd/system/$SERVICE_NAME > /dev/null
|
||||||
check_error "Failed to create PiVideo service."
|
check_error "Failed to create PiVideo service."
|
||||||
|
|
||||||
@@ -170,3 +167,4 @@ echo -e "${GREEN}======== The script was executed successfully ========${NOCOLOR
|
|||||||
echo -e "${GREEN}=========================================================${NOCOLOR}"
|
echo -e "${GREEN}=========================================================${NOCOLOR}"
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
|||||||
Executable
+42
@@ -0,0 +1,42 @@
|
|||||||
|
#! /usr/bin/python3
|
||||||
|
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
|
# GPIO-Setup
|
||||||
|
BUTTON_PIN = 17 # Ersetze dies durch den tatsächlichen GPIO-Pin, den du verwendest
|
||||||
|
GPIO.setmode(GPIO.BCM)
|
||||||
|
GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||||
|
|
||||||
|
loop_video = 'videos/loop.mp4'
|
||||||
|
trigger_video = 'videos/trigger.mp4'
|
||||||
|
|
||||||
|
# Funktion zum Abspielen eines Videos
|
||||||
|
def play_video(video_file):
|
||||||
|
subprocess.run(['cvlc', '--play-and-exit', '--fullscreen', '--no-video-title-show', video_file])
|
||||||
|
|
||||||
|
# Endlosschleife Video 1 starten
|
||||||
|
loop_video = subprocess.Popen(['cvlc', '--loop', '--fullscreen', '--no-video-title-show', loop_video])
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
# Überprüfen, ob der Button gedrückt wurde
|
||||||
|
button_state = GPIO.input(BUTTON_PIN)
|
||||||
|
if button_state == GPIO.LOW: # Button gedrückt
|
||||||
|
# Stoppe das loop_video
|
||||||
|
loop_video.terminate()
|
||||||
|
|
||||||
|
# Video 2 abspielen
|
||||||
|
play_video(trigger_video)
|
||||||
|
|
||||||
|
# Nach dem Abspielen von Video 2 wieder Video 1 in Schleife starten
|
||||||
|
loop_video = subprocess.Popen(['cvlc', '--loop', '--fullscreen', '--no-video-title-show', loop_video])
|
||||||
|
|
||||||
|
time.sleep(0.1) # Entprellen des Buttons
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
# Bei einem Tastaturabbruch das laufende Video stoppen und GPIO reinigen
|
||||||
|
loop_video.terminate()
|
||||||
|
GPIO.cleanup()
|
||||||
|
|
||||||
@@ -1,41 +1,76 @@
|
|||||||
#! /usr/bin/python3
|
import os
|
||||||
|
|
||||||
import RPi.GPIO as GPIO
|
|
||||||
import subprocess
|
|
||||||
import time
|
import time
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
from subprocess import Popen, call
|
||||||
|
import sys
|
||||||
|
|
||||||
# GPIO-Setup
|
os.system('sudo chvt 1')
|
||||||
BUTTON_PIN = 17 # Ersetze dies durch den tatsächlichen GPIO-Pin, den du verwendest
|
|
||||||
|
# Pfade zu den Dateien
|
||||||
|
THUMBNAIL_IMAGE = "/home/tim/PiVideo/videos/thumb.jpg"
|
||||||
|
TRIGGER_VIDEO = "/home/tim/PiVideo/videos/trigger.mp4"
|
||||||
|
LOG_FILE = "/home/tim/PiVideo/log.txt"
|
||||||
|
|
||||||
|
# GPIO-Einstellungen
|
||||||
|
BUTTON_PIN = 17
|
||||||
GPIO.setmode(GPIO.BCM)
|
GPIO.setmode(GPIO.BCM)
|
||||||
GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||||
|
|
||||||
loop_video = 'videos/loop.mp4'
|
# Umleitung der Ausgaben in eine Log-Datei
|
||||||
trigger_video = 'videos/trigger.webm'
|
sys.stdout = open(LOG_FILE, "a")
|
||||||
|
sys.stderr = open(LOG_FILE, "a")
|
||||||
|
|
||||||
# Funktion zum Abspielen eines Videos
|
def log_message(message):
|
||||||
def play_video(video_file):
|
"""Schreibt eine Nachricht in die Log-Datei."""
|
||||||
subprocess.run(['cvlc', '--play-and-exit', '--fullscreen', '--no-video-title-show', video_file])
|
timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
||||||
|
print(f"{timestamp} - {message}")
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
# Endlosschleife Video 1 starten
|
def show_thumbnail(image_path):
|
||||||
loop_video = subprocess.Popen(['cvlc', '--loop', '--fullscreen', '--no-video-title-show', loop_video])
|
"""Zeigt das Thumbnail an."""
|
||||||
|
log_message(f"Displaying thumbnail: {image_path}")
|
||||||
|
call(['sudo', 'fbi', '-T', '1', '-d', '/dev/fb0', '-a','-noverbose', image_path])
|
||||||
|
|
||||||
try:
|
def close_thumbnail():
|
||||||
while True:
|
"""Beendet fbi, um das Thumbnail zu schließen."""
|
||||||
# Überprüfen, ob der Button gedrückt wurde
|
log_message("Closing thumbnail.")
|
||||||
button_state = GPIO.input(BUTTON_PIN)
|
call(['sudo', 'killall', 'fbi'])
|
||||||
if button_state == GPIO.LOW: # Button gedrückt
|
|
||||||
# Stoppe das loop_video
|
|
||||||
loop_video.terminate()
|
|
||||||
|
|
||||||
# Video 2 abspielen
|
def play_video(video_path):
|
||||||
play_video(trigger_video)
|
"""Spielt das Trigger-Video ab."""
|
||||||
|
log_message(f"Playing video: {video_path}")
|
||||||
|
p = Popen(['cvlc', '--play-and-exit', '--fullscreen', '--no-video-title-show', video_path])
|
||||||
|
p.wait()
|
||||||
|
|
||||||
# Nach dem Abspielen von Video 2 wieder Video 1 in Schleife starten
|
|
||||||
loop_video = subprocess.Popen(['cvlc', '--loop', '--fullscreen', '--no-video-title-show', loop_video])
|
|
||||||
|
|
||||||
time.sleep(0.1) # Entprellen des Buttons
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
def main():
|
||||||
# Bei einem Tastaturabbruch das laufende Video stoppen und GPIO reinigen
|
log_message("Starting main loop.")
|
||||||
loop_video.terminate()
|
try:
|
||||||
GPIO.cleanup()
|
while True:
|
||||||
|
# Thumbnail anzeigen
|
||||||
|
show_thumbnail(THUMBNAIL_IMAGE)
|
||||||
|
|
||||||
|
# Warten, bis der Button gedrückt wird
|
||||||
|
while GPIO.input(BUTTON_PIN) == GPIO.HIGH:
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
|
||||||
|
# Video abspielen, wenn Button gedrückt wurde
|
||||||
|
log_message("Button pressed, playing trigger video.")
|
||||||
|
play_video(TRIGGER_VIDEO)
|
||||||
|
|
||||||
|
# fbi schließen, bevor das Video abgespielt wird
|
||||||
|
close_thumbnail()
|
||||||
|
# Nach dem Video wieder Thumbnail anzeigen
|
||||||
|
log_message("Trigger video finished, displaying thumbnail again.")
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
log_message("Script interrupted by user.")
|
||||||
|
finally:
|
||||||
|
GPIO.cleanup()
|
||||||
|
log_message("GPIO cleanup completed. Exiting script.")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
log_message("Script started.")
|
||||||
|
main()
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 254 KiB |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 129 KiB |
BIN
Binary file not shown.
Reference in New Issue
Block a user