Forum Index > Projects > LED Pegboard and Matrix Projects
 playing back a video file on peggy via i2c and arduino.
 |  Printable Version
By: Anonymous: Magicdominik () on Saturday, April 24 2010 @ 03:17 PM PDT (Read 8502 times)  
Anonymous: Magicdominik

I successfully got peggy 2 LE to display my webcam feed with the arduino i2c setup. I'm needing to have it display a recorded movie instead of the live webcam feed. I'm struggling to make it work. I basically went in to the sketch and switched out the video references with myMovie. it just displays black. I made sure to put the .mov file in the folder with the sketch. I'm not a genius at programing but have been using arduino for a few months to make motors, servo's and steppers move. This is much more harder!
Any help would be appreciated.





       
   
By: Anonymous: Magicdominik () on Saturday, April 24 2010 @ 03:40 PM PDT  
Anonymous: Magicdominik

I used the mirrorpegggy processing sketch with the two sketches for the arduino and the peggy. It all worked on my mac, but not with my pc. anyway.





       
   
By: Windell (offline) on Sunday, April 25 2010 @ 03:44 AM PDT  
Windell

The mirror demo relies on having a certain size video input, in terms of pixel number. To get it to work with a different input size, you should probably scale and/or crop it to have the exact same size. Processing can do this for you once you open the video file, or you could do it in an external program.

Or, if you're more determined, you could adapt the program to auto-detect the input video size and perform the necessary adjustments automatically.

As far as the mac versus pc issue, it may or may not be the same issue fundamentally. See if you can get the video input examples (which come with processing) to work correctly.


Windell H. Oskay
drwho(at)evilmadscientist.com
http://www.evilmadscientist.com/

Forum Evil Scientist
Evil Scientist

Status: offline

Registered: 06/15/06
Posts: 1932
Sunnyvale, CA

Profile Email Website  
   
By: Anonymous: Magicdominik () on Thursday, April 29 2010 @ 05:56 PM PDT  
Anonymous: Magicdominik

would that size be 320 x 240, and 15 frames. that's what the webcam is set to and it works.
I'm having a hell of a time getting a file to play properly. i guess i'll just keep at it.





       
   
By: Anonymous: anton () on Friday, April 30 2010 @ 09:42 PM PDT  
Anonymous: anton

hey -- i'm trying to do the exact same thing, and also having trouble. would you mind posting the code you're using? i can work on it too, maybe we'll figure it out.





       
   
By: Anonymous: code () on Sunday, May 02 2010 @ 04:39 PM PDT  
Anonymous: code

here's what i am using. i got it to work, but it plays in reverse, i need to make it play from left to right not right to left as it is doing now.
the code is the mirrorpeggy.pde but with the webcam video feed changed to play a movie.

import processing.video.*;
import processing.serial.*;

Serial peggyPort;
PImage peggyImage = new PImage(25,25);
byte [] peggyHeader = new byte[]
{
(byte)0xde, (byte)0xad, (byte)0xbe,(byte)0xef,1,0 };
byte [] peggyFrame = new byte[13*25];



// Size of each cell in the grid
int cellSize = 9;
int cellSize2 = 34; // was 20

// Number of columns and rows in our system
int cols, rows;
int ColLo, ColHi;
// Variable for capture device
//Capture video;
Movie myMovie; //changed this to movie not capture video

int xDisplay,yDisplay;
int xs, ys;
float brightTot;
int pixelCt;
color c2;

int OutputPoint = 0;

//int GrayArray[625];
int[] GrayArray = new int[625];
int j;
byte k;

int DataSent = 0;

// NEEDS TO HAVE YOUR ACTUAL SERIAL PORT LISTED!!!

void setup() {
peggyPort = new Serial(this, "/dev/cu.usbserial-A9007Mae", 115200); // CHANGE_HERE

smooth();
noStroke();
// size(640, 480, P3D);
size(cellSize2*25, cellSize2*25, JAVA2D);
//set up columns and rows
cols = 25; //width / cellSize;
ColLo = 4; //Was 4
ColHi = 29; // Was 29
rows = 25; //height / cellSize;
colorMode(RGB, 255, 255, 255, 100);
rectMode(CENTER);

// Uses the default video input, see the reference if this causes an error
// video = new Capture(this, width, height, 5);
// video = new Capture(this, 320, 240, 15); //Last number is frames per second

myMovie = new Movie(this, "moviename.mov" ); //plays the video file. the file needs to be
// in the same directory as the program.
// i've been using either .mov, or .mp4.

background(0);

j = 0;
k = 0;

while (j < 625){


GrayArray[j] = 4;//k;

k++;

if (k > 15)
k = 0;

j++;
}



}



