0

im writing a code which takes inputs from user to get paths of video files the user want to concatenate. now if the user has 5 videos which they want to concatenate and make one file out of them, my program does a good job getting all the videofile paths and stores them in a list. but the issue is I cant concatenate them using moviepy while they are in a list. this is the code

from moviepy.editor import VideoFileClip, concatenate_videoclips
listofpath=[]
no_vid = int(input('enter no of vid u wanna compile:  '))
for i in range(no_vid):
    vidpath = input('enter path to the files u wanna compile:  ')
    listofpath.append(vidpath)
print(listofpath)

final_clip = concatenate_videoclips([listofpath])
final_clip.write_videofile("E:\python_work\downloaded\my_concatenation.mp4")
user438383
  • 5,716
  • 8
  • 28
  • 43
ali abid
  • 11
  • 2
  • Change `listofpath.append(vidpath)` to listofpath.append(VideoFileClip(vidpath))` should fix the issue – Jay Dec 12 '22 at 12:29

1 Answers1

0
from moviepy.editor import VideoFileClip, concatenate_videoclips

listofpath=[]
no_vid = int(input('enter no of vid u wanna compile:  '))
for i in range(no_vid):
    vidpath = input('enter path to the files u wanna compile:  ')
    listofpath.append(vidpath)
print(listofpath)

Create a list of VideoFileClip objects

clips = [VideoFileClip(file) for file in listofpath]

Concatenate the clips

final_clip = concatenate_videoclips(clips)

Then write the video

final_clip.write_videofile("E:\python_work\downloaded\my_concatenation.mp4")
Packet
  • 11
  • 4