Dear Processing Discourse,
I'm hoping someone can hlep me with some video optimization.
I've been writing a sketch that takes a library of video files and displays them simultaneously on a 3 x 3 grid.
I want them to be able to load the videos from on the fly, based on a conceptual layer of relationships to each other.
One class is "Clip", which describes the meta data for the video. like frames, name, length, current frame.
Another class is "Relationship" which connects the clips, so if one clip is in playback, it looks to the relationship object of that clip to see if other clips should be triggered in playback.
These relationship objects also have values which can be adjusted on the fly through the interface. E.g. If clip A is playing, there's a 50% chance of a clip B being played on an adjecent grid co-ordinate.
The idea being that once a network of relationships for the clips are defined, videos can be "chained" on the fly depending on the relationship objects.
The current implementations initalises all the clips on start up, loading all the frames for each video in the "clip" object, so that when it comes to playback everything runs smoothly. This works with a small library of clips.
Unsurprisingly i'm running out of memory as things scale up. And load times are a killer.
What's the best way to cache load clips as needed?
i've been doing it rather nastily as small gif animations. Recorded and played back using the gifAnimation library. 320x240. Priority is smooth playback over resolution. Especially since all the videos are in a grid, things get big anyway.
Tried unsuccessfully to use GSVideo, but maybe i need to give it another crack.
I'm also using the NApplet library too, so i can have seperate windows for the interface and playback. But this means i could only get it working in Processing 1.2.1. Also because of these libraries i'm running P2D.
Have tried various forums without much luck so far.
Any ideas, thoughts, links, resources would be much apprecitated!
Many thanks in advance.
Cheers,
Keith
- import gifAnimation.*;
- class Clip{
- PImage[] frames;
- String name;
- String fileName;
- int startFrame;
- int endFrame;
- int currentFrame;
- Clip(PApplet parent, String clipName, String clipSource){
- //gif = new Gif(parent, clipSource);
- name = clipName;
- frames = Gif.getPImages(parent, clipSource);
- currentFrame = 0;
- startFrame = 0;
- endFrame = frames.length - 1;
- }
- //empty clip
- Clip(){
- frames = new PImage[1];
- frames[0] = _emptyImage;
- name = "empty";
- currentFrame = 0;
- startFrame = 0;
- endFrame = 0;
- }
- //clone clip
- Clip(Clip org){
- name = org.name;
- frames = org.frames;
- //changed to startFrame
- currentFrame = org.startFrame;
- startFrame = org.startFrame;
- endFrame = org.endFrame;
- }
- void setStart(int start){
- startFrame = start;
- currentFrame = start;
- }
- void setEnd(int end){
- if(end > frames.length){
- endFrame = frames.length - 1;
- }else{
- endFrame = end;
- }
- }
- PImage next(){
- if(currentFrame < endFrame){
- PImage frameImage = frames[currentFrame];
- currentFrame++;
- return frameImage;
- }else{
- return _emptyImage;
- }
- }
- int getCurrentFrame(){
- return currentFrame;
- }
- void gotoFrame(int frameno){
- if(frameno >= endFrame){
- currentFrame = endFrame;
- }else{
- currentFrame = frameno;
- }
- }
- String getLength(){
- return calTimeStamp(endFrame);
- }
- String getCurrentTime(){
- return calTimeStamp(currentFrame);
- }
- String calTimeStamp(int frameno){
- int minutes = frameno / (12*60);
- int seconds = (frameno / 12)%60;
- int secondframes = frameno%12;
- return nf(minutes,2) + ":" + nf(seconds,2) + ":" + nf(secondframes,2);
- }
- //public Clip clone(){
- // return this.clone();
- //}
- }
1