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,54 @@
/**
* Frames.
* by Andres Colubri
*
* Moves through the video one frame at the time by using the
* arrow keys.
*/
import codeanticode.gsvideo.*;
GSMovie movie;
int newFrame = 0;
PFont font;
void setup() {
size(320, 240);
background(0);
// Load and set the video to play. Setting the video
// in play mode is needed so at least one frame is read
// and we can get duration, size and other information from
// the video stream.
movie = new GSMovie(this, "station.mov");
movie.play();
font = loadFont("DejaVuSans-24.vlw");
textFont(font, 24);
}
void movieEvent(GSMovie movie) {
movie.read();
}
void draw() {
if (newFrame != movie.frame()) {
// The movie stream must be in play mode in order to jump to another
// position along the stream. Otherwise it won't work.
movie.play();
movie.jump(newFrame);
movie.pause();
}
image(movie, 0, 0, width, height);
fill(240, 20, 30);
text(movie.frame() + " / " + (movie.length() - 1), 10, 30);
}
void keyPressed() {
if (key == CODED) {
if (keyCode == LEFT) {
if (0 < newFrame) newFrame--;
} else if (keyCode == RIGHT) {
if (newFrame < movie.length() - 1) newFrame++;
}
}
}
@@ -0,0 +1,37 @@
/**
* Loop.
* Built-in video library replaced with gsvideo by Andres Colubri
*
* Move the cursor across the screen to draw.
* Shows how to load and play a QuickTime movie file.
*
* Note: GSVideo uses GStreamer as the underlying multimedia library
* for reading media files, decoding, encoding, etc.
* It is based on a set of Java bindings for GStreamer called
* gstreamer-java originally created by Wayne Meissner and currently
* mantained by a small team of volunteers. GStreamer-java can be
* used from any Java program, and it is available for download at
* the following website:
* http://code.google.com/p/gstreamer-java/
*/
import codeanticode.gsvideo.*;
GSMovie movie;
void setup() {
size(640, 480);
background(0);
// Load and play the video in a loop
movie = new GSMovie(this, "station.mov");
movie.loop();
}
void movieEvent(GSMovie movie) {
movie.read();
}
void draw() {
tint(255, 20);
image(movie, mouseX-movie.width/2, mouseY-movie.height/2);
}
@@ -0,0 +1,50 @@
/**
* Pixelate
* by Hernando Barragan.
* Built-in video library replaced with gsvideo by Andres Colubri
*
* Load a QuickTime file and display the video signal
* using rectangles as pixels by reading the values stored
* in the current video frame pixels array.
*/
import codeanticode.gsvideo.*;
int numPixels;
int blockSize = 10;
GSMovie myMovie;
color myMovieColors[];
void setup() {
size(640, 480);
noStroke();
background(0);
myMovie = new GSMovie(this, "station.mov");
myMovie.loop();
numPixels = width / blockSize;
myMovieColors = new color[numPixels * numPixels];
}
// Read new values from movie
void movieEvent(GSMovie m) {
m.read();
m.loadPixels();
for (int j = 0; j < numPixels; j++) {
for (int i = 0; i < numPixels; i++) {
myMovieColors[j*numPixels + i] = m.get(i, j);
}
}
}
// Display values from movie
void draw() {
for (int j = 0; j < numPixels; j++) {
for (int i = 0; i < numPixels; i++) {
fill(myMovieColors[j*numPixels + i]);
rect(i*blockSize, j*blockSize, blockSize-1, blockSize-1);
}
}
}
@@ -0,0 +1,44 @@
/**
* GSVideo movie reverse example.
*
* The GSMovie.speed() method allows to
* change the playback speed. Use negative
* values for backwards playback. Note that
* not all video formats support backwards
* playback. This depends on the underlying
* gstreamer plugins used by gsvideo. For
* example, the theora codec does support
* backward playback, but not so the H264
* codec, at least in its current version.
*
*/
import codeanticode.gsvideo.*;
GSMovie myMovie;
boolean speedSet = false;
public void setup() {
size(320, 240);
background(0);
myMovie = new GSMovie(this, "balloon.ogg");
myMovie.play();
}
public void movieEvent(GSMovie myMovie) {
myMovie.read();
}
public void draw() {
if (myMovie.ready()) {
if (!speedSet) {
// Setting the speed should be done only once,
// this is the reason for the if statement.
speedSet = true;
myMovie.goToEnd();
// -1 means backward playback at normal speed,
myMovie.speed(-1.0);
}
}
image(myMovie, 0, 0, width, height);
}
@@ -0,0 +1,49 @@
/**
* Scratch.
* by Andres Colubri
*
* Move the cursor horizontally across the screen to set
* the position in the movie file.
*/
import codeanticode.gsvideo.*;
GSMovie movie;
void setup() {
size(640, 480);
background(0);
// Load and set the video to play. Setting the video
// in play mode is needed so at least one frame is read
// and we can get duration, size and other information from
// the video stream.
movie = new GSMovie(this, "station.mov");
movie.play();
}
void movieEvent(GSMovie movie) {
movie.read();
}
void draw() {
// A new time position is calculated using the current mouse location:
float f = constrain((float)mouseX / width, 0, 1);
float t = movie.duration() * f;
// If the new time is different enough from the current position,
// then we jump to the new position. But how different? Here the
// difference has been set to 0.1 (1 tenth of a second), but it can
// be smaller. My guess is that the smallest value should correspond
// to the duration of a single frame (for instance 1/24 if the frame rate
// of the video file is 24fps). Setting even smaller values seem to lead
// to choppiness. This will become trickier once the GSMovie.speed()
// and GSMovie.frameRate() methods become functional.
if (0.1 < abs(t - movie.time())) {
// The movie stream must be in play mode in order to jump to another
// position along the stream. Otherwise it won't work.
movie.play();
movie.jump(t);
movie.pause();
}
image(movie, 0, 0, width, height);
}
@@ -0,0 +1,35 @@
/**
* GSVideo movie speed example.
*
* Use the GSMovie.speed() method to change
* the playback speed.
*
*/
import codeanticode.gsvideo.*;
GSMovie movie;
public void setup() {
size(320, 240);
background(0);
movie = new GSMovie(this, "balloon.ogg");
movie.loop();
PFont font = loadFont("DejaVuSans-24.vlw");
textFont(font, 24);
}
public void movieEvent(GSMovie movie) {
movie.read();
}
public void draw() {
image(movie, 0, 0, width, height);
float newSpeed = map(mouseX, 0, width, 0.1, 2);
movie.speed(newSpeed);
fill(240, 20, 30);
text(nfc(newSpeed, 2) + "X", width - 80, 30);
}