Duplicating Video TO SIDE BY SIDE

Hi, I have a very simple program that I have been trying to build for a while.

All I want to do is to take 1 video output and project it side by side in a full screen:

here is what I have so far

import processing.video.*;

Capture video;

int halfImage = width*height/2;

void setup() {
  size(320,240);
  video = new Capture(this,320,240);
  background(255);
  video.start();
}

void draw() {

  if (video.available()) {
    video.read();
  }
  image(video,0,0);


/*loadPixels();
for (int i = 0; i < halfImage; i++) {
  pixels[i+halfImage] = pixels[i];
}
updatePixels(); */
}

I have been playing around with loadpixels and get, my goal is to make as simple and short of code that is possible.

This is how I was imagining the output:

800px-PL-DS,_Wrocław,_ul._Katedralna_4;_Dawny_sierociniec;_90,_46;_3D_side-by-side

I haven't really seen an example or any other sketch that has done something like this, and was wondering if anyone could help :)

Thank you so much!

Answers

  • edited January 2014 Answer ✓

    You don't necessarily need loadPixels() if you're not modifying any image properties like specific pixels. You could just add an extra pair of parameters for the scaling of an image/video, and that's it.

    Here's what I'm talking about:

    import processing.video.*;
    
    Capture video;
    
    int halfImage = width*height/2;
    
    void setup() {
      size(320, 240);
      video = new Capture(this, 320, 240);
      background(255);
      video.start();
    }
    
    void draw() {
    
      if (video.available()) {
        video.read();
      }
      image(video, 0, 0, 160, 240); //Left image. //The last 2 parameters are responsible for the image size.
      image(video, 160, 0, 160, 240); //Right image
    }
    

    -- MenteCode

    Edit: I have indicated the change by commenting beside the changes, even though they're pretty self explanatory.

  • edited January 2014

    WOW thanks man, that was stupid easy hahaha.

    Didn't realize you could do that, thank you SO MUCH! (I am not too bright haha).

  • edited January 2014 Answer ✓

    Just to add to @MenteCode 's solution:

    Both width & height system variables are still 0 before setup()! So that line #5 is useless now! 3:-O
    Also, I've re-made the code w/ parameterized constants: (*)

    P.S.: Processing's reference teaches that too:
    http://processing.org/reference/image_.html

    // forum.processing.org/two/discussion/2266/
    // duplicating-video-to-side-by-side
    
    import processing.video.*;
    
    Capture video;
    int halfW;
    
    void setup() {
      size(320, 240);
      smooth(4);
    
      halfW = width >> 1;
    
      (video = new Capture(this, width, height)).start();
    }
    
    void draw() {
      if (!video.available())  return;
    
      video.read();
    
      image(video, 0, 0, halfW, height);
      image(video, halfW, 0, halfW, height);
    }
    
  • Sweet, that is even better!

    Ok, so say later on I need to make the video more square to keep the proportions right, I would just do this:

    image(video, 0, 0, halfW, height/2);   //or modify "height to whatever property"
    

    Also, I have never seen the last 2 parameters, (capture, float, float, [float?], [float?]) it is interesting because I was just looking for a way to squinch the video down and you magically posted those extra parameters (thank you).

    where is a good place to read up more on capture?

    I looked over:

    http://www.processing.org/reference/libraries/video/Capture.html http://processing.org/reference/libraries/video/

    and just about 15 other examples but have never seen 5 parameters?

    Thanks.

  • edited January 2014

    Function image() belongs to Processing's own API. It's not from a 3rd-party library like Capture from video.

  • Alright gotcha, thanks!

Sign In or Register to comment.