Python function to read video and convert to frames

五迷三道 提交于 2019-12-12 17:34:45

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/51215625/python-function-to-read-video-and-convert-to-frames

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!