Zulko / moviepy

Video editing with Python
https://zulko.github.io/moviepy/
MIT License
12.49k stars 1.56k forks source link

Concatenation of moviepy.audio.AudioClip.CompositeAudioClip instances #2228

Open Mathemilda opened 1 week ago

Mathemilda commented 1 week ago

Expected Behavior

I want to create a composed Audio.AudioClip instance to attach to my video. I have a method to create notes from frequences, they are concatenated together as a chime, and then I want to use the chimes separated by silence periods for my video.

Actual Behavior

Concatenation of moviepy.audio.AudioClip.CompositeAudioClip instance list produces an error.

Steps to Reproduce the Problem

My code, with my method for chime creation. It uses concatenate_audioclips().

texts = chime_dict.keys()
trial_chimes = []
for txt in texts:
    audioClip = mm.chime_clip(chime_dict[txt]['freq'],
                                      periods=chime_dict[txt]['periods'])
    print(audioClip.duration)
    trial_chimes.append(trial_chimes)

trial_chimes_concat = concatenate_audioclips(trial_chimes)

Here what I see in my console as output:

<class 'moviepy.audio.AudioClip.CompositeAudioClip'>
1.0
<class 'moviepy.audio.AudioClip.CompositeAudioClip'>
1.0
<class 'moviepy.audio.AudioClip.CompositeAudioClip'>
1.0
Traceback (most recent call last):

  Cell In[8], line 11
    trial_chimes_concat = concatenate_audioclips(trial_chimes)

  File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\moviepy\audio\AudioClip.py:315 in concatenate_audioclips
    durations = [c.duration for c in clips]

AttributeError: 'list' object has no attribute 'duration'

Specifications

steinathan commented 5 days ago

your example code looks a bit off, you mean .extend()

trial_chimes.append(trial_chimes)
Mathemilda commented 4 days ago

No. https://docs.python.org/3/tutorial/datastructures.html

steinathan commented 4 days ago

Yes.

image

You're appending trial_chimes back to itself and then concatenating it, some items in trial_chimes wont be Clip but rather Clip | List

look at your indent, you should append audioClip not trial_chimes