Skip to content

Instantly share code, notes, and snippets.

@dvingo
Last active July 31, 2018 00:50
Show Gist options
  • Save dvingo/13138f3f9beaf4bf9b24c48489ea109a to your computer and use it in GitHub Desktop.
Save dvingo/13138f3f9beaf4bf9b24c48489ea109a to your computer and use it in GitHub Desktop.
Some bash scripts for timelapse and video filters of the raspberry pi camera module.
#!/bin/bash -
# TODO look into auto uploading to youtube:
# https://gist.github.com/joglomedia/569da3d2756257112b53
# See http://photo.stackexchange.com/questions/21089/how-do-i-create-a-timelapse-video-from-a-collection-of-photographs-in-linux
# http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-enc-images.html
dir_of_jpegs=new_timelapse
output_dir=./
video_filename=output.avi
print_usage() {
printf "\nUsage:\n"
printf "\n$0 --dir-of-jpegs=<directory/path> --video-filename=<filename>\n\n"
}
echo " pwd: $(pwd)"
for arg in "$@"; do
case $arg in
--dir-of-jpegs=*)
temp_dir_of_jpegs="$(echo $arg | awk -F= '{print $2}')";;
--video-filename=*)
temp_video_filename="$(echo $arg | awk -F= '{print $2}')";;
--output-dir=*)
temp_output_dir="$(echo $arg | awk -F= '{print $2}')";;
esac
done
if [ -z "$temp_dir_of_jpegs" ]; then
echo 'Missing directory of jpegs. Exiting...'
print_usage
exit 1
fi
dir_of_jpegs="$temp_dir_of_jpegs"
if [ -z "$temp_video_filename" ]; then
echo 'Missing video output filename. Exiting...'
print_usage
exit 1
fi
video_filename="$temp_video_filename"
if [ -n "$temp_output_dir" ]; then
output_dir="$temp_output_dir"
fi
echo "dir of jpegs: $dir_of_jpegs"
echo "video_filename: $video_filename"
echo "output dir: $output_dir"
pushd $dir_of_jpegs
ls -1tr | grep -v filenames.txt > filenames.txt
echo 'running mencoder'
echo " pwd: $(pwd)"
mencoder \
-nosound \
-noskip \
-oac copy \
-ovc copy \
-o $video_filename \
-mf fps=20 'mf://@filenames.txt'
popd
mv "${dir_of_jpegs}/${video_filename}" .
#!/bin/bash -
current_hour=$(date +"%H")
mode=auto
output_dir=time-lapse-street-two
sleep_for=30
width=960
height=540
mkdir -p $output_dir
# Between 8pm (20) and 7am use night exposure mode.
# However, the computer time is returning the hour 2 hours ahead,
# so just adjust by adding 2.
while true; do
current_hour=$(date +"%H")
if [[ "${current_hour#0}" -gt 21 || "${current_hour#0}" -lt 9 ]]; then
mode=night
fi
current_datetime=$(date +"%FT%H-%M-%S%Z")
raspistill -w "$width" -h "$height" -ex "$mode" --nopreview -o "$output_dir/${current_datetime}.jpg"
sleep $sleep_for
done
#!/bin/bash -
play_time=3000
flip_vert=""
flip_hori=""
if [[ $# = 1 ]]; then
play_time=$1
fi
for arg in "$@"; do
case $arg in
--length=*)
play_time="${arg:9}"
;;
--flipv)
flip_vert="-vf"
;;
--fliph)
flip_hori="-hf"
;;
esac
done
raspivid -w 960 -h 540 $flip_vert $flip_hori -t $play_time
# /bin/bash -
orig_modes=(none negative solarise sketch denoise emboss
oilpaint hatch gpen pastel watercolour film blur
saturation colourswap washedout posterise colourpoint
colourbalance cartoon)
modes=(negative sketch emboss
oilpaint hatch pastel watercolour colourswap
posterise cartoon)
#play_time=60000
play_time=6000
while true; do
for mode in "${modes[@]}"; do
raspivid -w 960 -h 540 -vf -hf -t $play_time -ifx "$mode"
done
done

First time setup

This is first time based on the UK raspbian images.

US setup

Usually the problem is the '|' character. if you type this and get '~' then you should update the keyboard layout:

sudo raspi-config

change keyboard layout

other -> generic 104 key

Not the International one.

It will ask you to pick from some UK options, choose other

Then get to the US options

Camera

sudo raspi-config

Interfacing options

SSH

# This makes it start on boot:
sudo systemctl enable ssh

# This starts it now:
sudo systemctl start ssh

Auth is password based by default.

Timelapse setup

Mount a USB

Put the following contents in: /etc/systemd/system/mnt-usb_stick.mount

[Unit]
Description=Mount USB stick

[Mount]
What=/dev/sda1
Where=/mnt/usb_stick
Type=vfat
Options=defaults,user,umask=0000

[Install]
WantedBy=multi-user.target

Put the following in: /etc/systemd/system/timelapse.service

[Unit]
Description=Take some photos
After=mnt-usb_stick.mount
Requires=mnt-usb_stick.mount

[Service]
Type=simple
ExecStart=/home/pi/timelapse/do_timelapse.sh

[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment