I created a program to extract the video into frames.I need suggestion to stop the cv2.imshow() after when there is no more frames to show.
video frames count = 88
fps = 10.0
duration= int(8)
def reading_video():
read_input = cv2.VideoCapture(r"D:\data\input.mp4")
frame_rate = int(read_input.get(cv2.CAP_PROP_FRAME_COUNT)) # 88
print("total number of frames is ", frame_rate)
fps = read_input.get(cv2.CAP_PROP_FPS) #10.0
duration = int((frame_rate/fps) %60)# 8
print(duration) # 8.0
initial_frame = 0
while read_input.isOpened():
ret, frame = read_input.read()
if ret == True:
cv2.imshow('video_frame', frame)
write_path = r"D:\data\frame_output"
write_name = 'frame0' + str(initial_frame) + '.jpg'
cv2.imwrite(os.path.join(write_path, write_name), frame)
initial_frame += 1
if cv2.waitKey(0) & 0xFF == ord('c'):
break
else:
break
instance_variable = reading_video()
instance_variable.release()
cv2.destroyAllWindows()
If waitkey(int(duration)) then it played and after no frame i do getting cv2 Assertion error.
If waitkey(0) then i do getting AttributeError: 'NoneType' object has no attribute 'release'
release()
oninstance_variable
?reading_video()
doesn't usesreturn
so it returnsNone
so you haveinstance_variable = None
and laterNone.release()
– furas