Skip to content

Commit 03e08bb

Browse files
committed
update
1 parent b0280f0 commit 03e08bb

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎opencv/read_frame.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def process_frame(video_path, start_frame, end_frame, output_list, lock):
1414
thread_output = [] # 用于存储每个线程的输出
1515

1616
cap.set(cv2.CAP_PROP_POS_FRAMES, start_frame)
17-
for frame_number in range(start_frame, end_frame):
17+
18+
for _ in range(start_frame, end_frame):
1819
# 获取帧
1920
ret, _ = cap.read()
2021
if ret is False:
@@ -23,11 +24,14 @@ def process_frame(video_path, start_frame, end_frame, output_list, lock):
2324
# 获取时间戳
2425
timestamp = cap.get(cv2.CAP_PROP_POS_MSEC) / 1000.0
2526
thread_output.append(
26-
f"{time.ctime()} Thread {frame_number}: Timestamp - {timestamp}")
27+
f"{time.ctime()} Thread {start_frame}: Timestamp - {timestamp}")
2728

2829
# 设置视频流的位置,直接跳过一些帧
2930
cap.set(cv2.CAP_PROP_POS_FRAMES, cap.get(cv2.CAP_PROP_POS_FRAMES) + 20)
3031

32+
if cap.get(cv2.CAP_PROP_POS_FRAMES) >= end_frame:
33+
break
34+
3135
# 将每个线程的输出添加到共享的列表中
3236
# 使用锁确保对共享列表的安全访问
3337
with lock:
@@ -72,6 +76,7 @@ def main(video_path, num_threads):
7276
cv2.destroyAllWindows()
7377

7478

79+
# python3 read_frame.py /Users/frank/Movies/out.mp4 --num_threads 4
7580
if __name__ == "__main__":
7681
logging.basicConfig(level=logging.DEBUG,
7782
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',

0 commit comments

Comments
 (0)