Ask Your Question

Revision history [back]

Unable to extract frames from video file

Hi All,

when i am trying to extract images from a video file, it is keep on extracting images and counter does not stop. For eg: I am using video file of 25fps and of 41 second duration. So the count is coming approximately 1025. But my code is not stopping after 1025 and it keeps on extracting empty images after 1025. Please check my code and help me out.

import cv2

import cv2.cv as cv

import sys

import os

import numpy as np

import PIL

from matplotlib import pyplot as plt

invideo1 = cv.CaptureFromFile("flower.mp4")

totalNumberOfFrames1 = int(cv.GetCaptureProperty(invideo1, cv.CV_CAP_PROP_FRAME_COUNT)) framesprocessing1 = totalNumberOfFrames1 print(totalNumberOfFrames1)

count =0;

while (True):

im1 = cv.QueryFrame(invideo1)

cv.SaveImage('c://Shweta//opencv_poc//video1//frames1//pic'+str(count)+'.jpg', im1)

if cv.WaitKey() == 27: # ASCII 27 is the ESC key
    break
count +=1

del invideo

cv.DestroyWindow(winname)