0

I am a beginner in python I had this error when I try to write multiple videos for the final video

this is the code

from moviepy.editor import *

# getting video files

video_1 = VideoFileClip(r"C:\Users\shakila\PycharmProjects\autovideomerger\data\samples\inputs\1.mp4").fx(vfx.fadein,3).fx(vfx.fadeout,3)
video_2 = VideoFileClip(r"C:\Users\shakila\PycharmProjects\autovideomerger\data\samples\inputs\2.mp4").fx(vfx.fadein,3).fx(vfx.fadeout,3)
video_3 = VideoFileClip(r"C:\Users\shakila\PycharmProjects\autovideomerger\data\samples\inputs\3.mp4").fx(vfx.fadein,3).fx(vfx.fadeout,3)
video_4 = VideoFileClip(r"C:\Users\shakila\PycharmProjects\autovideomerger\data\samples\inputs\4.ts").fx(vfx.fadein,3).fx(vfx.fadeout,3)
video_5 = VideoFileClip(r"C:\Users\shakila\PycharmProjects\autovideomerger\data\samples\inputs\5.ts").fx(vfx.fadein,3).fx(vfx.fadeout,3)
video_6 = VideoFileClip(r"C:\Users\shakila\PycharmProjects\autovideomerger\data\samples\inputs\6.ts").fx(vfx.fadein,3).fx(vfx.fadeout,3)
video_7 = VideoFileClip(r"C:\Users\shakila\PycharmProjects\autovideomerger\data\samples\inputs\7.ts").fx(vfx.fadein,3).fx(vfx.fadeout,3)


# Make the text.
txt_clip_1 = (TextClip("1",fontsize=50,color='white',font ="Arial-Bold")
             .margin(left=10, top=10, opacity=0) 
             .set_position(("left","top"))
             .set_duration(video_1.duration) )
txt_clip_2 = (TextClip("2",fontsize=50,color='white',font ="Arial-Bold")
             .margin(left=10, top=10, opacity=0) 
             .set_position(("left","top"))
             .set_duration(video_2.duration) )
txt_clip_3 = (TextClip("3",fontsize=50,color='white',font ="Arial-Bold")
             .margin(left=10, top=10, opacity=0) 
             .set_position(("left","top"))
             .set_duration(video_1.duration))
txt_clip_4 = (TextClip("4",fontsize=50,color='white',font ="Arial-Bold")
             .margin(left=10, top=10, opacity=0) 
             .set_position(("left","top"))
             .set_duration(video_1.duration) )
txt_clip_5 = (TextClip("5",fontsize=50,color='white',font ="Arial-Bold")
             .margin(left=10, top=10, opacity=0) 
             .set_position(("left","top"))
             .set_duration(video_1.duration) )
txt_clip_6 = (TextClip("6",fontsize=50,color='white',font ="Arial-Bold")
             .margin(left=10, top=10, opacity=0) 
             .set_position(("left","top"))
             .set_duration(video_1.duration) ),
txt_clip_7 = (TextClip("7",fontsize=50,color='white',font ="Arial-Bold")
             .margin(left=10, top=10, opacity=0) 
             .set_position(("left","top"))
             .set_duration(video_1.duration) )


# Overlay text on video
result_1 = CompositeVideoClip([video_1, txt_clip_1])
result_2 = CompositeVideoClip([video_2, txt_clip_2])
result_3 = CompositeVideoClip([video_3, txt_clip_3])
result_4 = CompositeVideoClip([video_4, txt_clip_4])
result_5 = CompositeVideoClip([video_5, txt_clip_5])
result_6 = CompositeVideoClip([video_6, txt_clip_6])
result_7 = CompositeVideoClip([video_7, txt_clip_7]) 



final_video = concatenate_videoclips([result_1,result_2,result_3,result_4,result_5,result_6,result_7])
final_video.write_videofile( "PressureCoker.mp4",
        threads=8,
        bitrate="16000k",
        audio_codec="aac",
     
    )

basically what i m try to do is get the video file named 1 and place text overlay as "1" in video and add to the compilation when i run it on 2 videos it works fine

this is the error I am getting

Traceback (most recent call last):
  File "c:/Users/shakila/PycharmProjects/autovideomerger/amazon_scraper.py", line 40, in <module>
    result_1 = CompositeVideoClip([video_1, txt_clip_1]),
  File "C:\Users\shakila\PycharmProjects\autovideomerger\venv\lib\site-packages\moviepy\video\compositing\CompositeVideoClip.py", line 84, in __init__
    ends = [c.end for c in self.clips]
  File "C:\Users\shakila\PycharmProjects\autovideomerger\venv\lib\site-packages\moviepy\video\compositing\CompositeVideoClip.py", line 84, in <listcomp>
    ends = [c.end for c in self.clips]
AttributeError: 'tuple' object has no attribute 'end'
MrShakila
  • 874
  • 1
  • 4
  • 19
  • are there extra `,` at the end of various lines of your script for no reason? could you possibly remove those first. Are `video_1` and `txt_clip_1` the correct elements to use in CompositeVideoClip? – Andrew Ryan Oct 19 '22 at 03:40
  • yes I tried them separately and those two work perfectly (ill remove the extra "," and edit now) – MrShakila Oct 19 '22 at 03:44
  • but when i run multiple files it gives the error – MrShakila Oct 19 '22 at 04:14

1 Answers1

0

I fixed it! I'm trying to use .ts video files to merge the video, that's why that happens when I use only mp4 it works

MrShakila
  • 874
  • 1
  • 4
  • 19