We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone,
I would like to create a little soft able to receive a VLC stream on a local network (via UDP or RTSP). But I really don't know how to start. I've tried to use this : (by David Shiffman)
import java.awt.image.*;
import javax.imageio.*;
import java.io.ByteArrayInputStream;
import java.net.*;
// Port we are receiving.
int port = 9100;
DatagramSocket ds;
// A byte array to read into (max size of 65536, could be smaller)
byte[] buffer = new byte[65536];
PImage video;
void setup() {
size(400,300);
try {
ds = new DatagramSocket(port);
} catch (SocketException e) {
e.printStackTrace();
}
video = createImage(320,240,RGB);
}
void draw() {
// checkForImage() is blocking, stay tuned for threaded example!
checkForImage();
// Draw the image
background(0);
imageMode(CENTER);
image(video,width/2,height/2);
}
void checkForImage() {
DatagramPacket p = new DatagramPacket(buffer, buffer.length);
try {
ds.receive(p);
} catch (IOException e) {
e.printStackTrace();
}
byte[] data = p.getData();
println("Received datagram with " + data.length + " bytes." );
// Read incoming data into a ByteArrayInputStream
ByteArrayInputStream bais = new ByteArrayInputStream( data );
// We need to unpack JPG and put it in the PImage video
video.loadPixels();
try {
// Make a BufferedImage out of the incoming bytes
BufferedImage img = ImageIO.read(bais);
// Put the pixels into the video PImage
img.getRGB(0, 0, video.width, video.height, video.pixels, 0, video.width);
} catch (Exception e) {
e.printStackTrace();
}
// Update the PImage pixels
video.updatePixels();
}
But it isn't working, it detect that something is streamed but there is a NullPointer error. So if any of you have an idea on how to fix it or how to do it using another way, fell free to tell me !
Thanks
Answers
where?
and how do we run this code? we have the source but what else do we need to do to reproduce the error?
You have to run the code, then to go on VLC and to stream a video file using UDP (using 127.0.0.1) and to choose the port 9001. The error will occur at this moment. Here is the error :
Thanks for helping me !