如何解决将帧从视频文件夹提取到另一个文件夹?
我的文件夹中有大约1000个视频。每个视频都有不同的名称。我想从所有这些视频中提取帧并将它们存储在另一个文件夹中。但我希望这些帧应以与输入视频相同的名称开头。但是,每当我运行我的代码时,它就会覆盖具有相似名称的框架。 这是我的基本代码,用于提取单个视频的帧并将具有相同视频首字母的帧存储到另一个文件夹中。 如何为所有1000个视频进行更改?
import time
import os
def video_to_frames(input_loc,output_loc):
"""Function to extract frames from input video file
and save them as separate frames in an output directory.
Args:
input_loc: Input video file.
output_loc: Output directory to save the frames.
Returns:
None
"""
try:
os.mkdir(output_loc)
except OSError:
pass
# Log the time
time_start = time.time()
# Start capturing the feed
cap = cv2.VideoCapture(input_loc)
# Find the number of frames
video_length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) - 1
print ("Number of frames: ",video_length)
count = 0
print ("Converting video..\n")
# Start converting the video
while cap.isOpened():
# Extract the frame
ret,frame = cap.read()
# Write the results back to output location.
cv2.imwrite(output_loc + "051(%d).jpg" % (count+1),frame)
count = count + 1
# If there are no more frames left
if (count > (video_length-1)):
# Log the time again
time_end = time.time()
# Release the feed
cap.release()
# Print stats
print ("Done extracting frames.\n%d frames extracted" % count)
print ("It took %d seconds forconversion." % (time_end-time_start))
break
input_loc = "C:\\Users\\PycharmProjects\\pythonProject\\051.mp4"
output_loc = "C:\\Users\\PycharmProjects\\pythonProject"
video_to_frames(input_loc,output_loc)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。