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

MemoryError #259

Closed
chicagobools opened this issue Feb 8, 2016 · 3 comments
Closed

MemoryError #259

chicagobools opened this issue Feb 8, 2016 · 3 comments

Comments

@chicagobools
Copy link

I am seeing a memory error when using (I assume from past questions) VideoFileClip. Like other people, my first workaround was to split the job up into multiple files, however that still did not stop the memory error.

Have tried del var and delete var.reader with no success.

Here is the code with no del

[Problem somewhere in here]
loop:

  • read in 10 video subclips
  • add text over it
  • concatenate
  • write to file
    end loop

[This part is working fine]

  • load all video subclips
  • concatenate and write to file
`files = [f for f in os.listdir(path.relpath('mymovies/'))]

instances = open('bowie.txt', 'r')

video_num = 0
clip_count = 0
video = []
for line in instances:
    data = ast.literal_eval(line)
    ngram = str(data[0])
    srt = str(data[1][0]).strip()
    stamp = str(data[1][1]).strip()

    if clip_count < 10:
        if stamp[0].isdigit():
            ts = stamp.split(' --> ')
            start = getTime(ts[0])
            end = getTime(ts[1])
            film = 'mymovies/'+getMovie(srt, files)

            clip = VideoFileClip(film).subclip(start, end)
            txt = TextClip(ngram, fontsize=30, color='white')
            txt = txt.set_pos(("center","top")).set_duration(int(end) - int(start))
            vid = CompositeVideoClip([clip,txt], size=(1280,720))
            video.append(vid)
            clip_count += 1
    else:
        final = concatenate(video)
        vid_name = "bowie/spaceoddity_"+str(video_num)+'.mp4'
        final.write_videofile(vid_name, fps=24, codec='mpeg4', bitrate='2000k')
        clip_count = 0
        video_num+=1
        #clean up?
        time.sleep(5)

print '****FINISHED PARSING****'
print '****CONCATENATING VIDEOS****'

clips = ['bowie/spaceoddity_'+str(i)+'.mp4' for i in range(video_num)]

group = []

for clip in clips:
    group.append(VideoFileClip(clip))

final = concatenate(group)

final.write_videofile('bowie/final_spaceoddity.mp4', fps=24, codec='mpeg4')#, bitrate='2000k')`

The video files themselves are between 600MB and 1GB.
The purpose of this is to run a file containing ngrams and their occurrences in movies provided by an SRT file to create a video with the audio.

Python 2.7
Latest version of moviepy
Windows 7 64

@chicagobools
Copy link
Author

Running the above code without using TextClip and CompositeVideoClip (appending 'clip' straight to video list) gives me absolutely no memory errors. --> see EDIT

Ran again this time only without TextClip and saw no memory errors.

Error seems to be in the way I am using TextFileClip?

EDIT: I was wrong.

If my video sizes are different, using CompositeVideoClip.. size = (x, y) keeps the video's original size and uses black for the rest of the pixels (which is good visually). Is this the problem?

@chicagobools
Copy link
Author

Updating to say switching to Python 64bit seems to be a fix for this case.

@mattvenn
Copy link

With python2, and this program:
https://github.com/mattvenn/moviepy-test/blob/master/moviepy_demo.py

The computer runs out of ram after adding the first 10 files (combination of videos and images). My pc has 8gb of ram, and about half is available for moviepy.

I tried the same program and files with moviepy and python3, which uses about 2gb but succeeds.

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