Skip to content

Commit

Permalink
Merge branch 'main' of github.com:EVS-GIS/woodcam-rm
Browse files Browse the repository at this point in the history
  • Loading branch information
sdunesme committed Apr 14, 2023
2 parents 4072840 + d4c2420 commit 447aeec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'opencv-python-headless==4.6.0.66',
'requests==2.28.1',
'simplejson==3.17.6',
'sqlalchemy==1.4.46',
'suntime==1.2.5',
'werkzeug==2.1.2'
],
Expand Down
12 changes: 9 additions & 3 deletions woodcamrm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import redis
import shutil

from urllib.parse import urlparse, parse_qs

from datetime import datetime
from dotenv import dotenv_values

Expand Down Expand Up @@ -142,6 +144,10 @@ def save_video_file(filepath, rtsp_url, station_id):
# Get current height of frame
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)

# Get fps from rtsp url
parsed_url = urlparse(rtsp_url)
fps = int(parse_qs(parsed_url.query)['fps'][0])

# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'MJPG')

Expand All @@ -156,7 +162,7 @@ def save_video_file(filepath, rtsp_url, station_id):

# Define output
archive_file = os.path.join(filepath, "archives", f"archive_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.avi")
archive_output = cv2.VideoWriter(archive_file, fourcc, 3, (int(width),int(height)))
archive_output = cv2.VideoWriter(archive_file, fourcc, fps, (int(width),int(height)))

archive_timeout = time.time() + 600
logger.warning(f"starting {archive_file} recording")
Expand All @@ -165,7 +171,7 @@ def save_video_file(filepath, rtsp_url, station_id):
videos_number += 1

live_file = os.path.join(filepath, "videos", f"video_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.avi")
live_output = cv2.VideoWriter(live_file, fourcc, 3, (int(width),int(height)))
live_output = cv2.VideoWriter(live_file, fourcc, fps, (int(width),int(height)))

live_timeout = time.time() + 60
logger.debug(f"starting {live_file} recording")
Expand Down Expand Up @@ -206,7 +212,7 @@ def save_video_file(filepath, rtsp_url, station_id):
# Define output
live_file = os.path.join(filepath, "videos", f"video_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.avi")
archive_file = os.path.join(filepath, "archives", f"archive_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.avi")
live_output = cv2.VideoWriter(live_file, fourcc, 3, (int(width),int(height)))
live_output = cv2.VideoWriter(live_file, fourcc, fps, (int(width),int(height)))

live_timeout = time.time() + 30
logger.debug(f"starting {live_file} recording")
Expand Down

0 comments on commit 447aeec

Please sign in to comment.