我正在尝试使用VLCJ库(版本3.10.1)连接到d-link IP Camera并通过RTSP传输实时视频
系统规格: MacOS Sierra,版本10.12.6
我正在使用VLCJ的DirectMediaPlayer组件在vFrame中嵌入vlc媒体播放器。 当我输入公共IP时,弹出一个纯黑色空jFrame,出现以下错误。 当我在VLC播放器的网络选项中使用相同的IP地址时,我可以清楚地看到该流。问题是当我尝试通过Java客户端查看它时。
以下是代码:
declare @a numeric(20, 1) = '123.1';
declare @b numeric(20, 1) = '1234567890123456789.0';
select datalength(@a), datalength(@b);
以下是错误:
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();
}
}
}
我尝试在Windows机器上运行相同的操作但没有运气。