pythonlinuxdirectoryraspberry-pitimelapse

Create timelapse iterating through directories with Python linux


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! :)


Solution

  • 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")