From ea517114f954ce5e3124c9eb8748155deca85b93 Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Thu, 28 Nov 2019 14:14:41 +1100 Subject: [PATCH] Add 'create_video()' function --- spectur_live_view.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/spectur_live_view.py b/spectur_live_view.py index caab3ea..f7b5809 100644 --- a/spectur_live_view.py +++ b/spectur_live_view.py @@ -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()