back-end ustreamer, GPS, timelapse, and photo-refresh site working
This commit is contained in:
@ -5,6 +5,6 @@ rm $WORKING_DIR/run
|
||||
sleep 5
|
||||
|
||||
# create timelapse
|
||||
ffmpeg -r 30 -pattern_type glob -i "$WORKING_DIR/*.jpg" \
|
||||
/bin/ffmpeg -r 30 -pattern_type glob -i "$WORKING_DIR/*.jpg" \
|
||||
-vf "scale=1920x1080" -vcodec libx264 /$WORKING_DIR/00-timelapse.mp4
|
||||
|
||||
|
||||
12
templates/docker-compose-php.yaml.j2
Normal file
12
templates/docker-compose-php.yaml.j2
Normal file
@ -0,0 +1,12 @@
|
||||
services:
|
||||
|
||||
photo_refresh:
|
||||
container_name: photo_refresh
|
||||
image: php:8.0-apache
|
||||
ports:
|
||||
- 8080:80
|
||||
volumes:
|
||||
- ./html:/var/www/html/
|
||||
- {{ working_folder }}/small_thumbs:/var/www/html/capture
|
||||
network_mode: bridge
|
||||
restart: always
|
||||
16
templates/gps_service.service-python.j2
Normal file
16
templates/gps_service.service-python.j2
Normal file
@ -0,0 +1,16 @@
|
||||
[Unit]
|
||||
Description=GPS Monitoring Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
WorkingDirectory={{ gps_service_directory }}
|
||||
ExecStart={{ gps_service_directory }}/venv/bin/python3 {{ gps_service_directory }}/app.py
|
||||
Restart=always
|
||||
User=root
|
||||
Group=root
|
||||
Environment="PATH={{ gps_service_directory }}/venv/bin"
|
||||
Environment="VIRTUAL_ENV={{ gps_service_directory }}/venv"
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
14
templates/gps_service.service.j2
Normal file
14
templates/gps_service.service.j2
Normal file
@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=GPS Monitoring Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
WorkingDirectory={{ gps_service_directory }}
|
||||
ExecStart={{ gps_service_directory }}/gps_service.sh
|
||||
Restart=always
|
||||
User=root
|
||||
Group=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
15
templates/gps_service.sh.j2
Normal file
15
templates/gps_service.sh.j2
Normal file
@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
i=1
|
||||
while [ $i ]
|
||||
do
|
||||
GPS_DATA=$(gpspipe -w -n 5)
|
||||
LON=$(echo $GPS_DATA | jq .lon | grep -v null | tail -n 1)
|
||||
LAT=$(echo $GPS_DATA | jq .lat | grep -v null | tail -n 1)
|
||||
SPEED=$(echo $GPS_DATA | jq .speed | grep -v null | tail -n 1)
|
||||
echo lat:$LAT > {{ gps_service_directory }}/gps_data
|
||||
echo lon:$LON >> {{ gps_service_directory }}/gps_data
|
||||
echo speed:$SPEED >> {{ gps_service_directory }}/gps_data
|
||||
chmod 755 {{ gps_service_directory }}/gps_data
|
||||
sleep 1
|
||||
done
|
||||
|
||||
@ -1,12 +1,4 @@
|
||||
#!/bin/bash
|
||||
# no need to do this math forever
|
||||
input_width=1920
|
||||
input_height=1080
|
||||
output_width=1340
|
||||
output_height=580
|
||||
# Calculate the ratio for trimming the top part
|
||||
trim_ratio=$(echo "scale=4; $output_height / $output_width * $input_width" | bc)
|
||||
|
||||
# this saves a snapshot of the camera every second or so depending on how long all the other crap takes
|
||||
# let's hope the vars make it otherwise imma need to parse a bollocksing file
|
||||
|
||||
@ -23,10 +15,37 @@ do
|
||||
# This variable is for the timestamp
|
||||
TIME=$(date +%c)
|
||||
|
||||
# Save the initial image in a temp file
|
||||
convert $WORKING_DIR/$FILENAME.jpg -gravity SouthWest -pointsize 44 \
|
||||
-fill yellow -annotate +30+30 "$TIME" $WORKING_DIR/$FILENAME-temp1.jpg
|
||||
|
||||
# Add the second annotation to the temp file
|
||||
convert $WORKING_DIR/$FILENAME-temp1.jpg -gravity SouthEast -pointsize 44 \
|
||||
-fill yellow -annotate +30+30 "$COORDINATES" $WORKING_DIR/$FILENAME-temp2.jpg
|
||||
|
||||
# Append the two images and save the final result
|
||||
convert $WORKING_DIR/$FILENAME-temp2.jpg -append $WORKING_DIR/$FILENAME.jpg
|
||||
|
||||
# Optionally, remove intermediate files if you don't need them
|
||||
rm $WORKING_DIR/$FILENAME-temp1.jpg $WORKING_DIR/$FILENAME-temp2.jpg
|
||||
|
||||
|
||||
# this big boi should add both the timestamp and the coordinates
|
||||
convert $WORKING_DIR/$FILENAME.jpg \( +clone -gravity NorthWest -pointsize 22 -fill yellow -annotate +30+30 "$TIME" \) \
|
||||
\( +clone -gravity NorthEast -pointsize 22 -fill yellow -annotate +30+30 "$COORDINATES" \) \
|
||||
-append $WORKING_DIR/$FILENAME.jpg
|
||||
#convert $WORKING_DIR/$FILENAME.jpg \( +clone -gravity NorthWest -pointsize 44 -fill yellow -annotate +30+30 "$TIME" $WORKING_DIR/$FILENAME-time.jpg\) \
|
||||
#\( +clone -gravity NorthEast -pointsize 44 -fill yellow -annotate +30+30 "$COORDINATES" $WORKING_DIR/$FILENAME-final.jpg\)
|
||||
#-append $WORKING_DIR/$FILENAME.jpg
|
||||
|
||||
# This should add the current time to the image and save it
|
||||
#convert $WORKING_DIR/$FILENAME.jpg -gravity SouthWest -pointsize 44 \
|
||||
#-fill yellow -annotate +30+30 $TIME $WORKING_DIR/$FILENAME-temp.jpg
|
||||
# Delete original
|
||||
#rm $WORKING_DIR/$FILENAME.jpg
|
||||
|
||||
# This should add the current latlon to the image and save it
|
||||
#convert $WORKING_DIR/$FILENAME-temp.jpg -gravity SouthEast -pointsize 44 \
|
||||
#-fill yellow -annotate +30+30 $COORDINATES $WORKING_DIR/$FILENAME-final.jpg
|
||||
# Delete temp
|
||||
#rm $WORKING_DIR/$FILENAME-temp.jpg
|
||||
|
||||
# This is for the tiny pic
|
||||
# I'll make one every 5 seconds
|
||||
@ -34,7 +53,7 @@ do
|
||||
# Calculate the height to trim based on the aspect ratios of the input and output images
|
||||
if (( $i % 5 == 0 )); then
|
||||
NOW=$(date +%Y%m%d%H%M%S)
|
||||
convert $WORKING_DIR/$FILENAME.jpg -gravity North -crop x$trim_ratio +repage -resize 1340x580 {{ working_folder }}/small_thumbs/$NOW.jpg
|
||||
convert $WORKING_DIR/$FILENAME.jpg -gravity North -crop 1920x830+0+260 +repage -resize 1340x580 {{ working_folder }}/small_thumbs/$NOW.jpg
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
@ -42,17 +61,3 @@ do
|
||||
((i++))
|
||||
|
||||
done
|
||||
|
||||
|
||||
# old one-at-a-time rubbish
|
||||
# # This should add the current time to the image and save it
|
||||
# convert $WORKING_DIR/$FILENAME.jpg -gravity NorthWest -pointsize 22 \
|
||||
# -fill yellow -annotate +30+30 $TIME $WORKING_DIR/$FILENAME-temp.jpg
|
||||
# # Delete original
|
||||
# rm $WORKING_DIR/$FILENAME.jpg
|
||||
#
|
||||
# # This should add the current latlon to the image and save it
|
||||
# convert $WORKING_DIR/$FILENAME-temp.jpg -gravity NorthEast -pointsize 22 \
|
||||
# -fill yellow -annotate +30+30 $COORDINATES $WORKING_DIR/$FILENAME.jpg
|
||||
# # Delete temp
|
||||
# rm $WORKING_DIR/$FILENAME-temp.jpg
|
||||
@ -5,8 +5,8 @@ After=network.target
|
||||
[Service]
|
||||
ExecStart=/opt/carputer/timelapse/timelapse_service.sh
|
||||
Restart=always
|
||||
User=timelapse
|
||||
Group=timelapse
|
||||
User=root
|
||||
Group=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
trap "source {{ working_folder }}/create_timelapse.sh &" SIGINT SIGTERM
|
||||
|
||||
# initialize all the variables
|
||||
# basic things
|
||||
@ -18,13 +19,63 @@ echo Timelapse Initiated at $BEGIN >> $WORKING_DIR/info.txt
|
||||
echo Shuttlecraft Galileo located at $CITY, $STATE $ZIPCODE >> $WORKING_DIR/info.txt
|
||||
echo $DISPLAY_NAME >> $WORKING_DIR/info.txt
|
||||
|
||||
# Set the run file and fork the loop
|
||||
touch $WORKING_DIR/run
|
||||
source {{ working_folder }}/record_snapshots.sh &
|
||||
# timelapse creation helpers
|
||||
echo "To create timelapse, here's the ffpmeg script" >> $WORKING_DIR/info.txt
|
||||
echo "/bin/ffmpeg -r 30 -pattern_type glob -i "$WORKING_DIR/*.jpg" \\" >> $WORKING_DIR/info.txt
|
||||
echo "-vf "scale=1920x1080" -vcodec libx264 /$WORKING_DIR/00-timelapse.mp4" >> $WORKING_DIR/info.txt
|
||||
# there should be a script that can do them all
|
||||
echo "/bin/ffmpeg -r 30 -pattern_type glob -i "$WORKING_DIR/*.jpg" \\" >> {{ working_folder }}/generate_timelapses.sh
|
||||
echo "-vf "scale=1920x1080" -vcodec libx264 /$WORKING_DIR/00-timelapse.mp4" >> {{ working_folder }}/generate_timelapses.sh
|
||||
|
||||
# capture time
|
||||
i=1
|
||||
while [ $i ]
|
||||
do
|
||||
FILENAME=$(printf "img-%05d" "$i")
|
||||
# old API based latlon
|
||||
#LATLON=$(curl -s http://10.18.1.1:8184/where_is?api_key={{ tesla_api_key }} )
|
||||
#LON=$(echo $LATLON | jq .lon)
|
||||
#LAT=$(echo $LATLON | jq .lat)
|
||||
LAT=$(cat {{ gps_service_directory }}/gps_data | grep lat | cut -d ":" -f 2 | awk '{printf("%.5f\n", $1)}')
|
||||
LON=$(cat {{ gps_service_directory }}/gps_data | grep lon | cut -d ":" -f 2 | awk '{printf("%.5f\n", $1)}')
|
||||
SPEED_KPH=$(cat {{ gps_service_directory }}/gps_data | grep speed | cut -d ":" -f 2)
|
||||
if [ $SPEED_KPH -lt 1 ]; then
|
||||
SPEED_MPH=$(echo "scale=3; $SPEEK_KPH * 0.62" | bc)
|
||||
else
|
||||
SPEED_MPH=0
|
||||
fi
|
||||
COORDINATES="$LAT, $LON, $SPEED_MPH mph"
|
||||
curl http://127.0.0.1:7123/snapshot --output $WORKING_DIR/$FILENAME.jpg
|
||||
|
||||
# This variable is for the timestamp
|
||||
TIME=$(date +%c)
|
||||
|
||||
# Save the initial image in a temp file
|
||||
convert $WORKING_DIR/$FILENAME.jpg -gravity SouthWest -pointsize 44 \
|
||||
-fill yellow -annotate +30+30 "$TIME" $WORKING_DIR/$FILENAME-temp1.jpg
|
||||
|
||||
# Add the second annotation to the temp file
|
||||
convert $WORKING_DIR/$FILENAME-temp1.jpg -gravity SouthEast -pointsize 44 \
|
||||
-fill yellow -annotate +30+30 "$COORDINATES" $WORKING_DIR/$FILENAME-temp2.jpg
|
||||
|
||||
# Append the two images and save the final result
|
||||
convert $WORKING_DIR/$FILENAME-temp2.jpg -append $WORKING_DIR/$FILENAME.jpg
|
||||
|
||||
# Optionally, remove intermediate files if you don't need them
|
||||
rm $WORKING_DIR/$FILENAME-temp1.jpg $WORKING_DIR/$FILENAME-temp2.jpg
|
||||
|
||||
# This is for the tiny pic
|
||||
# I'll make one every 5 seconds
|
||||
# I have 1340x580. i think i will truncate the top
|
||||
# Calculate the height to trim based on the aspect ratios of the input and output images
|
||||
if (( $i % 5 == 0 )); then
|
||||
NOW=$(date +%Y%m%d%H%M%S)
|
||||
convert $WORKING_DIR/$FILENAME.jpg -gravity North -crop 1920x830+0+260 +repage -resize 1340x580 {{ working_folder }}/small_thumbs/$NOW.jpg
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
|
||||
((i++))
|
||||
|
||||
done
|
||||
|
||||
# set the trap and wait
|
||||
trap "source {{ working_folder }}/create_timelapse.sh &" SIGINT SIGTERM
|
||||
while true; do
|
||||
echo "Running..."
|
||||
sleep 1
|
||||
done
|
||||
Reference in New Issue
Block a user