Hello everyone , I meet you again , I'm your friend, Quan Jun .
#! encoding: UTF-8
import os
import cv2
import cv
videos_src_path='/sata_disk/E_office/zhouhongli/pig/train'
images_save_path='/sata_disk/E_office/zhouhongli/pig/frame'
videos = os.listdir(videos_src_path)
videos = filter(lambda x: x.endswith('mp4'), videos)
for each_video in videos:
print each_video
# get the name of each video, and make the directory to save frames
each_video_name,_=each_video.split('.')
os.mkdir(images_save_path +'/'+ each_video_name)
each_video_save_full_path=os.path.join(images_save_path, each_video_name) + '/'
# get the full path of each video, which will open the video tp extract frames
each_video_full_path=os.path.join(videos_src_path, each_video)
cap=cv2.VideoCapture(each_video_full_path)
frame_count = 1
success = True
while(success):
success, frame=cap.read()
print 'Read a new frame: ', success
params = []
params.append(cv.CV_IMWRITE_PXM_BINARY)
params.append(1)
cv2.imwrite(each_video_save_full_path + each_video_name + "_%d.jpg" % frame_count, frame, params)
frame_count = frame_count+1
cap.release()
But there's a problem , Every video conversion results in 30 In the subfolder , There are 2952 A picture , But the first 2952 Zhang Shikong , So only use the powerful Linux Recursively delete the eligible files , I delete drops like this .
[email protected]:~$ find . -name '*_2952.jpg' -size 0 -print0 |xargs -0 rm
python tools: Extract and save each frame of the video http://blog.csdn.net/u010167269/article/details/53268686 Linux find And rm Delete the eligible files in linkage https://maoxian.de/2015/12/1362.html
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/151885.html Link to the original text :https://javaforall.cn