I have tried to preview a clip with a subtitle. But I have a error that says :
AttributeError: 'CompositeAudioClip' object has no attribute 'fps'
`from moviepy.editor import *
from moviepy.video.tools.subtitles import SubtitlesClip
# Load the video clip
video_clip = VideoFileClip("H:/movie/A.Quiet place/1.mkv")
# Define a text generator function for the subtitles
def txt_gen(txt):
return TextClip(txt, font='Times new roman - bold', fontsize=36, color='white')
# Define the subtitle start and end times and text
sub_start_time = 0.2
sub_end_time = 5
sub_text = "This is the subtitle text"
# Create a list of subtitle tuples
subs = [((sub_start_time, sub_end_time), sub_text)]
# Create a SubtitlesClip object from the subtitle tuples and text generator
subtitles = SubtitlesClip(subs, txt_gen)
# Set the subtitle position
subtitles = subtitles.set_pos(('center', 'bottom'))
# Create a composite video clip with the video and subtitles
composite_clip = CompositeVideoClip([video_clip, subtitles])
# Preview the composite clip with subtitles
composite_clip.preview(fps=composite_clip.fps)
# Close the video preview window
composite_clip.close()`
my complete error :
Exception in thread Thread-10 (preview):
Traceback (most recent call last):
File "C:\Users\kian\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 1038, in _bootstrap_inner
self.run()
File "C:\Users\kian\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "<decorator-gen-118>", line 2, in preview
File "C:\Users\kian\AppData\Local\Programs\Python\Python311\Lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
^^^^^^^^^^^^^^^^
File "C:\Users\kian\AppData\Local\Programs\Python\Python311\Lib\site-packages\moviepy\audio\io\preview.py", line 49, in preview
sndarray = clip.to_soundarray(tt, nbytes=nbytes, quantize=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<decorator-gen-62>", line 2, in to_soundarray
File "C:\Users\kian\AppData\Local\Programs\Python\Python311\Lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
^^^^^^^^^^^^^^^^
File "C:\Users\kian\AppData\Local\Programs\Python\Python311\Lib\site-packages\moviepy\audio\AudioClip.py", line 107, in to_soundarray
fps = self.fps
^^^^^^^^
AttributeError: 'CompositeAudioClip' object has no attribute 'fps'
using video_clip.preview (in moviepy library) u can preview clip file . this works fine any operates as expected.
but when I add a subtitle to that clip I can't preview it anymore and I get the errors above.
composite_clip is [video_clip file + subtitle]
I can save composite_clip somewhere and open it with a players like potplayer. but I cant Preview it in my program.