Ask Your Question

Revision history [back]

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/b20c92f962f9d51dc56e15749b1cd894.mp4

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)