1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

high memory usage problem

Posted by Al on Nov 29, 2008

Hi everyone,
Could anyone offer a way of reducing the memory usage of the code sample below? What I'm trying to do is create a timelapse mov file from a folder of images. The current version just does the basics of changing the image every frame, but when I try to export a mov file the memory usage gets so high that nodebox freezes completely. I get the impression that nodebox caches the image of every frame, so that very quickly it's using over 1GB of ram.
Apologies if the quality of the code below is not very good, I'm not very familiar with python yet.

Any suggestions greatly appreciated.
Al

import os
 
class ImageList:
 
    def __init__(self, image_dir):
        self.image_dir = image_dir
        imgs = os.listdir(image_dir)
        self.imgs = [f for f in imgs if f.lower().endswith("jpg")]
        self.imgs.sort()
        
        self.img_num = 0
        
    def next_image(self):
        im = self.imgs[self.img_num]
        if self.img_num == len(self.imgs) -1:
            self.img_num = 0
        else:
            self.img_num += 1
            
        return self.image_dir + im
 
# ----------------------------------------
 
size(1080, 720)
speed(30)
        
ims = ImageList("/Users/al/Pictures/Timelapse/")
 
def draw():
    im = ims.next_image()
    image(im, 0, 0, alpha=1.0)