Add 'create_video()' function

hightide
Dan Howe 5 years ago
parent b4867a2629
commit ea517114f9

@ -7,6 +7,7 @@ import os
import glob import glob
import time import time
import pytz import pytz
import subprocess
from io import BytesIO from io import BytesIO
from datetime import datetime from datetime import datetime
import requests import requests
@ -24,7 +25,7 @@ URL = 'https://camera.uwatchit.com.au/UWatchitWebV2/User/LiveView#'
OUTPUT_DIR = 'images' OUTPUT_DIR = 'images'
TIMEZONE = 'Australia/Sydney' TIMEZONE = 'Australia/Sydney'
WAIT_TIME = 0.1 WAIT_TIME = 0.1
RECORDING_DURATION = 120 RECORDING_DURATION = 20
SILENT = True SILENT = True
username = '' username = ''
password = '' password = ''
@ -157,7 +158,7 @@ def get_next_image(driver, cookies):
t_local = t_utc.astimezone(pytz.timezone(TIMEZONE)) t_local = t_utc.astimezone(pytz.timezone(TIMEZONE))
# Save image # 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') t_local.strftime('%Y-%m-%d_%H-%M-%S%z') + '.jpg')
os.makedirs(os.path.dirname(jpg_name), exist_ok=True) os.makedirs(os.path.dirname(jpg_name), exist_ok=True)
im.save(jpg_name) im.save(jpg_name)
@ -192,7 +193,7 @@ def get_next_image(driver, cookies):
print(msg, end='\r', flush=True) print(msg, end='\r', flush=True)
def main(): def get_images():
# Start browser session # Start browser session
driver = start_session() driver = start_session()
cookies = login(driver) cookies = login(driver)
@ -215,8 +216,29 @@ def main():
break 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 # Create counter
t = [] t = []
# Open browser # Open browser
main() get_images()
# Create video
create_video()

Loading…
Cancel
Save