// render a PImage to the Peggy by transmitting it serially.
// If it is not already sized to 25x25, this method will
// create a downsized version to send...
void movieEvent(Movie myMovie) { //changed to movie
myMovie.play();
myMovie.read();
}

void renderToPeggy(PImage srcImg)
{
int idx = 0;

PImage destImg = srcImg;

// iterate over the image, pull out pixels and
// build an array to serialize to the peggy
for (int y =0; y < 25; y++)
{
byte val = 0;
for (int x=0; x < 25; x++)
{
color c = destImg.get(x,y);
int br = ((int)brightness(c))>>4;
if (x % 2 ==0)
val = (byte)br;
else
{
val = (byte) ((br<<4)|val);
peggyFrame[idx++]= val;
}
}
peggyFrame[idx++]= val; // write that one last leftover half-byte
}

peggyPort.write(peggyHeader);
peggyPort.write(peggyFrame);
}


void draw() { // took out video references
/*if (video.available()) {
video.read();
video.loadPixels();

background(0, 0, 0);
*/

myMovie.play();
myMovie.read();
myMovie.loadPixels();

background(0, 0, 0);

image(myMovie, 0, 0, 0, 0); // had problems with seeing movie in background, this fixed it

//int MaxSoFar = 0;
int thisByte = 0;
int e,k;
int br2;

int idx = 0;

PImage img2 = createImage(25, 25, ARGB );



// Begin loop for columns

k = 0;
for (int i = ColLo; i < ColHi;i++) {
// Begin loop for rows
for (int j = 0; j < rows;j++) {

// Where are we, pixel-wise?
int x = i * cellSize;
int y = j * cellSize;

int loc = (myMovie.width - x - 1) + y*myMovie.width; // Reversing x to mirror the image
// need to not reverse file. don't know how to not

// Each rect is colored white with a size determined by brightness
color c = myMovie.pixels[loc];

pixelCt = 0;
brightTot = 0;

for (int xs = x; xs < (x + cellSize); xs++) {
for (int ys = y; ys < (y + cellSize); ys++) {

pixelCt++;
loc = (myMovie.width - xs - 1) + ys*myMovie.width;
// loc = xs + ys*myMovie.width; // reverses to correct display direction
c2 = myMovie.pixels[loc];
brightTot += brightness(c2);

}
}

brightTot /= pixelCt;

xDisplay = (i-ColLo)*cellSize2 + cellSize2/2;
yDisplay = j*cellSize2 + cellSize2/2;



// Linear brightness:
br2 = int(brightTot / 8);

idx = (j)*cols + (i-ColLo);
GrayArray[idx] = (int) br2; //inverted image


br2 = br2*8;

fill(br2,br2,br2); // 8-level with true averaging
ellipse(xDisplay+1, yDisplay+1, cellSize2-1, cellSize2-1);

img2.pixels[idx] = br2;
k++;
}
}

renderToPeggy(img2);

} // End if video available
//} // end main loop





       
   
By: Anonymous: video () on Sunday, May 02 2010 @ 04:42 PM PDT  
Anonymous: video

i don't know why there are smiley faces in the code. strange. they should be closing brackets.
also i had to play with what file, size, and type of movie it would work with. i'm using after effects to create an animation and exporting it as h.264 and as an mp4. it kept crashing with .mov. i just played around all day to work out what i could get to play in the prog.





       
   
By: Windell (offline) on Sunday, May 02 2010 @ 05:48 PM PDT  
Windell

Quote by: video

i don't know why there are smiley faces in the code. strange. they should be closing brackets.
also i had to play with what file, size, and type of movie it would work with. i'm using after effects to create an animation and exporting it as h.264 and as an mp4. it kept crashing with .mov. i just played around all day to work out what i could get to play in the prog.



I think that I've fixed the smilies-- following certain characters with a right-parenthesis tends to generate them.

For reversing the video, try replacing the line

PHP Formatted Code
int loc = (myMovie.width - x - 1) + y*myMovie.width;


with

PHP Formatted Code
int loc = x + y*myMovie.width;



I'm not sure what's up with the video format. Which platform are you on, and do the Processing .mov examples work correctly for you? You may need Apple's quicktime plugin for .mov to work correctly.


