If you want second-wise, you can divide the code and check for the first frame of every second (Frames per second)
video = cv2.VideoCapture("INPUT.MOV") try: # creating a folder named data if not os.path.exists('secondWiseData'): os.makedirs('secondWiseData') except OSError: print ('Error: Creating directory of data') currentframe = 0 #Check the version of opencv you are using # Find OpenCV version (major_ver, minor_ver, subminor_ver) = (cv2.__version__).split('.') # if int(major_ver) < 3 : fps = int(video.get(cv2.cv.CV_CAP_PROP_FPS)) #Else fps = int(video.get(cv2.CAP_PROP_FPS)) #The FPS generated could be decimal as well. We get its greatest interger function by casting to int(). print('The FPS of the video is ', str(fps)) time_start=time.time() while(True): # reading from frame ret,frame = cam.read() if ret: # if video is still left continue creating images name = './secondWiseData/frame' + str(currentframe) + '.jpg' if currentframe % fps == 1: print ('Creating...' + name) cv2.imwrite(name, frame) currentframe += 1 continue else: currentframe += 1 continue # increasing counter so that it will # show how many frames are created else: break time_end=time.time() print('Total time taken is ', time_end-time_start) print('Total frames are ', currentframe) #Release all space and windows once done cam.release() cv2.destroyAllWindows()
This will give you the frames of every second in the video considered.
Answer from Kavya Goyal on Stack OverflowFor a project, I want to extract unique/distinctive frames from youtube videos. I tried filtering based on cosine similarity but this took forever and did not really work so well. Is there a technique to filter out the redundant/duplicate frames from a video and only keep one of every unique frame?
Can I extract several frames from the same video?
Yes, after exporting the first frame, return to the timeline and move the playhead to another moment. Select Export Current Frame again and repeat the process for every still you need. You don't have to import the original video again or create a separate project for each image.
Which video formats can I extract frames from?
Flixier works with common video formats, including MP4, MOV, MKV, WMV, and WebM. Import your file, add it to the timeline, and select the moment you want to save.
What does it mean to extract a frame from a video?
Extracting a frame means choosing one image from a video and saving it as a separate file. In Flixier, the exported frame is downloaded as a PNG without the editor interface or playback controls. You can then use it independently in a thumbnail, document, presentation, or social post.
From a credits roll video file like this:
https://i.stack.imgur.com/VM0SG.gif
How can I extract unique frames with ffmpeg? With unique frames I mean next image should start where exactly previous one ended.
Main goal is to then combine them together into one image file which will include all the credits in the roll in one image and I already know how to do with vstack filter. But extracting the required images is the problem.
Thanks.