Skip to content

Commit bd53813

Browse files
author
Abe Pazos
committed
Add streaming examples
1 parent 38a5da6 commit bd53813

File tree

7 files changed

+162
-0
lines changed

7 files changed

+162
-0
lines changed
Binary file not shown.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import java.nio.ByteBuffer;
2+
import java.io.FileOutputStream;
3+
import com.hamoid.*;
4+
5+
FileOutputStream vcam;
6+
ByteBuffer bytes;
7+
8+
void setup() {
9+
size(640, 480, P3D);
10+
textAlign(CENTER, CENTER);
11+
textFont(loadFont("PetMe64-48.vlw"));
12+
stroke(255, 180);
13+
strokeWeight(4);
14+
sphereDetail(3);
15+
try {
16+
vcam = new FileOutputStream("/dev/video2");
17+
} catch(Exception e) {
18+
e.printStackTrace();
19+
}
20+
bytes = ByteBuffer.allocate(640 * 480 * 3);
21+
}
22+
void draw() {
23+
hint(DISABLE_DEPTH_TEST);
24+
background(#224488);
25+
noFill();
26+
translate(width/2, height/2);
27+
rotateY(frameCount * 0.01);
28+
sphere(300);
29+
rotateY(-frameCount * 0.01);
30+
textSize(50 + 15*sin(frameCount * 0.1));
31+
fill(255, 180);
32+
text("hello jitsi", 0, 0);
33+
34+
loadPixels();
35+
bytes.clear();
36+
for(int i : pixels) {
37+
bytes.putInt(i);
38+
}
39+
40+
try {
41+
vcam.write(bytes.array());
42+
} catch(IOException e) {
43+
e.printStackTrace();
44+
}
45+
}
Binary file not shown.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import java.nio.ByteBuffer;
2+
import java.io.FileOutputStream;
3+
import com.hamoid.*;
4+
5+
FileOutputStream vcam;
6+
byte[] bytes;
7+
8+
void setup() {
9+
size(640, 480, P3D);
10+
textAlign(CENTER, CENTER);
11+
textFont(loadFont("PetMe64-48.vlw"));
12+
stroke(255, 180);
13+
strokeWeight(4);
14+
sphereDetail(3);
15+
try {
16+
vcam = new FileOutputStream("/dev/video2");
17+
} catch(Exception e) {
18+
e.printStackTrace();
19+
}
20+
bytes = new byte[640 * 480 * 3];
21+
}
22+
void draw() {
23+
hint(DISABLE_DEPTH_TEST);
24+
background(#224488);
25+
noFill();
26+
translate(width/2, height/2);
27+
rotateY(frameCount * 0.01);
28+
sphere(300);
29+
rotateY(-frameCount * 0.01);
30+
textSize(50 + 15*sin(frameCount * 0.1));
31+
fill(255, 180);
32+
text("hello jitsi", 0, 0);
33+
34+
loadPixels();
35+
for(int i=0; i<pixels.length; i++) {
36+
int x = i % 640;
37+
int y = i / 640;
38+
int ii = 639 - x + y * 640;
39+
bytes[i * 3 + 0] = (byte)(pixels[ii] >> 16);
40+
bytes[i * 3 + 1] = (byte)(pixels[ii] >> 8);
41+
bytes[i * 3 + 2] = (byte)(pixels[ii]);
42+
}
43+
44+
try {
45+
vcam.write(bytes);
46+
} catch(IOException e) {
47+
e.printStackTrace();
48+
}
49+
}
Binary file not shown.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifdef GL_ES
2+
precision mediump float;
3+
precision mediump int;
4+
#endif
5+
6+
#define PROCESSING_TEXTURE_SHADER
7+
8+
uniform sampler2D texture;
9+
uniform vec2 texOffset;
10+
uniform float time;
11+
varying vec4 vertColor;
12+
varying vec4 vertTexCoord;
13+
14+
void main() {
15+
vec2 p = vertTexCoord.st;
16+
vec3 c = texture2D(texture, p).rgb;
17+
if(abs(c.r - c.g) < 0.03 && c.r > 0.5) {
18+
c = vec3(0.0, 0.7, 0.0);
19+
c.r = step(0.5, sin(time + length(p * 20.0)));
20+
c.b = step(0.5, fract(time + p.x * 10.0));
21+
}
22+
gl_FragColor = vec4(c, 1.0);
23+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import com.hamoid.*;
2+
import processing.video.*;
3+
4+
Capture cam;
5+
VideoExport vcam;
6+
PShader fx;
7+
void setup() {
8+
size(640, 480, P2D);
9+
textAlign(CENTER, CENTER);
10+
frameRate(30);
11+
cam = new Capture(this, Capture.list()[1]);
12+
cam.start();
13+
fx = loadShader("fx.frag");
14+
}
15+
void draw() {
16+
if (cam.available()) {
17+
cam.read();
18+
}
19+
fx.set("time", millis() * 0.001);
20+
image(cam, 0, 0, width, height);
21+
filter(fx);
22+
if (vcam != null) { vcam.saveFrame(); }
23+
if (frameCount % 30 == 0) { fx = loadShader("fx.frag"); }
24+
}
25+
void keyPressed() {
26+
if (key == ' ') {
27+
vcam = new VideoExport(this);
28+
vcam.setFfmpegVideoSettings(
29+
new String[]{
30+
"[ffmpeg]", // ffmpeg executable
31+
"-s", "640x480", // size
32+
"-r", "30", // frame rate
33+
"-f", "rawvideo", // format rgb raw
34+
"-vcodec", "rawvideo", // in codec rgb raw
35+
"-pix_fmt", "rgb24", // pix format rgb24
36+
"-i", "-", // pipe input
37+
"-vf", "hflip", // horizontal flip
38+
"-f", "v4l2", // format rgb raw
39+
"-vcodec", "rawvideo", // in codec rgb raw
40+
"-pix_fmt", "rgb24", // pix format rgb24
41+
"/dev/video4" // $ v4l2-ctl --list-devices # find output device
42+
});
43+
vcam.startMovie();
44+
}
45+
}

0 commit comments

Comments
 (0)