Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python function to read video and convert to frames

I want to convert my input video to a set of frames. I have read the post on Python - Extracting and Saving Video Frames.

But I would like to have a function where I can insert the video as the parameter, not the location of the video file.

In the VideoCapture function below, it takes in the location of the video file.

import cv2
def vidtoframes(videoFile):
 vidcap = cv2.VideoCapture(videoFile)
 success,image = vidcap.read()
 count = 0

 while success:
  cv2.imwrite("frame%d.jpg" % count, image) # save frame as JPEG file      
  success,image = vidcap.read()
  print('Read a new frame: ', success)
  count += 1

But is there a function or way to pass a video to the method and convert it to array of frames without saving anything onto the disk.

like image 590
john Avatar asked Jul 02 '26 05:07

john


1 Answers

The video that is taken must be saved to a directory and then we can perform the functions upon it. That is how an application would work as well.

like image 104
hidrana jiglle Avatar answered Jul 04 '26 21:07

hidrana jiglle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!