Windell H. Oskay
drwho(at)evilmadscientist.com
http://www.evilmadscientist.com/

Forum Evil Scientist
Evil Scientist

Status: offline

Registered: 06/15/06
Posts: 1932
Sunnyvale, CA

Profile Email Website  
   
By: Anonymous: Magicdominik () on Monday, May 03 2010 @ 03:14 PM PDT  
Anonymous: Magicdominik

I replaced that code with the suggested and it made no difference. should it be in a different place?

I am using macpro with OSX snow leopard.
i'll look into the quicktime version. i was able to play .mov, but it seems to work better with mp4. the mov was too large. all i have is white dots that flash and move across rows. I can get results faster creating a movie file rather than working out code to make the led's do my bidding.





       
   
By: Anonymous: Magicdominik () on Monday, May 03 2010 @ 03:17 PM PDT  
Anonymous: Magicdominik

Ok, i got the code working to display the right way. my mistake. Thanks for fixing the smiley faces.





       
   
By: Anonymous: will () on Monday, May 03 2010 @ 03:46 PM PDT  
Anonymous: will

thanks for posting your code!

i'm on a macbook pro and can get a few seconds of video to play before processing freezes, tells me that i may have a problem with my 'perian' plugin (?) and in the debug window shows "Invalid memory access of location 0x20 eip=0x381fbe9e"

the file i'm trying to play is an mp4 version of the station.mov file that works with the example pixelate sketch.





       
   
By: Anonymous: Magicdominik () on Monday, May 10 2010 @ 12:28 PM PDT  
Anonymous: Magicdominik

I'm not familiar with the error. A quick google search uncovered a website. http://perian.org/
you can get a new update there.
I had major problems at first, then i discovered that i had an old version of processing. I upgraded to the newest 1.1 version. I also did a software update with the mac, but nothing came up so i ran the processing sketch and it worked.

On a pc, i had to install the new processing prog. and winvdig 1.1. it all works great. I used a webcam too, but had to install webcam stuff on the pc. i'm finding the mac much more user friendly. I'm successfully using it on a pc and a mac.

It used to crash at the end of the movie, but now it seems to be fine. I found that if i rush the program it behaves badly. I let it start up fully then open the sketch, take my time before i run the movie. it's been 100% all day yesterday.

I used the "station" movie to test the sketch on the mac when i was 1st working it out. it worked fine for me.

Just make sure you are current with all the programs.





       
   
By: Anonymous: kylevh () on Thursday, April 12 2012 @ 04:38 PM PDT  
Anonymous: kylevh

I am thinking of streaming a movie to Peggy using the serial hack, and the peggy2Serial library. Is this code a good starting place? What are the ideal dimensions and FPS for the video?





       
   
By: Anonymous: kylevh () on Thursday, April 12 2012 @ 08:06 PM PDT  
Anonymous: kylevh

So Im playing with peggy2.3, with peggy2serial library and the physical serial hack. Arudino 0023, and processing 1.2.1 (and also troubleshooting with the latest 1.5.1 version).
Happily, the mirror Peggy seems bomb-proof and will run indefinitely, but when I try the code here for implementing a video playback, I can only get about 1-3 minutes of playback before a memory allocation error pops up in processing and it quits.
The movie Im playing is simply a recording from the same webcam--so I would think it would be fine. That movie (.mov) opens in after effects as 640x480 at 15fps. I've tried rendering it at 320x240 as a .mov and as a .mp4, but always I get a similar error.

I'm wondering if anyone else is working on this, seems like a popular goal to stream a video. Thanks for any advice. Big Grin





       
   
By: Anonymous: kylevh () on Friday, April 13 2012 @ 09:47 PM PDT  
Anonymous: kylevh

reading into it more, it seems like its definitely not peggy-related at all. The problem for me is with quicktime, java, and processing, which seem to be out-of-step according to a few processing forums. if anyone finds a solution, please share Wink





       
   



 All times are PDT. The time is now 03:04 AM.
Normal Topic Normal Topic
Locked Topic Locked Topic
Sticky Topic Sticky Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Able to Post 
Filtered HTML Allowed 
Censored Content 

Evil Mad Scientist Forum Archives — Read only!

Please visit our new forums for new discussions.


DIY Hardware for Electronic Art


The Original Egg-Bot Kit


Octolively
Interactive LED kits


Meggy Jr RGB
LED matrix game
development kit.


Business-card sized
AVR target boards


Peggy 2
LED Pegboard kits

My Account






Lost your password?