12345678910111213141516171819202122232425262728293031323334353637383940 |
- import argparse
- import os
- import uuid
- import datetime
- import cv2
- from tqdm import tqdm
- def work(video_folder, output_folder, interval):
- if not os.path.exists(output_folder):
- os.makedirs(output_folder)
- video_list = os.listdir(video_folder)
- num = 1
- cnt = 1
- for video in tqdm(video_list):
- video_path = video_folder + '/' + video
- vid = cv2.VideoCapture(video_path)
- time = datetime.datetime.now()
- t = str(time.year).zfill(4) + '-' + str(time.month).zfill(2) + '-' + str(time.day).zfill(2)
- while vid.isOpened():
- is_read, frame = vid.read()
- if is_read:
- if num % interval == 0:
- file_name = '%04d' % cnt
- cv2.imwrite(output_folder + '/' + 'kdan_' + t + '_' + str(file_name) + '_' + str(uuid.uuid1())[0:4] + '.jpg', frame)
- # 00000111.jpg 代表第111帧
- cv2.waitKey(1)
- cnt += 1
- num += 1
- else:
- break
- if __name__ == '__main__':
- parser = argparse.ArgumentParser()
- parser.add_argument('--video_folder', type=str, default='./video/01')
- parser.add_argument('--output_folder', type=str, default='./video_frame')
- parser.add_argument('--interval', type=int, default=10, help='帧率间隔')
- args = parser.parse_args()
- work(args.video_folder, args.output_folder, args.interval)
|