-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimelapse.py
54 lines (44 loc) · 1.37 KB
/
timelapse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
from datetime import datetime
from ftplib import FTP
import subprocess
import secrets
mp4File = 'timelapse.mp4'
localImagePath = "/root/growpi/images/"
def getAllImages():
start = datetime.now()
ftp = FTP(secrets.FTP_URL)
ftp.login(user=secrets.USERNAME, passwd=secrets.PASSWORD)
ftp.cwd('/images/')
# Get All Files
files = ftp.nlst()
files.remove('..')
#print(files)
# Print out the files
for file in files:
if not os.path.isfile(file):
print('Downloading...' + file)
ftp.retrbinary('RETR ' + file, open(localImagePath + file, 'wb').write)
else:
print(file + ' Already exists')
ftp.close()
end = datetime.now()
diff = end - start
print('All files downloaded for ' + str(diff.seconds) + 's')
def uploadMP4():
ftp = FTP(secrets.FTP_URL)
ftp.login(user=secrets.USERNAME, passwd=secrets.PASSWORD)
ftp.storbinary('STOR ' + mp4File, open(mp4File, 'rb'))
print("Succesfully uploaded: " + mp4File)
ftp.quit()
def makeTimelapse(frames=5):
p = subprocess.Popen(['ffmpeg', '-r', '{}'.format(frames), '-pattern_type', 'glob' ,'-i', '*.jpg', '-c:v', 'libx264', mp4File, '-y'])
p.wait()
print("Created: " + mp4File)
def main():
os.chdir(localImagePath)
getAllImages()
makeTimelapse(24)
uploadMP4()
if __name__ == '__main__':
main()