[init]
This commit is contained in:
commit
ac50292883
13
.gitignore
vendored
Normal file
13
.gitignore
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
# Project
|
||||
|
||||
pics
|
||||
videos
|
||||
|
||||
# Vim
|
||||
[._]*.s[a-v][a-z]
|
||||
!*.svg # comment out if you don't need vector files
|
||||
[._]*.sw[a-p]
|
||||
[._]s[a-rt-v][a-z]
|
||||
[._]ss[a-gi-z]
|
||||
[._]sw[a-p]
|
||||
|
47
capture.py
Executable file
47
capture.py
Executable file
@ -0,0 +1,47 @@
|
||||
#!/usr/bin/python
|
||||
import threading
|
||||
import requests
|
||||
import datetime
|
||||
import time
|
||||
import os
|
||||
import sys
|
||||
|
||||
delay = 10.0
|
||||
resolution = "1280x960"
|
||||
localDir = './photos/'
|
||||
|
||||
if sys.argv[1]:
|
||||
localDir = sys.argv[1] +"/"
|
||||
|
||||
if sys.argv[2]:
|
||||
delay = float(sys.argv[2])
|
||||
|
||||
# Change here with your IP
|
||||
url = 'http://poi:poi@192.168.0.32:8888/photo.jpg'
|
||||
focusUrl = 'http://poi:poi@192.168.0.32:8888/focus'
|
||||
|
||||
def convpicture(infile, outfile,resolution):
|
||||
quali = 80
|
||||
command = 'convert {} -quality {} -resize {} {}'.format(infile,quali,resolution,outfile)
|
||||
os.system(command)
|
||||
|
||||
def takePicture():
|
||||
# focus did better with macro picture
|
||||
Focus_request = requests.get(focusUrl)
|
||||
if Focus_request.status_code == 200:
|
||||
time.sleep(1) # important
|
||||
Img_request = requests.get(url)
|
||||
if Img_request.status_code == 200:
|
||||
time.sleep(1)
|
||||
now = datetime.datetime.now()
|
||||
name = now.strftime('%Y%m%d_%H%M%S' ) +'.jpg'
|
||||
print ('get picture '+ name)
|
||||
with open( localDir + 'last.jpg', 'wb') as f:
|
||||
f.write(Img_request.content)
|
||||
convpicture(localDir+'last.jpg',localDir+ name,resolution)
|
||||
|
||||
def printit():
|
||||
threading.Timer(delay, printit).start()
|
||||
takePicture()
|
||||
|
||||
printit()
|
78
makevideo.sh
Executable file
78
makevideo.sh
Executable file
@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
usage(){
|
||||
cat << EOF
|
||||
|
||||
$(basename $0) -d <directory> -s <rate> -p <prefix> -v <video_dir>
|
||||
|
||||
——————————————————————————————————————————————————————————————————————————————————
|
||||
Opt | Variable | Type | Definition | Default value
|
||||
——————————————————————————————————————————————————————————————————————————————————
|
||||
-d directory path Directory path of images to convert ./pics
|
||||
-r rate int Convert only 1/N images 1
|
||||
-p prefix str Images filename prefix. ''
|
||||
-v video_dir path Directory path to store video file. ./videos
|
||||
-s size str Images geometry. '1024x768'
|
||||
——————————————————————————————————————————————————————————————————————————————————
|
||||
|
||||
EOF
|
||||
exit
|
||||
}
|
||||
panic(){ echo $@; exit 2;}
|
||||
|
||||
directory="./pics"
|
||||
prefix=""
|
||||
rate="1"
|
||||
size='1024x768'
|
||||
video_dir="./videos"
|
||||
|
||||
while getopts "hd:s:p:v:" o; do
|
||||
case "${o}" in
|
||||
h)
|
||||
usage
|
||||
;;
|
||||
r)
|
||||
rate=${OPTARG}
|
||||
;;
|
||||
d)
|
||||
directory=${OPTARG}
|
||||
;;
|
||||
p)
|
||||
prefix=${OPTARG}
|
||||
;;
|
||||
v)
|
||||
video_dir=$( realpath ${OPTARG} 2>/dev/null )
|
||||
;;
|
||||
\?)
|
||||
panic "Unknown option at position $OPTIND. Exiting."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Safe test ffmpeg
|
||||
which ffmpeg &>/dev/null || panic "No ffmpeg found. Exiting."
|
||||
|
||||
# Safe test directory
|
||||
directory="$( realpath ${directory} 2>/dev/null )/"
|
||||
[ -n "${directory}" ] && [ -d "${directory}" ] || panic "'${directory}' is not a valid directory. Exiting."
|
||||
|
||||
# Safe test prefix
|
||||
[ -n "$( ls ${directory}/${prefix}* 2>/dev/null)" ] || panic "${directory}/${prefix}\* doesn't match any file. Exiting."
|
||||
|
||||
# Safe test rate
|
||||
[ ${rate} -gt 0 ] || panic "Invalid rate '${rate}'"
|
||||
pts=$( echo 1/$rate | bc -l )
|
||||
|
||||
# Safe test video_dir
|
||||
video_dir="$( realpath ${video_dir} 2>/dev/null )/"
|
||||
[ -n "${video_dir}" ] || panic "The video_dir option cannot be empty. Exiting."
|
||||
[ -d "${video_dir}" ] || {
|
||||
read -p "'${video_dir}' does not exist, do you want to create it? [Y/n] : "
|
||||
REPLY=${REPLY:-Y}
|
||||
[ "N" == ${REPLY^^} ] && panic "The video directory must exist. Exiting."
|
||||
mkdir -p ${video_dir} 2>/dev/null || panic "Failed to create '${video_dir}'. Exiting"
|
||||
}
|
||||
[ -n "$( ls ${directory}/${prefix}* 2>/dev/null)" ] || panic "${directory}/${prefix}\* doesn't match any file. Exiting."
|
||||
|
||||
|
||||
date=$(date +%s)
|
||||
ffmpeg -pattern_type glob -i "pics/*.jpg" -filter:v "setpts=(${pts})*PTS" -pix_fmt yuv420p -s "${size}" -vcodec libx264 "${video_dir}/$date.mp4"
|
Loading…
Reference in New Issue
Block a user