-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
29 lines (22 loc) · 774 Bytes
/
utils.py
File metadata and controls
29 lines (22 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import cv2
# Combine overlapping or adjacent intervals
def merge_intervals(intervals):
if not intervals:
return []
intervals.sort(key=lambda x: (x[0], x[1]))
merged = [intervals[0]]
for current in intervals[1:]:
last = merged[-1]
if current[0] <= last[1]:
merged[-1] = (last[0], max(last[1], current[1]))
else:
merged.append(current)
return merged
def count_frames(video_path):
cap = cv2.VideoCapture(video_path)
estimated_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
fps = cap.get(cv2.CAP_PROP_FPS)
duration = estimated_frames / fps
print(f"Estimated frames: {estimated_frames}")
print(f"FPS: {fps}")
print(f"Duration: {duration:.2f} seconds")