我想将视频文件从1个文件夹移到各个子文件夹
我制作了从帧制作视频的脚本。它可以正确创建多个视频,但只能在一个特定路径上。下面是代码
def frames_to_video(detected_object_input,video_op,fps):
folders=glob(detected_object_input)
img_list=[]
frame_array=[]
for folder in folders:
folder_name=os.path.basename(folder)
vid_ext=".mp4"
vid_name = folder_name+vid_ext
final_op=video_op+"\\"+vid_name
#print(final_op)
for f in glob(folder+"/*jpg"):
img_list.append(f)
for i in range(len(img_list)):
filename = img_list[i]
img=cv2.imread(img_list[i])
height,width,layers=img.shape
size=(width,height)
print(filename)
frame_array.append(img)
out = cv2.VideoWriter(final_op,cv2.VideoWriter_fourcc(*'DIVX'),fps,size)
for i in range(len(frame_array)):
out.write(frame_array[i])
out.release()
detected_object_input= ("C:\\new_multi_cat\\models\\research\\object_detection\\my_imgs\\*")
video_op= ("C:\\new_multi_cat\\models\\research\\object_detection\\my_imgs")
fps= 2
frames_to_video(detected_object_input, video_op, fps)
假设有文件夹X。它有多个子文件夹,如A,B,C。我的代码根据文件夹的名称制作视频文件,即videoA,videoB,videoC等。但是这些视频是在文件夹X中创建的。我希望这些视频文件可以在其各自的子文件夹中创建,例如子文件夹A内的videoA,子文件夹B内的videoB等。