| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import os
- from tracemalloc import start
- import cv2
- import glob
- import numpy as np
- # 视频来源 地址需要替换自己的可识别文件地址
- # videoPath = '/Users/gemer/Desktop/test-video'
- # folders = glob.glob('/Users/gemer/Desktop/test-video-1')
- folders = sorted(filter(os.path.isfile,
- glob.glob('/Users/gemer/Desktop/test-video-1' + '/*.264', recursive=True)))
- imagePath = '/Users/gemer/Desktop/test-video-1/image/'
- videonames_list = []
- print('list_of_files', folders)
- for folder in folders:
- videonames_list.append(folder)
- print(folder)
- print('There are {} videos in Folder'.format(len(videonames_list)))
- filePath = '/Users/gemer/Desktop/'
- out_video = np.empty([30, 1920, 1080, 3], dtype=np.uint8)
- out_video = out_video.astype(np.uint8)
- start_frame = 12
- count = 0
- # for i in range(0, len(videonames_list)):
- # video_data = videonames_list[i]
- # video = cv2.VideoCapture(video_data)
- # success = True
- # while success:
- # success, image = video.read()
- # name = imagePath + str(i) + '-' + str(count)+'.jpg'
- # if success == True:
- # if count == 10:
- # cv2.imwrite(name, image)
- # print('video {} '.format(i))
- # print('Frame {} Extracted Successfully'.format(count))
- # count += 1
- # else:
- # count = 0
- # print('\n\n\nVideo {} Extracted Successfully\n\n\n'.format(video_data))
- caps = [cv2.VideoCapture(i) for i in videonames_list]
- print('cap', caps)
- frameCount = 0
- vidIndex = 0
- # for vid in caps:
- for index, vid in enumerate(caps):
- # print(x)
- fourcc = cv2.VideoWriter_fourcc('H', '2', '6', '4')
- size = (int(vid.get(cv2.CAP_PROP_FRAME_WIDTH)),
- int(vid.get(cv2.CAP_PROP_FRAME_HEIGHT)))
- fps = vid.get(cv2.CAP_PROP_FPS) # 30p/self
- fps = int(fps)
- hz = int(1000.0 / fps)
- sizeStr = str(size[0]) + 'x' + str(size[1])
- print('index {}'.format(index))
- while(True):
- success, image = vid.read()
- if success == True:
- name = imagePath + str(frameCount)+'.jpg'
- cv2.imwrite(name, image)
- print('Frame {} Extracted Successfully'.format(frameCount))
- frameCount += 1
- else:
- frameCount = 0
|