
import os
import cv2
videos_src_path="C:/Users/xpp/Desktop/"
video_formats=[".mp4",".mov"]
frames_save_path="C:/Users/xpp/Desktop/"
width=320
height=240
time_interval=50
def video2frame(video_src_path,formats,frame_save_path,frame_width,frame_height,interval):
videos=os.listdir(video_src_path)
def filter_format(x,all_formats):
if x[-4:] in all_formats:
return True
else:
return False
videos=filter(lambda x:filter_format(x,formats),videos)
for each_video in videos:
each_video_name=each_video[:-4]
os.mkdir(frame_save_path+each_video_name)
each_video_save_full_path=os.path.join(frame_save_path, each_video_name)+"/"
each_video_full_path = os.path.join(video_src_path, each_video)
cap=cv2.VideoCapture(each_video_full_path)
frame_index=0
frame_count=0
if cap.isOpened():
success=True
else:
success=False
print("读取失败!")
while(success):
success, frame=cap.read()
if frame_index%interval==0:
resize_frame=cv2.resize(frame,(frame_width,frame_height),interpolation=cv2.INTER_AREA)
cv2.imwrite(each_video_save_full_path+"%d.jpg"%frame_count,resize_frame)
frame_count+=1
frame_index+=1
cap.release()
if __name__=='__main__':
video2frame(videos_src_path,video_formats,frames_save_path,width,height,time_interval)
算法:视频分帧是将视频分成一帧一帧来提取、展示、检索视频中的画面。
文献:D Standards. (1997). Digital video broadcasting (dvb) ; framing structure, channel coding and modulation for digital terrestrial television.
Carrillo, H. , Quiroga, J. , Zapata, L. , & Maldonado, E. . (2022). Automatic football video production system with edge processing. Machine Vision and Applications, 33(2), 1-14.
数据集:https://www.crcv.ucf.edu/data/UCF101.php
https://serre-lab.clps.brown.edu/resource/hmdb-a-large-human-motion-database/#dataset
https://www.di.ens.fr/~laptev/actions/hollywood2/