python-对一个目录下的多个视频进行抽帧

# --*-- coding: utf-8 --*--
import os
import sys
import cv2

gef getFrame(srcRoot,saveRoot):
    fileList = os.listdir(srcRoot)
    for i in range(len(fileList))
        tmpName = 0
        frameFrequency = 5  # 每5帧抽1帧
        if not fileList[i].endswith('.mkv'):
            continue
        filePath = srcRoot + '\\'+ fileList[i] # .\DK\0-1.mkv
        print(filePath)
        if not os.path.exists(saveRoot):
            os.makedirs(saveRoot)
        single_path = os.path.join(saveRoot, fileList[i].split('.')[0])
        if not os.path.exists(single_path):
            os.makedirs(single_path)
        videoFile = cv2.VideoCapture(filePath)  # 打开视频
        while True:
            tmpName += 1
            res, image = videoFile.read()  # 按帧读取视频
            if not res:
                print('not res , not image')
                break
            if tmpName % frameFrequency == 0:
                save_path = os.path.join(single_path, str(tmpName)+'.jpg')
                cv2.imwrite(save_path, image)
                print(save_path, 'save done!')
        print(i, filePath + '图片提取结束')
        videoFile.release()

videoPath = sys.argv[1] # .\DK
saveRoot = sys.argv[2]  # .\DK_Sampling_5Frame
getFrame(videoPath,saveRoot)
#useage: python GetFrame.py videoPath saveRoot

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值