new gsvideo library

This commit is contained in:
benfry
2011-06-18 16:27:28 +00:00
parent 4dac2e0a71
commit 7d7db7d0d1
56 changed files with 6561 additions and 1 deletions
@@ -0,0 +1,58 @@
// Using integration with GLGraphics for fast video playback.
// All the decoding stages, until the color conversion from YUV
// to RGB are handled by gstreamer, and the video frames are
// directly transfered over to the OpenGL texture encapsulated
// by the GLTexture object.
// You need the GLGraphics library (0.99+) to use this functionality:
// http://glgraphics.sourceforge.net/
import processing.opengl.*;
import codeanticode.glgraphics.*;
import codeanticode.gsvideo.*;
GSCapture cam;
GLTexture tex;
void setup() {
size(640, 480, GLConstants.GLGRAPHICS);
cam = new GSCapture(this, 640, 480);
// Use texture tex as the destination for the camera pixels.
tex = new GLTexture(this);
cam.setPixelDest(tex);
cam.play();
/*
// You can get the resolutions supported by the
// capture device using the resolutions() method.
// It must be called after creating the capture
// object.
int[][] res = cam.resolutions();
for (int i = 0; i < res.length; i++) {
println(res[i][0] + "x" + res[i][1]);
}
*/
/*
// You can also get the framerates supported by the
// capture device:
String[] fps = cam.framerates();
for (int i = 0; i < fps.length; i++) {
println(fps[i]);
}
*/
}
void captureEvent(GSCapture cam) {
cam.read();
}
void draw() {
// If there is a new frame available from the camera, the
// putPixelsIntoTexture() function will copy it to the
// video card and will return true.
if (tex.putPixelsIntoTexture()) {
image(tex, 0, 0, width, height);
}
}
@@ -0,0 +1,80 @@
// Using integration with GLGraphics for fast video playback.
// All the decoding stages, until the color conversion from YUV
// to RGB are handled by gstreamer, and the video frames are
// directly transfered over to the OpenGL texture encapsulated
// by the GLTexture object.
// You need the GLGraphics library (0.99+) to use this functionality:
// http://glgraphics.sourceforge.net/
import processing.opengl.*;
import codeanticode.glgraphics.*;
import codeanticode.gsvideo.*;
GSMovie mov;
GLTexture tex;
int fcount, lastm;
float frate;
int fint = 3;
void setup() {
size(1280, 800, GLConstants.GLGRAPHICS);
frameRate(90);
mov = new GSMovie(this, "movie.avi");
// Use texture tex as the destination for the movie pixels.
tex = new GLTexture(this);
mov.setPixelDest(tex);
// This is the size of the buffer where frames are stored
// when they are not rendered quickly enough.
tex.setPixelBufferSize(10);
// New frames put into the texture when the buffer is full
// are deleted forever, so this could lead dropeed frames:
tex.delPixelsWhenBufferFull(false);
// Otherwise, they are kept by gstreamer and will be sent
// again later. This avoids loosing any frames, but increases
// the memory used by the application.
mov.loop();
background(0);
noStroke();
}
void draw() {
// Using the available() method and reading the new frame inside draw()
// instead of movieEvent() is the most effective way to keep the
// audio and video synchronization.
if (mov.available()) {
mov.read();
// putPixelsIntoTexture() copies the frame pixels to the OpenGL texture
// encapsulated by
if (tex.putPixelsIntoTexture()) {
// Calculating height to keep aspect ratio.
float h = width * tex.height / tex.width;
float b = 0.5 * (height - h);
image(tex, 0, b, width, h);
String info = "Resolution: " + mov.width + "x" + mov.height +
" , framerate: " + nfc(frate, 2) +
" , number of buffered frames: " + tex.getPixelBufferUse();
fill(0);
rect(0, 0, textWidth(info), b);
fill(255);
text(info, 0, 15);
fcount += 1;
int m = millis();
if (m - lastm > 1000 * fint) {
frate = float(fcount) / fint;
fcount = 0;
lastm = m;
}
}
}
}
@@ -0,0 +1,40 @@
// Using integration with GLGraphics for fast video playback.
// All the decoding stages, until the color conversion from YUV
// to RGB are handled by gstreamer, and the video frames are
// directly transfered over to the OpenGL texture encapsulated
// by the GLTexture object.
// You need the GLGraphics library (0.99+) to use this functionality:
// http://glgraphics.sourceforge.net/
import processing.opengl.*;
import codeanticode.glgraphics.*;
import codeanticode.gsvideo.*;
GSMovie movie;
GLTexture tex;
void setup() {
size(640, 480, GLConstants.GLGRAPHICS);
background(0);
movie = new GSMovie(this, "station.mov");
// Use texture tex as the destination for the movie pixels.
tex = new GLTexture(this);
movie.setPixelDest(tex);
movie.loop();
}
void movieEvent(GSMovie movie) {
movie.read();
}
void draw() {
// If there is a new frame available from the movie, the
// putPixelsIntoTexture() function will copy it to the
// video card and will return true.
if (tex.putPixelsIntoTexture()) {
tint(255, 20);
image(tex, mouseX-movie.width/2, mouseY-movie.height/2);
}
}
@@ -0,0 +1,38 @@
// Using integration with GLGraphics for fast video playback.
// All the decoding stages, until the color conversion from YUV
// to RGB are handled by gstreamer, and the video frames are
// directly transfered over to the OpenGL texture encapsulated
// by the GLTexture object.
// You need the GLGraphics library (0.99+) to use this functionality:
// http://glgraphics.sourceforge.net/
import processing.opengl.*;
import codeanticode.glgraphics.*;
import codeanticode.gsvideo.*;
GSPipeline pipeline;
GLTexture tex;
void setup() {
size(320, 240, GLConstants.GLGRAPHICS);
pipeline = new GSPipeline(this, "videotestsrc");
// Use texture tex as the destination for the pipeline pixels.
tex = new GLTexture(this);
pipeline.setPixelDest(tex);
pipeline.play();
}
void pipelineEvent(GSPipeline pipeline) {
pipeline.read();
}
void draw() {
// If there is a new frame available from the pipeline, the
// putPixelsIntoTexture() function will copy it to the
// video card and will return true.
if (tex.putPixelsIntoTexture()) {
image(tex, 0, 0, width, height);
}
}