Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with reader not being defined #950

Closed
davisschenk opened this issue Apr 25, 2019 · 2 comments
Closed

Issue with reader not being defined #950

davisschenk opened this issue Apr 25, 2019 · 2 comments

Comments

@davisschenk
Copy link

I am trying to combine a few sets of AudioFileClip's and ImageClip's into one movie. But am having a weird error, I have spent a long time and tried many things to attempt and get it to work.

I have tried:

  • Creating one combined AudioClip and then adding it to the combined ImageClips instead of adding a bunch of ImageClips that already have audio attached
  • Different ways of putting the clips together such as .set_audio and using a temp audio file when writing the clip to a file
  • Testing a similar situation in the console which worked
  • Searching and searching through moviepy docs and previous questions
from moviepy import editor as mp
from gtts import gTTS
from mutagen.mp3 import MP3


class test:
    def __init__(self):
        self.clips = []

    def add_clip(self, text, picture_path, audio_path):
        tts = gTTS(text)
        tts.save(audio_path)

        duration = MP3(audio_path).info.length

        image_clip = mp.ImageClip(picture_path, duration=duration)
        audio = mp.AudioFileClip(audio_path)
        image_clip = image_clip.set_audio(audio)
        self.clips.append(image_clip)
        audio.close()
        image_clip.close()


t = test()
t.add_clip("Hello", 'screenshots/t3_bgykzb/main.png', 'screenshots/t3_bgykzb/main.mp3')
t.add_clip("Hello", 'screenshots/t3_bgykzb/main2.png', 'screenshots/t3_bgykzb/main.mp3')
t.add_clip("Hello", 'screenshots/t3_bgykzb/main3.png', 'screenshots/t3_bgykzb/main.mp3')

main_clip = mp.concatenate_videoclips(t.clips)
main_clip.write_videofile(f'screenshots/movie.mp4', fps=24)
main_clip.close()

I expect this to output an mp4 file that has 3 clips, each one saying hello using tts. The TTS works fine and outputs an mp3 correctly, it works fine when I comment out the set_audio line, but when I combine all of the clips into a single mp4 it has an error.

AttributeError: 'NoneType' object has no attribute 'get_frame'

Full Error:
https://mystb.in/ulusafajan.rb

None of the objects in the list are None and I am confused why the concatenated clip doesnt have a reader

Any and all help is appreciated! Thanks!

https://stackoverflow.com/questions/55840571/python-moviepy-reader-not-defined-when-writing-video-file

Specifications

  • Python Version: 3.6
  • Moviepy Version: 1.0.0
  • Platform Name: Windows 10 Pro
  • Platform Version: 10.0.17134 Build 17134
@Zulko
Copy link
Owner

Zulko commented Apr 25, 2019

Not sure what is going on. But you shouldn't close the clips in add_clip, in particular the audio clips. Keep in mind that the clips are not fully read until you run "write_videofiles()" so you can't close them until your final clip is written.

@davisschenk
Copy link
Author

Thanks that seemed to fix it, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants