Axis Time-Laps Script Teil 1

Axis Time-Laps Script Teil 1

Axis Time-Laps Script Teil 1

Einleitung

Diese Script dient dem Download und der ersten Verarbeitung der Bilder vom der Kamera.

Funktionen

func_check

Die Funktion "func_check" dient der Überprüfung, ob die benötigten Programme alle Installiert sind. Falls ein Programm nicht installiert ist, wird eine entsprechende Fehlermeldung ausgegeben und das Script wird beendet. Folgenden Programme werden benötigt:

  • imagemagick
  • curl
  • whipthail
#Variable not editabel
var_convert="/usr/bin/convert"
var_curl="/usr/bin/curl"
var_whiptail="/usr/bin/whiptail"
var_temp_ip="192.168.1.2"

#Function

function func_check() {
    if [[ ! -x $var_convert ]]; then
        echo "Program \"imagemagick\" is not install\n\
        Please install \"imagemagick\""
        exit
    fi
    if [[ ! -x $var_curl ]]; then
        echo "Program \"curl\" is not install\n\
        Please install \"curl\""
        exit
    fi
    if [[ ! -x $var_whiptail ]]; then
        echo "Program \"whiptail\" is not install\n\
        Please install \"whiptail\""
        exit
    fi
}

func_image

Die Funktion "func_image" läde via "curl" das aktuelle Bild der Kamera herunter und bearbeite dies entsprechenden weiter.

Bei der ersten Variabele "var_output_image_name" wird der Name des Zielbildes definiert. Als Name wird die Zeit und Datum nach der UNIX Zeit gewählt.

Danach wird das Bild von der Kamera bezogen, die IP-Adresse bzw. der Hostname wird über die Option "-c" definiert. Die Auflösung des Bild wird über die Optionen "-r" definiert, hier bei muss der Wert auf die Kamera angepasst werden

function func_image() {
    var_output_image_name=$(date +%s)
    var_date_image=$(date +"%Y.%m.%d %H:%M")
    curl --digest -u "$var_cam_user:$var_cam_pw" -s \
    --output $var_output_image_name.jpg \
    http://$var_cam_host/axis-cgi/jpg/image.cgi?resolution=$var_image_resolution
    convert $var_output_image_name.jpg \
    -pointsize 30 -fill white -undercolor '#00000080' \
    -gravity NorthWest -annotate +20+20 \
    "$var_date_image" $var_output_image_name.jpg
    convert $var_output_image_name.jpg \
    $var_logo -gravity southeast -geometry +10+10 \
    -composite $var_output_image_name.jpg
}

func_metadate

Die Funktion "func_metadate" bearbeite mittels "exiftool" die Metadaten des Bildes, es wird nur das Copyright ergänzt. Das Copyright wird mit der Option "-C" angegeben.

function func_metadate() {
    if [[ -n $var_copyright ]]; then
        exiftool -m -overwrite_original -copyright="$var_copyright" $var_output_image_name.jpg
    fi
}

func_help

Die Funktion "func_help" zeigt und beschreibt die möglichen Optionen.

function func_help() {
    echo -e "Usage: axis_timelaps_image [OPTIONS]\n\
    Options:\n\
      -c     IP-Address or Hostname from Axis Networkcamera\n\
      -u     Username from Cam\n\
      -p     Passwort for User from Cam\n\
      -r     Resolution for Image\n\
      -l     Logo\n\
      -C     Copyright Information\n\
      -o     Output folder\n\
      -i     Interactive Configuration"
    exit
}

Script

#!/bin/bash

######################################################################################
#Script Name    : axis_timelaps_image                                                #
#Description    : Bashscript for creating Timelaps-Videos from Axis Networkcameras   #
#Args           : -c,-C,-i,-h,-l,-o,-p,-r,-u                                         #
#Author         : Gregor Holzfeind                                                   #
#Email          : gregor@holzfeind.ch                                                #
#License        : GNU General Public License v3.0                                    #
#Version        : 1.1                                                                #
######################################################################################

#Variable not editabel
var_convert="/usr/bin/convert"
var_curl="/usr/bin/curl"
var_whiptail="/usr/bin/whiptail"
var_temp_ip="192.168.1.2"

#Function

