convert all image into separate video using moviepy python

Viewed 23

I have 10 images in a folder under current directory of where my python script is stored. I want to convert all my 10 images into 10 videos with the same file name (or) existing filename+suffix(somename).mp4 . The problem is the below script is converting either all images into one video or erroring out. Need help to fix my problem .

Error : Traceback (most recent call last): File "1.py", line 17, in video.write_videofile(filename, prefix+".mp4", fps=24) TypeError: write_videofile() got multiple values for argument 'fps'

    import os
    from moviepy.editor import *
    base_dir = os.path.realpath(".")
    print(base_dir)
    directory=sorted(os.listdir('.'))
    print(directory)
    clips = []
    for filename in directory:
      if filename.endswith(".jpg"):
        prefix = filename.split(".jpg")[0]
        clips.append(ImageClip(filename).set_duration(1))
    print(clips)
    video = concatenate(clips, method="compose")
    video.write_videofile(filename, prefix+".mp4", fps=24)
1 Answers

The error is complaining that it is receiving to many arguments.

Try running the write_videofile without the filename argument. The signature only accepts one positional argument which should be the file you are writing to.

video.write_videofile(prefix+".mp4", fps=24)

docs

Related