Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/preset_rec_cmd.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
640x128_s 4000
118 changes: 94 additions & 24 deletions tools/raw2ogg2anim
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,127 @@

# needs: dcraw, double, netpbm tools, gstreamer, gifenc.sh

if [ "$4" = "" ]; then echo "format: `basename $0` vname first last fps [d[d]]"; exit; fi

#Determining the model of Raspberry Pi we're running on, to set an appropriate number of parallell processes
if [ "`lscpu | grep 'Model' | grep -o 'A72'`" = "A72" ]; then
num_processes=40
echo "Model 4, running 40 parallell processes"
else
if [ "`lscpu | grep 'Model' | grep -o 'A53'`" = "A53" ]; then
num_processes=20
echo "Model 3, running 20 parallell processes"
else
num_processes=10
echo "couldn't determine model, running 10 parallell processes"
fi
fi


#The following three code blocks define functions to be called later
#1. converts raw frames to png format
dcraw_conversion() {
dcraw $f
echo -en "$f \r"
}


#2. stretches lines so that videos recorded with line skips look better
line_doubling() {
if [ "$5" = "" ]; then
ln -s $f $f.d
else
if [ "$5" = "d" ]; then
double $f > $f.d
else
double $f > $f.D
double $f.D > $f.d
fi
fi
echo -en "$f \r"
}


#3. converts from intermediary format ppm to final image format png
ppmtopng_conversion() {
pnmtopng $f > $f.png
echo -en "$f \r"
}


# Taking user inputs
if [ "$4" = "" ]; then echo "format: `basename $0` vname first last fps [-t] [-k] [d[d]]"; exit; fi


# If the user inputs "-t" as parameter 5, then we append the current date and time to the filename
if [ "$5" = "-t" ]; then
echo "appending date and time to filename"
momentOfCapture=`date +%m.%d_T%H:%M:%S`
fi


# if the user adds the command line option -c or --count, ls | grep $1 is run in cwd,
# and the new filename is incremented by one in relation to the highest numbered similar filename.

#ls | grep $1


echo "removing old auxiliary files"
rm -f out.*.raw out.*.ppm out.*.ppm.[dDT] out.*.ppm.d.png


# this command appears to be slower when parallellized, so it's a single process for the time being.
echo "copying /dev/shm/out.????.raw files"
for((f=$2; f<=$3; ++f))
do
# cp /dev/shm/out.$(printf "%04d" $f).raw .
cat hd0.32k /dev/shm/out.$(printf "%04d" $f).raw >out.$(printf "%04d" $f).raw
cat /dev/shm/hd0.32k /dev/shm/out.$(printf "%04d" $f).raw >out.$(printf "%04d" $f).raw
echo -en "$f \r"
done
echo


echo "dcraw each .raw file (to .ppm)"
for f in out.*.raw
do
dcraw $f
echo -en "$f \r"
((i=i%num_processes)); ((i++==0)) && wait
dcraw_conversion &
done
echo
wait


echo ".ppm -> .ppm.d"
for f in out.*.ppm
do
if [ "$5" = "" ]; then
ln -s $f $f.d
else
if [ "$5" = "d" ]; then
double $f > $f.d
else
double $f > $f.D
double $f.D > $f.d
fi
fi
echo -en "$f \r"
((i=i%num_processes)); ((i++==0)) && wait
line_doubling &
done
echo
wait


echo ".ppm.d -> .ppm.d.png"
for f in out.*.ppm.d
do
pnmtopng $f > $f.png
echo -en "$f \r"
((i=i%num_processes)); ((i++==0)) && wait
ppmtopng_conversion &
done
echo
wait


echo "now creating $1.ogg"
gst-launch-1.0 multifilesrc location="out.%04d.ppm.d.png" index=$2 caps="image/png,framerate=\(fraction\)$4/1" ! pngdec ! videorate ! videoconvert ! videorate ! theoraenc ! oggmux ! filesink location="$1.ogg"

echo "now creating $1.anim.gif"
gifenc.sh $1.ogg $1.anim.gif

if [ "$5" = "-T" ]; then
echo "now creating $1-$momentOfCapture.gif"
gifenc.sh $1.ogg $1-$momentOfCapture.gif
else
echo "now creating $1.gif"
gifenc.sh $1.ogg $1.gif
fi


#comment the following two line if you want to keep individual image frames and other files in the current directory
[if "$6" != "-k" ]; then
echo "removing new auxiliary files"
rm -f out.*
fi

echo "done"
55 changes: 55 additions & 0 deletions tools/recording_trigger.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# This script reads the state of a hardcoded pin every set interval, and if the pin is read 'HIGH',
# a user-defined recording is launched. After the command is launched, the script exits.


# First the user lets us know whether to launch a preset or custom command
echo 'Please enter the recording command you wish to launch:'
echo 'If you instead want to read a preset command from a file, press key f and enter'
rec_cmd=
while [[ $rec_cmd = "" ]]; do
read rec_cmd
done


# Read command from a file if rec_cmd == f, otherwise store input as command
if [[ $rec_cmd = "f" ]]; then
rec_cmd=$(<preset_rec_cmd.txt)
echo "Running preset command upon triggering: "
echo $rec_cmd
else
echo "running this command upon triggering: "
echo $rec_cmd
fi


# Set desired input pin
echo "which pin would you like to read? (BCM numbering scheme) "
read input_pin
if [ ! -e /sys/class/gpio/gpio$input_pin ]; then
echo "$input_pin" > /sys/class/gpio/export
fi
echo "pin $input_pin is set as input pin"


#reading the input pin continuously, every interval
declare -i i
while [ 1 ]; do
status=$(< /sys/class/gpio/gpio$input_pin/value)
#echo $status
if [[ $status = "1" ]]; then
i+=1
fi
sleep 0.1 #seconds
if [[ $status != "1" && i>="1" ]]; then
i=0
fi
if [[ $i = "5" ]]; then
break
fi
done


#run commmand
$rec_cmd