Extracting image from video at a given time using OpenCV

后端 未结 3 2032
深忆病人
深忆病人 2021-02-01 09:39

My task is to make a utility that can take a video and time in seconds.

The utility should write out jpeg images from the video with the given input.

E.g. let th

3条回答
  •  礼貌的吻别
    2021-02-01 10:10

    # Import the necessary packages
    import cv2
    
    vidcap = cv2.VideoCapture('Wildlife.mp4')
    success,image = vidcap.read()
    print success
    #cv2.imwrite("frame.jpg", image) 
    
    count = 0
    framerate = vidcap.get(5)
    print "framerate:", framerate
    framecount = vidcap.get(7)
    print "framecount:", framecount
    vidcap.set(5,1)
    newframerate = vidcap.get(5)
    print "newframerate:", newframerate  
    
    while success:
      success,image = vidcap.read()
      #cv2.imwrite("frame%d.jpg" % count, image) 
    
      getvalue = vidcap.get(0)
      print getvalue
      if getvalue == 20000:
        cv2.imwrite("frame%d.jpg" % getvalue, image)  
    
      #if cv2.waitKey(10) == 27:                     
          #break
      count += 1
    

    The output is as follows

    framerate: 29.97002997
    framecount: 901.0
    newframerate: 29.97002997
    

    Why frame rate is not changing.I want to change frame rate to 1 so that whatever time value user gives i should be able to get image frame.

提交回复
热议问题