~voidraven/s4

b3b5702ccf489e1f9888fc49935ff31d8ca26260 — lotus 2 years ago 9e19eda
Added more comments and cleaned up foramtting. Version bump.
2 files changed, 49 insertions(+), 7 deletions(-)

M .s4/watch.sh
M s4ctl.sh
M .s4/watch.sh => .s4/watch.sh +30 -6
@@ 3,41 3,58 @@
# template used to create each camera+computer watch file.


# ------ Begin Global vars --------------------------------------
# ID is the camera number (0-n)
ID=XXX

# We expect /dev/video0 to be the webcam
WEBCAM="/dev/video0"

# Example valid resolutions: 640x480, 1280x720, or 1920x1080
REZ=YYY

# Your networked storage location
STORAGE=ZZZ
# Framerate you want to record at, 30 or 60 depending on what your cameras support

# Framerate you want to record at
# 30 or 60 depending on what your cameras support
FRAMERATE=WWW

# Where the local currently recording video is residing.
# When the video is done recording, we copy it over
CACHE_DIR="$HOME/.s4/cache"

# log file location
S4_LOG_DIR="$HOME/.s4/s4.log"

# FFmpeg arguments:
FF_ARG_STD="-hide_banner -nostats -loglevel fatal"
FF_ARG_LOG="-loglevel warning"
#FF_ARG_DBG=""
FF_FORMAT="avi"

# Logging disabled by default
# ( to enable change to "true" )
S4_LOG_ENABLED="NO-S4-LOGGING"
# ------ End Global vars ---------------------------------

# flip the status files over to reflect True

# ------ Begin functions ---------------------------------
# flip the status files over to reflect 'True'
fun_set_true () {
    echo "false" > "$STORAGE/s4/cameras/$ID/stop.status"
}

# flip the status files over to reflect False

# flip the status files over to reflect 'False'
fun_set_false () {
    echo "true" > "$STORAGE/s4/cameras/$ID/stop.status"
}

# kick off

# Kicks off recording work
# args: 1
# 1: filename to save video as (e.g. 22-2)
fun_record () {
    fun_set_true
    L_VIDNAME=$1


@@ 45,9 62,11 @@ fun_record () {
    ffmpeg -y $FF_ARG_STD -framerate $FRAMERATE -video_size $REZ -i $WEBCAM "$CACHE_DIR/$L_VIDNAME.$FF_FORMAT" &
}

# stop the camera

# Stop the camera and copy over the completed file
# args: 1
# 1: # file to be copied (f.t.b.c) over to the main storage
fun_stop () {
    # file to be copied (f.t.b.c) over to the main storage
    L_FTBC=$1
    fun_set_false
    kill $(pidof ffmpeg)


@@ 56,6 75,8 @@ fun_stop () {
    fi
}


# Checks if our status files have been modified
fun_check () {
    RUNSTAT=$(cat "$STORAGE/s4/cameras/$ID/run.status")
    STOPSTAT=$(cat "$STORAGE/s4/cameras/$ID/stop.status")


@@ 70,6 91,8 @@ fun_check () {
	echo "Error State: run & stop status files out of sync.."
    fi
}
# ------ End functions ---------------------------------


# was the script called recursively?
if [ "$#" -eq 1 ] && [ "$1" = "check" ] ; then


@@ 78,6 101,7 @@ if [ "$#" -eq 1 ] && [ "$1" = "check" ] ; then
    exit 0
fi


if [ -d $STORAGE/s4 ] ; then
    # where is this script running from?
    THIS_PWD=$(dirname $0)

M s4ctl.sh => s4ctl.sh +19 -1
@@ 6,11 6,17 @@
#
# This file the main controller utility

VERSION="0.1.1"
VERSION="0.1.2"

GBL_ERROR_MSG=""

# NOTE: variable preceeded by "L_" are "local" variables


# create the s4 directory tree
# args: 2
# 1: number of cameras we are working with
# 2: video storage path ( /mnt/where/i/want/vids )
fun_make_tree () {
    L1_CAMERAS=$1
    L1_STORAGE=$2


@@ 31,6 37,9 @@ fun_make_tree () {
}

# make sure we received good user input
# args: 2
# 1: number of cameras (1-99)
# 2: video recording resolution (640x480, 1280x720, etc)
fun_check_input () {
    L2_CAMERAS=$1
    L2_REZ=$2


@@ 48,6 57,11 @@ fun_check_input () {
}

# edit each of the watch templates to use the provided settings
# args: 4
# 1: number of cameras to set up
# 2: video recording resolution (640x480, 1280x720, etc)
# 3: root video storage location
# 4: video recording framerate (60 for 60fps)
fun_edit_templates () {
    L3_CAMERAS=$1
    L3_REZ=$2


@@ 128,6 142,8 @@ fun_check_config () {


# start/stop the camera(s)
# args: 1
# 1: action to perform; start or stop
fun_start_or_stop () {
    L_ACTION=$1
    fun_check_config


@@ 168,6 184,8 @@ fun_print_info () {
}

# print an error message
# args: 1
# 1: error message to print
fun_error () {
    echo "Uh Oh, something borked!"
    echo $1