when read some videos,the func read() hangs
when read some specific videos,the func read() hang,and does not return,i can not exit even i add some signal alarm. video file:
http://nos.netease.com/videocrawler/b...
my code:
video = cv2.VideoCapture(video_path)
rate = int(video.get(cv2.cv.CV_CAP_PROP_FPS))
ret, frame = video.read()
index = 0
while ret:
print "get pic " + str(index)
if index % (rate*interval) == 0:
img = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
img_name = str(index/rate) + '.jpg'
img_path = os.path.join(image_video_path, img_name)
cv2.imwrite(img_path, img)
index += 1
print "read next " + str(index)
try:
signal.signal(signal.SIGALRM, handler)
signal.alarm(1)
ret, frame = video.read()
signal.alarm(0)
except:
print "time out"
ret = False
frame = None
print ret
python
cv2 version : 2.4.13.3
os:Linux version 3.16.0-4-amd64 ([email protected]) (gcc version 4.8.4 (Debian 4.8.4-1) ) #1 SMP Debian 3.16.7-ckt25-2+deb8u3 (2016-07-02)
build from source
@berak. There's something with code as above and something is missing. And
index += 1
andTry
trap could be insideif/else
condition block. But I cannot troubleshooting for him, because I'm using OpenCV 3.3.1. I can merely workaround to OpenCV3.3.1. The code as above is garbage. He is not coding probably.