0

I'm using this method to pick random files of a certain type from a folder a user inputs, and then concentate them together in MoviePy:

 filename = glob.glob(input +"/*.mp3")
sdofjsodfj = random.choice(filename)
aclips.append(AudioFileClip(sdofjsodfj))
random.shuffle(aclips)
filename = glob.glob(input + "/*.mp4")
clipname = random.choice(filename)
lend = random.uniform(.5, VideoFileClip(clipname).duration)
end = clipname
finalclip = VideoFileClip(end).subclip(lend - .5, lend).fx(vfx.speedx, random.uniform(.54, 3)).resize((250, 250))

However, this method sometimes works, but most of the time returns this error:

IndexError: Cannot choose from an empty sequence

Is there a reason why it would be doing this?

queddd
  • 1

1 Answers1

0

It simply means there are no .mp4 files in the directory you globbed (you may possibly have other file types in there but not mp4). And so an empty list is returned as filename.

Seyi Daniel
  • 2,259
  • 2
  • 8
  • 18
  • But I have tons of mp4s and mp3s in there... and sometimes it finds them in the glob but other times it doesn't for whatever odd reason – queddd Aug 31 '20 at 14:59