I hope the question is clear enough. Basically I have an array "output" containing all the folders I will utilize (as shown below):
output = ['folder1', 'folder2', 'folder3', 'folder4']
I want to create a video for all the subfolders. I can manage to do it if I just create a video with all the videos, but not when I want to create a video from the videos of each folder. the following code I used to compile all the .mp4 files into one video:
from moviepy.editor import *
import os
from natsort import natsorted
L =[]
for root, dirs, files in os.walk("/media/pi/videos"):
#files.sort()
files = natsorted(files)
for file in files:
if os.path.splitext(file)[1] == '.mp4':
filePath = os.path.join(root, file)
video = VideoFileClip(filePath)
L.append(video)
final_clip = concatenate_videoclips(L)
final_clip.to_videofile("output.mp4", fps=24, remove_temp=False)
But when I try to do the same thing over a for loop I get errors and cannot manage to get my head around what is wrong. Any help is sincerely appreciated. This is the code I have been trying to get to work:
output.sort()
for i in output:
if not i == 'System Volume Information':
path2 = '/media/pi/videos/%s' % i
L =[]
for root, dirs, files in os.walk(path2):
#files.sort()
files = natsorted(files)
for file in files:
if os.path.splitext(file)[1] == '.mp4':
filePath = os.path.join(root, file)
video = VideoFileClip(filePath)
L.append(video)
final_clip = concatenate_videoclips(L)
final_clip.to_videofile("output.mp4", fps=24, remove_temp=False)
Basically What I am trying to do is combine a certain amount of videos. I have renamed all my .mp4 files to "1.mp4" "2.mp4" "3.mp4" etc, and I am am trying to make the code combine lets say 5 .mp4 files for 1 video and would go in a for loop until there are no more videos to combine. This is the only way I could think of doing it. I have made subfolders containing 5 .mp4 files and now I am trying to combine these videos for each folder. This, I believe, is not very efficient so any better advice would be helpful