function func_check() {
    if [[ ! -x $var_convert ]]; then
        echo "Program \"imagemagick\" is not install\n\
        Please install \"imagemagick\""
        exit
    fi
    if [[ ! -x $var_curl ]]; then
        echo "Program \"curl\" is not install\n\
        Please install \"curl\""
        exit
    fi
    if [[ ! -x $var_whiptail ]]; then
        echo "Program \"whiptail\" is not install\n\
        Please install \"whiptail\""
        exit
    fi
}

function func_image() {
    var_output_image_name=$(date +%s)
    var_date_image=$(date +"%Y.%m.%d %H:%M")
    curl --digest -u "$var_cam_user:$var_cam_pw" -s --output $var_output_image_name.jpg http://$var_cam_host/axis-cgi/jpg/image.cgi?resolution=$var_image_resolution
    convert $var_output_image_name.jpg -pointsize 30 -fill white -undercolor '#00000080' -gravity NorthWest -annotate +20+20 "$var_date_image" $var_output_image_name.jpg
    convert $var_output_image_name.jpg $var_logo -gravity southeast -geometry +10+10 -composite $var_output_image_name.jpg
}
function func_metadate() {
    if [[ -n $var_copyright ]]; then
        exiftool -m -overwrite_original -copyright="$var_copyright" $var_output_image_name.jpg
    fi
}

function func_help() {
    echo -e "Usage: axis_timelaps_image [OPTIONS]\n\
    Options:\n\
      -c     IP-Address or Hostname from Axis Networkcamera\n\
      -u     Username from Cam\n\
      -p     Passwort for User from Cam\n\
      -r     Resolution for Image\n\
      -l     Logo\n\
      -C     Copyright Information\n\
      -o     Output folder\n\
      -i     Interactive Configuration"
    exit
}

function func_output_dir() {
    mv $var_output_image_name.jpg $var_output_dir/
}

function func_interactiv() {
    func_interactiv_host
    var_image_resolution=$(whiptail --inputbox "What is the Resolution of the image" 8 78 1920x1080 --title "Resolution of the image" 3>&1 1>&2 2>&3)
    curl --digest -u "$var_cam_user:$var_cam_pw" -s http://$var_cam_host/axis-cgi/param.cgi?action=list | grep "root.Properties.Image.Resolution" | cut -d"=" -f2 | grep "800x450"
    func_interactiv_cancel
    var_check_logo
}

function func_interactiv_host() {
    var_cam_host=$(whiptail --inputbox "What is the IP-Address or the Hostname from Axis Networkcamera" 8 78 $var_temp_ip --title "Address of Camera" 3>&1 1>&2 2>&3)
    func_interactiv_cancel
    var_temp_ip=$var_cam_host
    var_test_ping=$(ping -c4 $var_temp_ip | grep "loss" | awk '{print $8}' | cut -d"%" -f1)
    if [[ $var_test_ping -le 80 ]]; then
        whiptail --title "Error" --msgbox "this address \"var_temp_ip\" is not available, please fix" 8 78
        func_interactiv_host
    fi
    var_cam_user=$(whiptail --inputbox "What is the Username" 8 78 root --title "Username of Camera" 3>&1 1>&2 2>&3)
    func_interactiv_cancel
    var_cam_pw=$(whiptail --passwordbox "What is the Password" 8 78  --title "Password of Camera" 3>&1 1>&2 2>&3)
    func_interactiv_cancel
    var_temp_user=$(curl --digest -u "$var_cam_user:$var_cam_pw" -s http://$var_cam_host/axis-cgi/imagesize.cgi?camera=1 | grep "401")
    if [[ -n $var_temp_user ]]; then
        func_interactiv_host
    fi
}

function func_interactiv_cancel() {
    var_exitstatus=$?
    if [[ $var_exitstatus -eq 1 ]]; then
        exit
    fi
}

#Programm
func_check
while getopts c:u:p:r:l:C:o:hi opt 2>/dev/null
do
    case $opt in
        c) var_cam_host=$OPTARG;;
        u) var_cam_user=$OPTARG;;
        p) var_cam_pw=$OPTARG;;
        r) var_image_resolution=$OPTARG;;
        l) var_logo=$OPTARG;;
        C) var_copyright=$OPTARG;;
        o) var_output_dir=$OPTARG;;
        h) func_help;;
        i) func_interactiv;;
        *) func_help;;
    esac
done
func_image
func_metadate
func_output_dir
Gregor Holzfeind

Gregor Holzfeind

Currently there are no comments, so be the first!