Live Stream RTSP using VLCJ Mac OS

1k views Asked by At

I am trying to connect to a d-link IP Camera and stream live video over RTSP using VLCJ library (Version 3.10.1)

System Specifications: MacOS Sierra, Version 10.12.6

I'm using VLCJ's DirectMediaPlayer Component to embed vlc media player in the jFrame. An solid black empty jFrame pops up with the following error when I input the public IP. When I use the same IP adress in the VLC player's network option, I can clearly see the stream. The problem is only when I try to view it through the Java client.

Here's the code:

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import uk.co.caprica.vlcj.component.DirectMediaPlayerComponent;
import uk.co.caprica.vlcj.discovery.NativeDiscovery;
import uk.co.caprica.vlcj.mrl.RtspMrl;
import uk.co.caprica.vlcj.player.direct.BufferFormat;
import uk.co.caprica.vlcj.player.direct.BufferFormatCallback;
import uk.co.caprica.vlcj.player.direct.DirectMediaPlayer;
import uk.co.caprica.vlcj.player.direct.RenderCallback;
import uk.co.caprica.vlcj.player.direct.RenderCallbackAdapter;
import uk.co.caprica.vlcj.player.direct.format.RV32BufferFormat;

public class DirectTestPlayer {

    private static final int width = 600;

    private static final int height = 400;

    private final JFrame frame;

    private final JPanel videoSurface;

    private final BufferedImage image;

    private final DirectMediaPlayerComponent mediaPlayerComponent;

    public static void main(final String[] args) {
        new NativeDiscovery().discover();
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new DirectTestPlayer(args);
            }

        });
    }

    public DirectTestPlayer(String[] args) {
        frame = new JFrame("Direct Media Player");
        frame.setBounds(100, 100, width, height);
        frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        videoSurface = new VideoSurfacePanel();
        frame.setContentPane(videoSurface);
        image = GraphicsEnvironment
                .getLocalGraphicsEnvironment()
                .getDefaultScreenDevice()
                .getDefaultConfiguration()
                .createCompatibleImage(width, height);
        BufferFormatCallback bufferFormatCallback = new BufferFormatCallback() {
            @Override
            public BufferFormat getBufferFormat(int sourceWidth, int sourceHeight) {
                return new RV32BufferFormat(width, height);
            }
        };
        mediaPlayerComponent = new DirectMediaPlayerComponent(bufferFormatCallback) {
            @Override
            protected RenderCallback onGetRenderCallback() {
                return new TutorialRenderCallbackAdapter();
            }

        };
        frame.setVisible(true);
        String mrl = new RtspMrl().host("xx.xxx.x.xxx")
                .port(554)
                .path("/play1.sdp")
                .value();
        String[] options = {":sout-rtsp-user", "admin", ":sout-rtsp-pwd", "", ":no-sout-rtp-sap",
                ":no-sout-standard-sap",
                ":sout-all",
                ":sout-keep",
                ":demux=h264"};
        //mediaPlayerComponent.getMediaPlayer().playMedia(args[0]);
      mediaPlayerComponent.getMediaPlayer().playMedia(mrl,options);
    }

    private class VideoSurfacePanel extends JPanel {

        private VideoSurfacePanel() {
            setBackground(Color.black);
            setOpaque(true);
            setPreferredSize(new Dimension(width, height));
            setMinimumSize(new Dimension(width, height));
            setMaximumSize(new Dimension(width, height));
        }

        @Override
        protected void paintComponent(Graphics g) {
            Graphics2D g2 = (Graphics2D)g;
            g2.drawImage(image, null, 0, 0);
        }
    }

    private class TutorialRenderCallbackAdapter extends RenderCallbackAdapter {

        private TutorialRenderCallbackAdapter() {
            super(new int[width * height]);
        }

        @Override
        protected void onDisplay(DirectMediaPlayer mediaPlayer, int[] rgbBuffer) {
            // Simply copy buffer to the image and repaint
            image.setRGB(0, 0, width, height, rgbBuffer, 0, width);
            videoSurface.repaint();
        }
    }
}

Here's the error:

[00007f84a368a848] live555 demux error: Failed to connect with rtsp://xx.xxx.x.xxx:554/play1.sdp
[00007f84a59b4918] core input error: open of `rtsp://xx.xxx.x.xxx:554/play1.sdp' failed
[00007f84a59b4918] core input error: Your input can't be opened
[00007f84a59b4918] core input error: VLC is unable to open the MRL 'rtsp://xx.xxx.x.xxx:554/play1.sdp'. Check the log for details.

I've tried running the same on a windows machine and no luck.

0

There are 0 answers