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

Out of memory exception #862

Closed
Morketh opened this issue Oct 20, 2018 · 4 comments
Closed

Out of memory exception #862

Morketh opened this issue Oct 20, 2018 · 4 comments

Comments

@Morketh
Copy link

Morketh commented Oct 20, 2018

System is running out of memory while trying to combine PNG files (7200 frames at 1920x1080) output from PovRay to produce an Mp4 animation. Issue #827 looks possibly related.

import os, math
from vapory import *
from moviepy.editor import *

"""
Kinematic Logo Animation
By: Andrew Malone
"""

## SETTINGS ##

SceneName = "GreenGear"
ImgWidth = 1920
ImgHeight = 1080
AnimationTime = 60 # seconds
FPS = 120
CAM_TYPE = 2 # see CamType() for a list of camera definitions

# starting frame for animations this MUST satisfy 0 < FRAMENUMBER < MAX_FRAMES
# As long as this is true any animation sequence (or subset) can be rendered
FRAMENUMBER = 0

# SCENE GLOBALS #
CWD = os.getcwd()

## Internal Variables ##
MAX_FRAMES = AnimationTime*FPS
OutputFileName = "{}_{}-frames_{}-FPS".format(SceneName,MAX_FRAMES,FPS)
ImageFrmtStr = "{}-{:03}.png"
ImageDir = CWD+"\\img\\"
Mp4Dir = CWD+"\\mp4\\"

# speed 120 FPS
# 't' is pos at time
def CamType(i,fps,frame):
    """Returns camera at time if i == 2 elif i == 1 static cam """
    step=1
    iy = 25
    fy = iy+6.5
    ix = -30
    fx = 0
    iz = -30
    fz = 0
    
    y = iy + (fy-iy)*0.5*frame
    x = ix + (fx-ix)*0.5*frame
    z = iz + (fz-iz)*0.5*frame
    
    #
    if i == 1: # Static Cam
        return Camera('angle', 45, 'location', [0.0 , 1.0,-2.0], 'look_at', [0 , 1.0 , 0.0])
    elif i == 2: # Animated Cam
        return Camera('angle', 45, 'location', [-35.0 , 25.0 ,-30.0], 'look_at', [0 , 1.0 , 0.0])

# Generic sun object located at x,y,z
sun = LightSource([-900,2500,-3500], 'color', 'White')

# Colors and Textures #
CI_ColorMap = ColorMap([0.0,  'rgb', [0.0, 0.0, 0.0]],
                       [0.7,  'rgb', [0.0, 0.3, 0.0]],
                       [0.5,  'rgb', [0.0, 0.7, 0.0]],
                       [0.6,  'rgb', [0.0, 0.2, 0.0]],
                       [0.65, 'rgb', [0.0, 1.0, 1.0]],
                       [0.75, 'rgb', [0.0, 0.2, 0.0]],
                       [0.8,  'rgb', [0.0, 0.5, 0.0]],
                       [1.0,  'rgb', [0.0, 1.0, 0.0]])

CI_Plasma_Marble = Pigment('marble', 'turbulence', 2.75, CI_ColorMap, 'scale', 2.5, 'rotate', [0, 7.5 ,0])
# End of Colors and Textures #

# Define a Wheel Object #
WheelH = 1
WheelRadius = 2
SpokeW = (WheelRadius*2)+2
SpokeAngle = 360/3

## Static Objects ##
Axel = Cylinder([0,-(WheelH/2),0], [0,(WheelH/2),0], WheelRadius)
# Start -x -y -z End x y z
Spoke = Box([-SpokeW/2,-(WheelH/2),0.5],[SpokeW/2,(WheelH/2),-0.5])

Frames = []
## Scene Animation ##
while FRAMENUMBER < MAX_FRAMES:
    FRAMENUMBER += 1
    print("Rendering Frame: {} of {}".format(FRAMENUMBER,MAX_FRAMES))
    Wheel = Object(Union(Axel,
                   Object(Spoke,'rotate',[0,SpokeAngle*1,0]),
                   Object(Spoke,'rotate',[0,SpokeAngle*2,0]),
                   Object(Spoke,'rotate',[0,SpokeAngle*3,0])
                   ), Texture(CI_Plasma_Marble), 'rotate', [0,((360*24)/MAX_FRAMES)*FRAMENUMBER,0])


# End of Wheel Object #

    scene = Scene( CamType(CAM_TYPE,FPS,FRAMENUMBER),
               objects = [sun,Wheel],
               included = ["colors.inc", "textures.inc"],
               defaults = [Finish( 'ambient', 0.1, 'diffuse', 0.9)] )

    scene.render(ImageDir+ImageFrmtStr.format(OutputFileName,FRAMENUMBER), antialiasing=0.001, height=ImgHeight, width=ImgWidth, remove_temp=False) # Keep Pov File for debugging
    Frames.append(ImageClip(ImageDir+ImageFrmtStr.format(OutputFileName,FRAMENUMBER)).set_duration(1/FPS))
    

concat_clip = concatenate_videoclips(Frames, method="compose") # exception thrown MemoryError()
concat_clip.write_videofile(Mp4Dir+"{}.mp4".format(OutputFileName), fps=FPS)

Specifications

  • i7-8700 @3,2GHz
  • 16 GB ram
  • Python Version: 3.6 x64 Installed with Visual Studio 2017 ver 15.8.7
  • Moviepy Version: 0.2.3.5
  • Platform Name: Windows 10 Pro
  • Platform Version: 1803 build 17134.345
  • Pip environment packages below
astroid==2.1.0.dev0
certifi==2018.10.15
chardet==3.0.4
colorama==0.4.0
decorator==4.3.0
future==0.16.0
idna==2.7
imageio==2.4.1
isort==4.3.4
lazy-object-proxy==1.3.1
mccabe==0.6.1
mido==1.2.9
moviepy==0.2.3.5
numpy==1.15.2
Pillow==5.3.0
pip==18.1
pyFluidSynth==1.2.5
pylint==2.1.1
requests==2.19.1
setuptools==40.4.3
six==1.11.0
tqdm==4.27.0
typed-ast==1.1.0
urllib3==1.23
Vapory==0.1.1
wrapt==1.10.11
yapf==0.24.0
@Zulko
Copy link
Owner

Zulko commented Oct 20, 2018

This is not really a moviepy issue, the problem is that you are loading all frames in memory. You could avoid that using ImageSequenceClip. You can also avoid writing images by defining a make_frame(t) function as explained in my blog post about vapory. Sorry for not giving links am on mobile.

@Morketh
Copy link
Author

Morketh commented Oct 21, 2018

Apologies are not required. I figured the issue was because of the loading of the frames. I did look through the vapory page. This was very helpful and why I started working on PovRay again. I should probably re-read through the pages again for things I've missed. Thank-you for your quick reply on this matter. I will also dig through the ImageSequenceClip documentation and see what i can turn up.

@keikoro
Copy link
Collaborator

keikoro commented Dec 16, 2018

@Morketh Did you manage to solve your problem? Can we close this issue?

@Morketh
Copy link
Author

Morketh commented Dec 16, 2018

Yes, according to Zulko "This is not really a moviepy issue, the problem is that you are loading all frames in memory." After rewriting the code I'm able to deal with the memory issues now.

@Morketh Morketh closed this as completed Dec 16, 2018
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

3 participants