I am using tutorial code I found, and I can open and view about the first second of my mp4 video, but after that, cap.read() returns false and the video exits. Any idea why that might be? The number of frames is reported as 9494.
Update: so after I covert it to avi using: “ffmpeg.exe” -i “GH010032.MP4” -c:v libx264 -crf 19 -preset slow -c:a aac -b:a 192k -ac 2 GH010032.avi
Opencv can display the avi just fine. Any ideas? Is this a 264 codec issue or something?
import cv2 as cv import numpy as np # Create a VideoCapture object and read from input file # If the input is the camera, pass 0 instead of the video file name cap = cv.VideoCapture('C:\\Users\\kulcy\\Videos\\GoPro\\GH010032.MP4') print (int(cap.get(cv.CAP_PROP_FRAME_COUNT))) # Check if camera opened successfully if (cap.isOpened()== False): print("Error opening video stream or file") # Read until video is completed i=0 while(cap.isOpened()): print (i) i+=1 if i==45: print ("here") # Capture frame-by-frame ret, frame = cap.read() if ret == True: # Display the resulting frame cv.imshow('Frame',frame) # Press Q on keyboard to exit if cv.waitKey(1) & 0xFF == ord('q'): break # Break the loop else: print ("is open: ", cap.isOpened()) break # When everything done, release the video capture object cap.release() # Closes all the frames cv.destroyAllWindows()
Using python 3.10.2 and opencv_python-18.104.22.168