Giter Club home page Giter Club logo

Comments (5)

keikoro avatar keikoro commented on September 28, 2024

Please check if the problem persists when you try with pre-release v2.0.0.dev2.

from moviepy.

kaushal101 avatar kaushal101 commented on September 28, 2024

After a number of trial and errors, I was able to make it work once again with 1.0.3, so thought I would share my analysis.

I stripped down all the code and went to very basic, and to my surprise below code worked. So I knew the issue is with some specific part of my original logic, but the basic functionality works.

clip1 = VideoFileClip(r"E:\To be backed up\2019.02 Oxford\PANA5378.MP4").subclip(0, 5).volumex(0.1)
clip2 = VideoFileClip(r"E:\To be backed up\2019.02 Oxford\PANA5379.MP4").subclip(0, 5).volumex(0.1)

clips = []
clips.append (clip1)
clips.append (clip2)
final_clip = concatenate_videoclips(clips, method="compose")
output_video_path = r"c:\kaushal\video projects\test1.mp4"
final_clip.write_videofile(output_video_path, codec="libx264", fps=30)

From here, I started adding back my original logic one after the other, making sure the code works at every point. And this is what is my conclusion. It's the way I'm using subclip functionality that was breaking the process.

If I use the functionality in one single method like below, it is working:

def gen_clips(selected_videos, duration):
    clips = []
    for video_path in selected_videos:
        
        print("processing file: " + video_path)
        try:
            original_duration = get_video_duration(video_path)
            if original_duration > duration:
                start_time = random.uniform(0, original_duration - duration)
                end_time = start_time + duration    # End time in seconds
                clip = VideoFileClip(video_path).subclip(start_time,end_time).volumex(0.4)
                clips.append(clip)
        except Exception as e:
            print(f"Error processing file {video_path}: {e}")
    return clips

But if I'm using the same functionality by calling a different function like below, it doesn't work. This particular methods don't throw any errors, but the final write_videofile method fails with the error from my original post.

def create_video_clip(video_path, start_time, end_time):
    with VideoFileClip(video_path) as clip:
        return clip.subclip(start_time, end_time).volumex(0.1)

def gen_clips(selected_videos, duration):
    clips = []
    for video_path in selected_videos:
        print("processing file: " + video_path)
        
        try:
            original_duration = get_video_duration(video_path)
            if original_duration > duration:
                start_time = random.uniform(0, original_duration - duration)
                end_time = start_time + duration    # End time in seconds
                clip = create_video_clip(video_path, start_time, end_time)
                clips.append(clip)
                #clip.close()
        except Exception as e:
            print(f"Error processing file {video_path}: {e}")
    return clips

I don't fully understand why it's behaving like this, because it's basically the same functionality. Something might be going wrong in handling over the clips from one method to the other perhaps?

from moviepy.

ardyli avatar ardyli commented on September 28, 2024

Exception in thread Thread-7 (audio2video2rtsp):
Traceback (most recent call last):
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
self.run()
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "/data_group/gatkadmin/ai/suziren/Speech2SadTalker/server_Speech2SadTalker_one.py", line 495, in audio2video2rtsp
result = animate_from_coeff.generate(data, save_dir, pic_path, crop_info,
File "/data_group/gatkadmin/ai/suziren/Speech2SadTalker/src/facerender/animate_one.py", line 195, in generate
make_animation(source_image, source_semantics, target_semantics,
File "/data_group/gatkadmin/ai/suziren/Speech2SadTalker/src/facerender/modules/make_animation_one.py", line 584, in make_animation
final_video.write_videofile(file_name, codec='libx264', fps=25, audio_bitrate="24k",bitrate='57k') #, audio_codec='aac'
File "", line 2, in write_videofile
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/decorators.py", line 56, in requires_duration
return f(clip, *a, **k)
File "", line 2, in write_videofile
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/decorators.py", line 135, in use_clip_fps_by_default
return f(clip, *new_a, **new_kw)
File "", line 2, in write_videofile
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/decorators.py", line 24, in convert_masks_to_RGB
return f(clip, *a, **k)
File "", line 2, in write_videofile
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/video/VideoClip.py", line 332, in write_videofile
self.audio.write_audiofile(
File "", line 2, in write_audiofile
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/decorators.py", line 56, in requires_duration
return f(clip, *a, **k)
File "", line 2, in write_audiofile
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/audio/AudioClip.py", line 230, in write_audiofile
return ffmpeg_audiowrite(
File "", line 2, in ffmpeg_audiowrite
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/decorators.py", line 56, in requires_duration
return f(clip, *a, **k)
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/audio/io/ffmpeg_audiowriter.py", line 204, in ffmpeg_audiowrite
for chunk in clip.iter_chunks(
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/audio/AudioClip.py", line 90, in iter_chunks
yield self.to_soundarray(
File "", line 2, in to_soundarray
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/decorators.py", line 56, in requires_duration
return f(clip, *a, **k)
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/audio/AudioClip.py", line 138, in to_soundarray
snd_array = self.get_frame(tt)
File "", line 2, in get_frame
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/Clip.py", line 93, in get_frame
return self.make_frame(t)
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/audio/AudioClip.py", line 320, in make_frame
sounds = [
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/audio/AudioClip.py", line 321, in
c.get_frame(t - c.start) * np.array([part]).T
File "", line 2, in get_frame
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/Clip.py", line 93, in get_frame
return self.make_frame(t)
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/Clip.py", line 136, in
newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/Clip.py", line 187, in
return self.fl(lambda gf, t: gf(t_func(t)), apply_to,
File "", line 2, in get_frame
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/Clip.py", line 93, in get_frame
return self.make_frame(t)
File "/opt/service/miniconda3/envs/pytorch_env/lib/python3.10/site-packages/moviepy/audio/io/AudioFileClip.py", line 88, in
self.make_frame = lambda t: self.reader.get_frame(t)
AttributeError: 'NoneType' object has no attribute 'get_frame'

from moviepy.

ardyli avatar ardyli commented on September 28, 2024

Specifications
Python Version: 3.10.9
MoviePy Version: v2.0.0.dev2.
Platform Name: Linux
Platform Version: Ubuntu Server 22

from moviepy.

ardyli avatar ardyli commented on September 28, 2024

The issue arises when synthesizing video clips from image and audio clips, as the program always checks whether there is a ‘get_frame’ attribute in the audio object. If not, it will raise an error message: AttributeError: ‘NoneType’ object has no attribute ‘get_frame’.

问题出现在用图像片段与音频片段合成视频片段时,程序都会去检测音频对象中有没有get_frame属性。如没有都会抛出AttributeError: 'NoneType' object has no attribute 'get_frame' 出错信息。

from moviepy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.