Video-Summary/generate test footage/kap.py

35 lines
726 B
Python
Raw Normal View History

2022-01-09 19:25:44 +00:00
# python
2020-11-05 22:17:05 +00:00
import cv2
import imageio
import time
2022-01-09 19:25:44 +00:00
2020-11-08 15:28:47 +00:00
writer = imageio.get_writer("./x23.mp4", fps=15)
2022-01-09 19:25:44 +00:00
2020-11-05 22:17:05 +00:00
url = "http://50.227.41.1/mjpg/video.mjpg"
i = 0
cap = cv2.VideoCapture(url)
2022-01-09 19:25:44 +00:00
while True:
2020-11-05 22:17:05 +00:00
try:
if i < 10:
2022-01-09 19:25:44 +00:00
i += 1
2020-11-05 22:17:05 +00:00
continue
2022-01-09 19:25:44 +00:00
2020-11-05 22:17:05 +00:00
result, frame = cap.read()
2022-01-09 19:25:44 +00:00
if result == False:
print("Error in cap.read()") # this is for preventing a breaking error
2020-11-05 22:17:05 +00:00
# break;
2022-01-09 19:25:44 +00:00
time.sleep(1)
2020-11-08 15:28:47 +00:00
break
2020-11-05 22:17:05 +00:00
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
writer.append_data(frame)
2022-01-09 19:25:44 +00:00
i += 1
2020-11-05 22:17:05 +00:00
2022-01-09 19:25:44 +00:00
if i > 20 * 60 * 60 * 2:
2020-11-05 22:17:05 +00:00
break
except Exception as e:
2020-11-08 15:28:47 +00:00
print("meh")
cap.release()
cv2.destroyAllWindows()
2022-01-09 19:25:44 +00:00
writer.close()