Video Library: Distorted Images / How to save a video

edited July 2014 in Library Questions

Hi Everyone

I need a sketch which records a video from a webcam, so that I can play it back in processing at a later time. At the moment I am using the video library to capture images from the webcam and then I save each frame using the saveFrame command. The code I am using at this point is basically the example code:

 /**
 * Getting Started with Capture.
 * 
 * Reading and displaying an image from an attached Capture device. 
 */

import processing.video.*;

Capture cam;

void setup() {
  size(320, 240);

  String[] cameras = Capture.list();

  if (cameras == null) {
    println("Failed to retrieve the list of available cameras, will try the default...");
    cam = new Capture(this, 320, 240);
  } if (cameras.length == 0) {
    println("There are no cameras available for capture.");
    exit();
  } else {
    println("Available cameras:");
    for (int i = 0; i < cameras.length; i++) {
      println(cameras[i]);
    }

    // The camera can be initialized directly using an element
    // from the array returned by list():
    cam = new Capture(this, cameras[6]);
    // Or, the settings can be defined based on the text in the list
    //cam = new Capture(this, 640, 480, "Built-in iSight", 30);

    // Start capturing the images from the camera
    cam.start();
  }
//frameRate(5);
}

void draw() {
  if (cam.available() == true) {
    cam.read();
  }
  image(cam, 0, 0);
  // The following does the same as the above image() line, but 
  // is faster when just drawing the image without any additional 
  // resizing, transformations, or tint.
  //set(0, 0, cam);
    saveFrame("participant-######.tif"); 
}

I have two problems:

a) The images I grab are distorted if things move fast. Its almost as if the image is not all updating at the same time.

This is what images look like: distortion Any idea what is causing this and how to prevent it?

b) I would prefer saving things in video files. The old MovieMaker class used to be able to do that, but apparently it is obsolete and replaced by the video class. Is there anyway I can use something like mm.addFrame(pixels,width,height); the way it was previously done?

edit: running windows 7, 64bit using Processing v 2.2.1, 32bit and Logitech C615 webcam (http://www.logitech.com/en-ca/support/hd-webcam-c615?crid=405&osid=14&bit=64)

Tagged:

Answers

  • Hi fkeel,

    I am using the library GSvideo to save movie files directly. (instead of saving frames and converting them) Maybe this will work on your distortion problem aswell or is the distortion happening while you are playing the sketch? In the library there's an example sketch called MovieMaker. The code works well on Processing 2.2.1

    Nevertheless if you want to playback movies later it doesn't work with gsvideo unless you have version 1.5.1

  • Using GSvideo both solved the distortion problem & allowed me to save it as an .ogg file

    Thanks for the suggestion.

  • I thought the MovieMaker library was removed from Processing 2? not the case?

  • Hi fkeel!

    can you post your example with GSvideo, which shows recording from webcam.

    Thanks

    Roshan

Sign In or Register to comment.