赞
踩
转载注明出处谢谢
# -*- coding: utf-8 -*- import shutil import numpy as np import cv2 import os from multiprocessing import Pool def do_capture(src_path, path, name): output_path = path + os.sep + name if not os.path.exists(output_path): os.mkdir(output_path) else: print("folder exists") cap = cv2.VideoCapture(src_path + os.sep + name) # videoFPS = int((cap.get(cv2.CAP_PROP_FPS))) # print(videoFPS) count = 1 while True: ret, frame = cap.read() # show a frame if ret is True: # print(frame.shape) count = count + 1 # print(count) if count % 12 == 0: # 设置抽帧间隔,fps=25,每秒抽2帧 cropped = frame[360:1080, 0:1920] # 裁剪坐标为[y0:y1, x0:x1] output_name = os.path.join(output_path, str(int(count / 12)) + ".jpg") cv2.imwrite(output_name, cropped) else: break print("finished") cap.release() # cv2.destroyAllWindows() if __name__ == "__main__": videos_src_path = r'E:\records\long' # 提取图片的视频文件夹 output_root_path = r'.\records_capture' # 保存图片的路径 # 视频列表 videos_dir = list(filter(lambda x: x.endswith('mp4'), os.listdir(videos_src_path))) # 筛选出mp4格式 #多线程处理 num_worker = 1 file_list_arr = np.array_split(videos_dir, num_worker) p_no = 0 pool = Pool(processes=num_worker) for video_name in videos_dir: # 循环读取路径下的文件并筛选输出 if os.path.splitext(video_name)[1] == ".mp4": # 筛选mp4文件 print(video_name) # 输出所有的mp4文件 # break pool.apply(do_capture, args=(videos_src_path, output_root_path, video_name)) pool.close() pool.join() print("done!")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。