-1

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
    Can you confirm or send us documentation on what the `concatenate` function does? From looking at documentation, concatenate would be to mix clips (in this case your images) together. – PythonKiddieScripterX Sep 17 '22 at 08:36

1 Answers1

0

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

Alexander
  • 16,091
  • 5
  • 13
  • 29
  • `video.write_videofile(prefix+".mp4", fps=24)` when i tried this with two files "image 1 & image 2" the output is image2.mp4 video . The video contains both the images inside (image1 & image 2) .... not as separate files.... I am struggling with for loop condition here .. – The Analyser Sep 17 '22 at 08:23
  • 1
    @TheAnalyser, that's another question. Please do not ask follow-up questions in comments, that's not what Stack Overflow is intended for. You might want to take the short [tour] and/or read [ask] to make sure you understand how the site works. The answer of Alexander seems the correct answer to the question you posted above. See also [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers). – wovano Sep 17 '22 at 08:46