danaszapiro / EC500

0 stars 0 forks source link

Fixed windows compatibility with ffmpeg #8

Open antpas opened 6 years ago

antpas commented 6 years ago

Function definition to make video from images using Ffmpeg

def make_video():

uses subprocess.call to use the ffmpeg command, also crops images to fit within frame

try:
    os.chdir(r"C:\Users\antth\PycharmProjects\EC500Project2\output")
    for index, oldfile in enumerate(glob.glob("*.jpg"), start=1):
        newfile = 'image{}.jpg'.format(index)
        os.rename(oldfile, newfile)

    os.chdir(r"C:\Users\antth\PycharmProjects\EC500Project2\output")
    os.system('ffmpeg -y -loglevel panic -framerate 1/3 -i image%d.jpg video.avi')

except (RuntimeError, TypeError, NameError):
    print("ERROR: ffmpeg unable to to create video")
    pass
else:
    print("Video done. Saved as out.mp4")
antpas commented 6 years ago

This is hard-coded for my directory on my windows machine.