【发布时间】:2019-04-06 20:36:00
【问题描述】:
我想从 3 个视频中提取帧到 3 个不同的文件夹中。每个文件夹都有相应视频文件的帧。我只能访问第三个视频的目标。如何也提取前 2 个视频的帧
到目前为止,我已经根据视频文件创建了具有名称的文件夹。开发了帧提取代码,但只能从最后一个视频中提取。下面是我的代码
import cv2
import glob
from glob import glob
import os
import shutil
def extractFrames(m,n):
if not os.path.exists:
os.makedirs(n)
vid_files=glob(m)
print(vid_files)
for v_f in range(len(vid_files)):
v1=os.path.basename(vid_files[v_f])
print(v1)
vid_name = os.path.splitext(v1)[0]
print(vid_name)
output = n +'\\video_' + vid_name
os.makedirs(output)
print(output)
vidcap = cv2.VideoCapture(vid_files[v_f])
print(vidcap)
success,image = vidcap.read()
seconds = 2
fps = vidcap.get(cv2.CAP_PROP_FPS) # Gets the frames per second
multiplier = fps * seconds
count=0
while success:
img_name = vid_name + '_f' + str(count) + ".jpg"
image_path = output + "/" + img_name
frameId = int(round(vidcap.get(1)))
success,image = vidcap.read()
if frameId % multiplier == 0:
cv2.imwrite(filename = image_path, img = image)
count+=1
vidcap.release()
cv2.destroyAllWindows()
print('finished processing video {0} with frames {1}'.format(vid_files[v_f], count))
return output
x=("C:\\Python36\\videos\\*.mp4")
y=("C:\\Python36\\videos\\videos_new")
z=extractFrames(x,y)
如果有 3 个视频,即 video1,video2,video3。我想将相应的帧提取到它们的特定文件夹中,即 video1 文件夹、video2 文件夹、video3 文件夹。目前,我只能将第三个视频的帧提取到文件夹 video3 中。我怎样才能为video1和video2做到这一点
【问题讨论】:
-
您缺少的一件事是
if not os.path.exists:中的参数。这应该指定哪个目录:if not os.path.exists(n):. -
@NielsHenkens 我试过这个,看起来这与从视频中提取帧到特定文件夹无关。如何将视频帧提取到相应的文件夹中。我认为这与循环有关