Python函数读取视频并转换为帧 [英] Python function to read video and convert to frames

查看:75
本文介绍了Python函数读取视频并转换为帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的输入视频转换为一组帧.我已经阅读了帖子Python - 提取和保存视频帧.

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.

在下面的 VideoCapture 函数中,它接收视频文件的位置.

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.

推荐答案

拍摄的视频必须保存到一个目录中,然后我们才能对其执行功能.这也是应用程序的工作方式.

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.

这篇关于Python函数读取视频并转换为帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