Skript Dokumentation

Dieses Skript dient zur Einrichtung eines RTSP-Stream-Viewers auf einem Raspberry Pi. Es installiert den mpv-Player und konfiguriert das System so, dass der RTSP-Stream beim Start des Raspberry Pi automatisch gestartet wird.

Funktionen

configure_full

Diese Funktion fordert den Benutzer zur Eingabe aller erforderlichen Einstellungen auf und speichert sie in einer config.ini Datei.

configure_full() {
    # Prompt the user to enter the RTSP stream URL
    read -p "Enter the RTSP stream URL: " rtsp_url

    # Prompt the user to enter the camera resolution width
    read -p "Enter the camera resolution width (e.g., 2560 for 2560x1440): " original_width

    # Prompt the user to enter the camera resolution height
    read -p "Enter the camera resolution height (e.g., 1440 for 2560x1440): " original_height

    # Prompt the user to enter the desired zoom percentage (e.g., 60 for 60%)
    read -p "Enter the desired zoom percentage (e.g., 60 for 60%): " zoom_percentage

    # Calculate the crop values based on the zoom percentage
    update_crop_values $original_width $original_height $zoom_percentage

    # Create the config.ini file
    cat < $WORK_DIR/config.ini
[Settings]
RTSP_URL=$rtsp_url
CROP_WIDTH=$crop_width
CROP_HEIGHT=$crop_height
CROP_X=$crop_x
CROP_Y=$crop_y
ZOOM_PERCENTAGE=$zoom_percentage
EOL

    echo "Configuration saved to $WORK_DIR/config.ini"
}

update_config

Diese Funktion aktualisiert spezifische Konfigurationswerte in der config.ini Datei.

update_config() {
    key=$1
    value=$2

    # Update the value in config.ini
    if grep -q "^$key=" "$WORK_DIR/config.ini"; then
        sed -i "s|^$key=.*|$key=$value|" "$WORK_DIR/config.ini"
    else
        echo "$key=$value" >> "$WORK_DIR/config.ini"
    fi

    # Special handling for resolution and zoom to update crop values
    if [[ "$key" == "CROP_WIDTH" || "$key" == "CROP_HEIGHT" || "$key" == "ZOOM_PERCENTAGE" ]]; then
        source "$WORK_DIR/config.ini"
        update_crop_values $CROP_WIDTH $CROP_HEIGHT $ZOOM_PERCENTAGE
        update_config "CROP_WIDTH" $crop_width
        update_config "CROP_HEIGHT" $crop_height
        update_config "CROP_X" $crop_x
        update_config "CROP_Y" $crop_y
    fi

    echo "Updated $key in $WORK_DIR/config.ini"
}

Parameter

Das Skript unterstützt den Parameter --configure mit zusätzlichen Optionen url, resolution und zoom, um spezifische Konfigurationswerte zu aktualisieren:

Installation

Das Skript aktualisiert die Paketliste, installiert mpv und erstellt ein Startskript sowie eine .desktop-Datei, um das Skript beim Start des Raspberry Pi automatisch auszuführen.

# Update the package list
sudo apt-get update

# Install mpv
sudo apt-get install -y mpv

# Create the start_stream.sh script
cat < ./start_stream.sh
#!/bin/bash

# Debugging information
LOGFILE="$WORK_DIR/start_stream.log"
echo "Starting RTSP stream..." > \$LOGFILE
date >> \$LOGFILE

# Set working directory
cd \$PWD

# Load configuration
source <(grep = ./config.ini)

# Start mpv with the RTSP stream in fullscreen mode, apply cropping to zoom into the center
mpv --fs --no-border --vf=crop=\$CROP_WIDTH:\$CROP_HEIGHT:\$CROP_X:\$CROP_Y "\$RTSP_URL" >> \$LOGFILE 2>&1
EOL

# Make the start_stream.sh script executable
chmod +x ./start_stream.sh

# Debugging information
echo "Creating autostart directory and .desktop file..."

# Create the autostart directory if it doesn't exist
mkdir -p ~/.config/autostart

# Create the .desktop file for autostart
cat < ~/.config/autostart/start_stream.desktop
[Desktop Entry]
Type=Application
Name=Start RTSP Stream
Exec=\$PWD/start_stream.sh
X-GNOME-Autostart-enabled=true
EOL

# Debugging information
echo "Autostart setup complete."

# Notify the user that the setup is complete
echo "Setup complete. The RTSP stream will start automatically with zoom and rotation on the next reboot."

# Notify the user to reboot the system
echo "Please reboot your Raspberry Pi to apply the changes."

Abschluss

Nach der Installation wird der Benutzer aufgefordert, das System neu zu starten, um die Änderungen zu übernehmen.

# Notify the user that the setup is complete
echo "Setup complete. The RTSP stream will start automatically with zoom and rotation on the next reboot."

# Notify the user to reboot the system
echo "Please reboot your Raspberry Pi to apply the changes."

Installationsanleitung

Folgen Sie diesen Schritten, um das Skript zu installieren und zu konfigurieren:

  1. Laden Sie das Installationsskript herunter:
    wget https://osv-camera.pages.dev/osv_camera.sh
  2. Machen Sie das Skript ausführbar:
    chmod +x osv_camera.sh
  3. Konvertieren Sie die Zeilenenden des Skripts:
    dos2unix osv_camera.sh
  4. Führen Sie das Installationsskript aus:
    ./osv_camera.sh
  5. Konfiguration ändern:
  6. Starten Sie den Raspberry Pi neu:
    sudo reboot
  7. Überprüfen Sie die Logdatei nach dem Neustart:
    cat ./start_stream.log

Nach dem Neustart wird der RTSP-Stream automatisch mit den angegebenen Einstellungen gestartet.