Add 'create_video()' function

hightide
Dan Howe 5 years ago
parent b4867a2629
commit ea517114f9

@ -7,6 +7,7 @@ import os
import glob
import time
import pytz
import subprocess
from io import BytesIO
from datetime import datetime
import requests
@ -24,7 +25,7 @@ URL = 'https://camera.uwatchit.com.au/UWatchitWebV2/User/LiveView#'
OUTPUT_DIR = 'images'
TIMEZONE = 'Australia/Sydney'
WAIT_TIME = 0.1
RECORDING_DURATION = 120
RECORDING_DURATION = 20
SILENT = True
username = ''
password = ''
@ -157,7 +158,7 @@ def get_next_image(driver, cookies):
t_local = t_utc.astimezone(pytz.timezone(TIMEZONE))
# Save image
jpg_name = os.path.join(current_hightide_dir, 'images',
jpg_name = os.path.join(current_hightide_dir, 'jpg',
t_local.strftime('%Y-%m-%d_%H-%M-%S%z') + '.jpg')
os.makedirs(os.path.dirname(jpg_name), exist_ok=True)
im.save(jpg_name)
@ -174,7 +175,7 @@ def get_next_image(driver, cookies):
# Check if recording has completed
if t[-1] - t[0] > RECORDING_DURATION:
raise(StopIteration)
raise (StopIteration)
# Count images collected
n = len(t)
@ -192,7 +193,7 @@ def get_next_image(driver, cookies):
print(msg, end='\r', flush=True)
def main():
def get_images():
# Start browser session
driver = start_session()
cookies = login(driver)
@ -215,8 +216,29 @@ def main():
break
def create_video():
"""Combine all images into timelapse video with ffmpeg
"""
mp4_name = os.path.join(current_hightide_dir, f'{timestamp}_{height}.mp4')
now.strftime('%Y-%m-%d_%H-%M')
command = [
'ffmpeg',
'-pattern_type',
'glob',
'-framerate',
'10',
'-i',
current_hightide_dir + '/jpg/*.jpg',
mp4_name,
]
subprocess.run(command, stdout=subprocess.DEVNULL)
# Create counter
t = []
# Open browser
main()
get_images()
# Create video
create_video()

Loading…
Cancel
Save