I'm using OpenCV python to capture a video. This is my code
import cv2
cap = cv2.VideoCapture("vid.mp4")
while True:
flag, frame = cap.read()
if not flag:
cv2.imshow('video', frame)
if cv2.waitKey(10) == 27:
break
When a frame is not ready it produces an error like this

or
Truncating packet of size 2916 to 1536
[h264 @ 0x7ffa4180be00] AVC: nal size 2912
[h264 @ 0x7ffa4180be00] AVC: nal size 2912
[h264 @ 0x7ffa4180be00] no frame!
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7ffa41803000] stream 0, offset 0x14565: partial file
I wanted to find a way to hide this error! I guess that this error is being produced by ffmpeg. Is there any way to hide or disable it?
This error is produced when I call cap.read(). And I also tried to wrap it with try ... except ... but it doesn't work because it doesn't throw any exceptions.