Reputation: 21
I'm trying to write a program where I iterate through directories, and in each sub directory I create a timelapse with the images inside the folder.
This is what I have for now:
import os
#iterating through directories
RootDir='/home/pi/TestMultFolder/RootDir'
for subdir, dirs, files in os.walk(RootDir)
filepath=subdir
print filepath
#create Timelapse
os.system("avconv -r 10 -i Img_%04d.jpg -r 10 -vcodec libx264 -crf 20 -g 15 timelapse.mp4")
This prints the correct subdirectories, but does not do the timelapse. The timelapse command works if I do it in a single folder. I'm using a Raspberry Pi v3.
Thanks in advance! :)
Upvotes: 1
Views: 204
Reputation: 21
Nevermind found out what was wrong. Here's why for any who's interested:
I simply did not change directory to execute command. So I added an os.chdir(filepath)
import os
#iterating through directories
RootDir='/home/pi/TestMultFolder/RootDir'
for subdir, dirs, files in os.walk(RootDir)
filepath=subdirs+'/'
print filepath
#create Timelapse
os.chdir(filepath)
os.system("avconv -r 10 -i Img_%04d.jpg -r 10 -vcodec libx264 -crf 20 -g 15 timelapse.mp4")
Upvotes: 0
Reputation: 1494
You misused os.walk, waht you call subdir is actually the root directory, you should use it like :
for root, dirs, files in os.walk(RootDir):
and you will find your subdirs in dirs.
Upvotes: -2