forked from markszabo/tapo-c200-timelapse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapture.py
36 lines (33 loc) · 1.24 KB
/
capture.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
import time
import datetime
import os
import subprocess
import logging
import timelapseconfig
# prepare the output folder
write_path = timelapseconfig.output_dir + datetime.datetime.today().strftime(timelapseconfig.daily_foldername_date_formatstring)
if not os.path.exists(write_path):
os.makedirs(write_path)
time.sleep(10)
print ("Starting capture")
starttime = datetime.datetime.now().timestamp()
failed = 0
succeeded = 0
while datetime.datetime.now().timestamp() < starttime + timelapseconfig.cronjob_repeat_time:
cycle_starttime = datetime.datetime.now().timestamp()
file_name = write_path + "/" + str(int(datetime.datetime.now().timestamp())) + ".png"
print(file_name)
logging.info(f"Capturing image {succeeded + failed + 1}...")
res = subprocess.call(
f"ffmpeg -y -loglevel fatal -rtsp_transport tcp -i {timelapseconfig.rtsp_url} -frames:v 1 {file_name}",
shell=True,
)
if res == 0:
succeeded += 1
else:
failed += 1
end = time.time()
logging.info(f"Succeeded: {succeeded}, failed: {failed}")
#camera.video_take_snapshot(0,file_name,1920,1080)
while datetime.datetime.now().timestamp() < cycle_starttime + timelapseconfig.delay_between_images:
time.sleep(0.1)