Having trouble playing a recorded video stored in an ArrayList
in
Contributed Library Questions
•
2 years ago
I'm trying to use GSVideo to record a video into an ArrayList and delete some of its frames. Recording the video works fine, but when I try to step through the images, the program will only display the last frame.
- import codeanticode.gsvideo.*;
- GSCapture cam;
- ArrayList pictures = new ArrayList();
- boolean recording = true;
- int frame = 0;
- void setup() {
- size(640, 480);
- String[] cameras = GSCapture.list();
- cam = new GSCapture(this, 640, 480, cameras[0]);
- cam.play();
- }
- void draw() {
- println("Draw: " + frame);
- if(cam.available() == true) {
- if(recording) {
- cam.read();
- pictures.add(cam);
- frame++;
- }
- }
- try {
- background(0);
- image((PImage) pictures.get(frame-1), 0, 0, width, height);
- } catch(IndexOutOfBoundsException e) {
- ; //do nothing
- }
- }
- void keyPressed() {
- recording = false;
- if(key == 'q') {
- frame = max((frame - 1) % pictures.size(),1);
- } else if(key == 'e') {
- frame = min((frame + 1) % pictures.size(),pictures.size());
- } else if(key == 'w') {
- pictures.remove(frame);
- frame = frame % pictures.size();
- }
- println("KeyPressed: " + frame);
- }
The controls (if it worked) are:
- Q to step back a frame
- E to step forward a frame
- W to erase the current frame
1