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() {
  try {
    ds = new DatagramSocket(port);
  } catch (SocketException e) {
  video = createImage(320,240,RGB);

 void draw() {
  // checkForImage() is blocking, stay tuned for threaded example!

  // Draw the image

void checkForImage() {
  DatagramPacket p = new DatagramPacket(buffer, buffer.length); 
  try {
  } catch (IOException e) {
  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
  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) {
  // Update the PImage pixels

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 !



  • there is a NullPointer error.


    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 and to choose the port 9001. The error will occur at this moment. Here is the error :

    Received datagram with 65536 bytes.
        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.