#videoname是视频的名字,videoPath_root是视频的文件夹路径,pngPath_root是抽出来的帧存储的文件夹路径
def getVideoPng(videoname, videoPath_root, pngPath_root):
if not os.path.exists(pngPath_root):
os.mkdir(pngPath_root)
videopath = os.path.join(videoPath_root, videoname)
vidcap = cv2.VideoCapture(videopath)
fps = int(vidcap.get(cv2.CAP_PROP_FPS))
num_frames = vidcap.get(cv2.CAP_PROP_FRAME_COUNT)
print(num_frames)
print(fps)
n = 0
while n < num_frames:
success, image = vidcap.read()
pngpath = os.path.join(pngPath_root, videoname.split(".")[0], "{}.png".format(j))
if not os.path.exists(os.path.join(pngPath_root, videoname.split(".")[0])):
os.mkdir(os.path.join(pngPath_root, videoname.split(".")[0]))
print(n)
imag = cv2.imwrite(pngpath, image)
n+=1
print("done for {}".format(videoname))
Opencv读取视频帧率
最新推荐文章于 2024-08-27 16:32:25 发布