Skip to main content

picorvid.sh

Dieses Snippet gibt den Typ einer Webcam/Kamera aus. Ist es ein Bild oder Video - der Rückgabewert ist zur Weiterverarbeitung.
Dabei ist der Rückgabewert wie folgt:
0 = Bild
1 = Video
2 = nicht unterstützt
3 = Fehler/ungültig

HOWTO:

$0 URL

Beispiel:

url="http://192.168.1.10/video.cgi"

typ=$(bash lib/picorvid.sh "$url")

# VARIANTE 1
case "$typ" in
    1)
        echo "MJPEG-Stream erkannt"
        ;;
    0)
        echo "Einzelbild erkannt"
        ;;
    2)
        echo "Bekannt, aber nicht unterstützt"
        ;;
    3)
        echo "Ungültige oder unbekannte URL"
        ;;
esac

# VARIANTE 2
if [ "$typ" = "1" ]; then
    echo "Video/Stream"
elif [ "$typ" = "0" ]; then
    echo "Bild"
fi

 

Script:

#!/bin/bash

# Video
if echo "$1" | grep -qE '\.mjpg|\.mjpeg|faststream|video\.cgi|GetOneShot|mjpg\.cgi|videostream\.cgi|\/image|\?action\=stream|\/cam_.\.cgi|\.r-kom\.de'; then
	echo "1"
	exit 0

# Bild
elif echo "$1" | grep -qE 'snapshot\.cgi|SnapshotJPEG|\.jpg|api\.cgi|cgi-bin\/camera|alarmimage|oneshotimage|image\/Index|CGIProxy\.fcgi|nph-jpeg\.cgi|onvif\/snapshot|GetImage\.cgi'; then
	echo "0"
	exit 0

# nicht unterstützt
elif echo "$1" | grep -qE 'GetData\.cgi|mjpeg\.cgi|\.png'; then
	echo "2"
	exit 0
else
# ansonsten ungültig
	echo "3"
	exit 0
fi