From 8e2f27bb50a2e2116ba4e8962c022415cc1649f3 Mon Sep 17 00:00:00 2001 From: Conner Vieira Date: Wed, 4 Sep 2024 14:01:01 -0400 Subject: [PATCH] Added video framerate snapping --- CHANGELOG.md | 8 +++++--- TODO.md | 3 ++- assets/support/configdefault.json | 2 +- dashcam.py | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5088bff..46109cb 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -452,6 +452,7 @@ This update focuses on unifying Predator's different modes to allow multipurpose - Updated dash-cam mode. - Added customizable frame-rate restrictions. - Added a per-device configuration value to set a maximum allowed frame-rate. When this frame-rate is exceeded, Predator will throttle dash-cam recording to stay below the limit. + - A threshold can be set to allow Predator to round up to the maximum framerate if it is within a small difference. - Added a per-device configuration to set a minimum expected frame-rate, below which a warning is displayed. This value does not have any impact on the actual recording frame-rate. - Overhauled dash-cam saving. - Frames captured during dash-cam recording are now saved in a separate thread. @@ -480,9 +481,13 @@ This update focuses on unifying Predator's different modes to allow multipurpose - Dashcam video save events can now be triggered using buttons via GPIO pins. - Improved looped recording. - Each thread now checks to see if old segments have already been deleted before deleting them themselves. + - Added optional background ALPR to dash-cam mode. + - The user can now configure Predator to conduct ALPR in the background while simultaneously capturing video. + - Removed the old "background recording" functionality in real-time mode, and it's corresponding configuration value. - Updated status lighting. - Moved the status lighting configuration to the "general" section. - Network requests are only made to update the status lighting if it has changed since the last update. + - This means that the status lighting can be turned off, and it will only turn back on when an update is made. - Updated configuration back-end. - Predator can now automatically update the configuration file between versions when configuration values are added or removed. - Added an initial start-up sequence, where Predator shows some basic information before the normal start-up. @@ -490,6 +495,3 @@ This update focuses on unifying Predator's different modes to allow multipurpose - Remote alert database sources can now be cached. - This allows Predator to continue using entries from a remote alert database even when the source goes offline. - Migrated most of the ALPR processing to a dedicated file for sake of organization. -- Added optional background ALPR to dash-cam mode. - - The user can now configure Predator to conduct ALPR in the background while simultaneously capturing video. - - Removed the old "background recording" functionality in real-time mode, and it's corresponding configuration value. diff --git a/TODO.md b/TODO.md index e89a87e..6eba3e9 100755 --- a/TODO.md +++ b/TODO.md @@ -40,7 +40,8 @@ These are the features actively planned for Predator and are likely to be added - [X] Add default config support for values that involve adding entries. - [X] Improve the efficiency of the GPS stamp. - [X] Check to see if old dashcam video files actually exist before deleting them. -- [ ] Test GPS behavior. +- [X] Test GPS behavior. +- [X] Finish video framerate snapping. ## Hypothetical diff --git a/assets/support/configdefault.json b/assets/support/configdefault.json index 9e7fae8..ea70212 100755 --- a/assets/support/configdefault.json +++ b/assets/support/configdefault.json @@ -166,7 +166,7 @@ "max_deletions_per_round": 10 } }, - "framerate_snap": 0.5 + "framerate_snap": 0.1 }, "capture": { "video": { diff --git a/dashcam.py b/dashcam.py index 1101ecf..0da97b6 100755 --- a/dashcam.py +++ b/dashcam.py @@ -915,7 +915,7 @@ def dashcam_output_handler(directory, device, width, height, framerate): save_this_segment = False # This will be set to True when the saving trigger is created. The current and previous dashcam segments are saved immediately when the trigger is created, but this allows the completed segment to be saved once the next segment is started, such that the saved segment doesn't cut off at the moment the user triggered a save. process_timing("start", "Dashcam/Calculations") - if (framerate + 0.2 >= float(config["dashcam"]["capture"]["video"]["devices"][device]["framerate"]["max"])): # Check to see if the frame-rate benchmark is within 0.2FPS of the maximum allowed framerate. + if (framerate + config["dashcam"]["saving"]["framerate_snap"] >= float(config["dashcam"]["capture"]["video"]["devices"][device]["framerate"]["max"])): # Check to see if the frame-rate benchmark is within 0.2FPS of the maximum allowed framerate. framerate = float(config["dashcam"]["capture"]["video"]["devices"][device]["framerate"]["max"]) # Set the frame-rate to the maximum allowed frame-rate. process_timing("end", "Dashcam/Calculations") @@ -973,7 +973,7 @@ def dashcam_output_handler(directory, device, width, height, framerate): output = cv2.VideoWriter(current_segment_name[device] + "." + config["dashcam"]["saving"]["file"]["extension"], cv2.VideoWriter_fourcc(output_codec[0], output_codec[1], output_codec[2], output_codec[3]), float(calculated_framerate[device]), (width, height)) # Start the new video output file. process_timing("start", "Dashcam/Calculations") - if (calculated_framerate[device] > float(config["dashcam"]["capture"]["video"]["devices"][device]["framerate"]["max"])): # Check to see if the calculated frame-rate exceeds the maximum allowed frame-rate. + if (calculated_framerate[device] + config["dashcam"]["saving"]["framerate_snap"] >= float(config["dashcam"]["capture"]["video"]["devices"][device]["framerate"]["max"])): # Check to see if the frame-rate benchmark is within 0.2FPS of the maximum allowed framerate. calculated_framerate[device] = float(config["dashcam"]["capture"]["video"]["devices"][device]["framerate"]["max"]) # Set the frame-rate to the maximum allowed frame-rate. process_timing("end", "Dashcam/Calculations") process_timing("start", "Dashcam/Writing")