VLC and Processing

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

  • there is a NullPointer error.

    where?

    and how do we run this code? we have the source but what else do we need to do to reproduce the error?

  • edited January 2017

    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 :

    Received datagram with 65536 bytes.
    java.lang.NullPointerException
        at VideoReceiver.checkForImage(VideoReceiver.java:77)
        at VideoReceiver.draw(VideoReceiver.java:49)
        at processing.core.PApplet.handleDraw(PApplet.java:2403)
        at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1527)
        at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:316)
    

    Thanks for helping me !

Sign In or Register to comment.