when read some videos,the func read() hangs

asked 2017-11-17 00:54:24 -0600

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)

edit retag flag offensive close merge delete

Comments

  • how did you install your cv2 ? (never trust your ppm !)
  • be careful with video props, like CAP_PROP_FPS, it might not be supported, and return 0
  • your try/catch block looks useless, it won't raise anything
berak gravatar imageberak ( 2017-11-17 01:13:12 -0600 )edit

build from source

district9 gravatar imagedistrict9 ( 2017-11-17 01:23:14 -0600 )edit

@berak. There's something with code as above and something is missing. And index += 1 and Try trap could be inside if/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.

supra56 gravatar imagesupra56 ( 2017-11-17 07:34:04 -0600 )edit