+ 2

opencv video recording problem

when trying to record video using while loop than the video is geeting paused and when i'm using only if case like if true video.write(frame) but i'm unable to save the video and each time when the video.write () is occuring it's creating a .avg file but it's not opening. this is my code ---> def Connect(self): self.cap = cv2.VideoCapture(0) while(self.cap.isOpened()): ret, frame = self.cap.read() if ret == True: date = datetime.datetime.now() self.displayImage(frame,0) cv2.waitKey() fourcc = cv2.VideoWriter_fourcc(*"XVID") self.out = cv2.VideoWriter('./videos/Video_%s%s%sT%s%s.avi'%(date.year,date.month,date.day,date.hour,date.minute),fourcc, 30, (1280, 720)) if(captureImg): print("capture") cv2.imwrite('./images/img_%s%s%sT%s%s.png'%(date.year, date.month, date.day, date.hour, date.minute),frame) self.captureImg=False # this is the main logic of recording video ,and here something is going wrong. if self.VdoRecord: while(True): out.write(frame) if self.VdoRecord == False: out.release() break self.cap.release() cv2.destroyAllWindows()

25th Apr 2022, 5:02 AM
Anjali Singh
Anjali Singh - avatar
2 Respostas
0
I had the same problem, it's because of gstreamer support. First you have to check if your opencv has gstreamer support by running the following code: import cv2 print(cv2.getBuildInformation()) Scroll down till you get to GSTREAMER option. If it states the value as YES, then the problem is from smth else, if it's NO then you have to build your own opencv version with gstreamer support. Use this website for more info how to compile opencv with gstreamer: https://galaktyk.medium.com/how-to-build-opencv-with-gstreamer-b11668fa09c
12th May 2022, 8:05 PM
Parsa Gharavi
Parsa Gharavi - avatar
0
I give some sleep time and now my video recording is working Parsa Gharavi
13th Jul 2022, 7:58 PM
Anjali Singh
Anjali Singh - avatar