Skip to content

Commit

Permalink
Add compression and day folder to timelapse (EliasKotlyar#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdlima authored and jmtatsch committed May 18, 2018
1 parent df90e1a commit a893ce6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions firmware_mod/config/timelapse.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
TIMELAPSE_INTERVAL=2.0
# Duration of the script should run, in minutes, set to 0 for unlimited
TIMELAPSE_DURATION=0
# Save dir config
SAVE_DIR_PER_DAY=1
# Enable compression
COMPRESSION_QUALITY=80
18 changes: 13 additions & 5 deletions firmware_mod/scripts/timelapse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@

PIDFILE='/run/timelapse.pid'
TIMELAPSE_CONF='/system/sdcard/config/timelapse.conf'
SAVE_DIR='/system/sdcard/DCIM/timelapse'
BASE_SAVE_DIR='/system/sdcard/DCIM/timelapse'

if [ -f "$TIMELAPSE_CONF" ]; then
. "$TIMELAPSE_CONF" 2>/dev/null
fi

if [ -z "$TIMELAPSE_INTERVAL" ]; then TIMELAPSE_INTERVAL=2.0; fi

if [ ! -d "$SAVE_DIR" ]; then
mkdir -p $SAVE_DIR
fi

# because``date`` doesn't support milliseconds +%N
# we have to use a running counter to generate filenames
Expand All @@ -24,6 +21,13 @@ last_prefix=''
ts_started=$(date +%s)

while true; do
SAVE_DIR=$BASE_SAVE_DIR
if [ $SAVE_DIR_PER_DAY -eq 1 ]; then
SAVE_DIR="$BASE_SAVE_DIR/$(date +%Y-%m-%d)"
fi
if [ ! -d "$SAVE_DIR" ]; then
mkdir -p $SAVE_DIR
fi
filename_prefix="$(date +%Y-%m-%d_%H%M%S)"
if [ "$filename_prefix" = "$last_prefix" ]; then
counter=$(($counter + 1))
Expand All @@ -33,7 +37,11 @@ while true; do
fi
counter_formatted=$(printf '%03d' $counter)
filename="${filename_prefix}_${counter_formatted}.jpg"
/system/sdcard/bin/getimage > "$SAVE_DIR/$filename" &
if [ -z "$COMPRESSION_QUALITY" ]; then
/system/sdcard/bin/getimage > "$SAVE_DIR/$filename" &
else
/system/sdcard/bin/getimage | /system/sdcard/bin/jpegoptim -m"$COMPRESSION_QUALITY" --stdin --stdout > "$SAVE_DIR/$filename" &
fi
sleep $TIMELAPSE_INTERVAL

if [ $TIMELAPSE_DURATION -gt 0 ]; then
Expand Down

0 comments on commit a893ce6

Please sign in to comment.