我正在尝试用java中的RPi相机做直播,但是我有问题,因为我在这种编程方面很新,并且没有找到能够帮助我解决这个问题的答案。
我从此页面获得了我的服务器应用程序:enter link description here
它适用于.NET,但我想用Java完成整个事情(在我的情况下是UDP版本)。 我正在关注enter link description here的文档,但它仍然无效。
以下是我的客户端应用代码:
public class CamService {
public static IDuplexOutputChannel myVideoChannel;
public static String StreamAddr = "udp://192.168.0.145:8093/";
public static OutputStream myVideoStream;
public static BufferedOutputStream bOut;
public static String pName;
public static void main(String[] args) throws Exception {
JFrame frame;
EmbeddedMediaPlayerComponent mediaPlayerComponent;
new NativeDiscovery().discover();
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "c:\\program files (x86)\\videolan\\vlc\\");
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
IMessagingSystemFactory aMessaging = new UdpMessagingSystemFactory();
myVideoChannel = aMessaging.createDuplexOutputChannel(StreamAddr);
myVideoChannel.responseMessageReceived().subscribe(myOnResponseMessageReceived);
frame = new JFrame("AWWWW!");
frame.setBounds(100, 100, 600, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
mediaPlayerComponent.release();
myVideoChannel.closeConnection();
System.exit(0);
}
});
frame.setContentPane(mediaPlayerComponent);
frame.setVisible(true);
String[] mediaOptions = {
":sout=#transcode{vcodec=h264,venc=x264{preset=ultrafast},vb=512 }"
+ ":std{access=udp,mux=ts}" };
Media media = new SimpleMedia(StreamAddr, mediaOptions);
mediaPlayerComponent.getMediaPlayer().playMedia(media);
myVideoChannel.openConnection();
}
private static void onResponseMessageReceived(Object sender, DuplexChannelMessageEventArgs e) throws IOException
{
byte[] aMessage = (byte[])e.getMessage();
System.out.println("Byte message: " + aMessage);
myVideoStream.write(aMessage, 0, aMessage.length);
bOut = new BufferedOutputStream(myVideoStream);
System.out.println("Buffered Output: " + myVideoStream);
}
private static EventHandler<DuplexChannelMessageEventArgs> myOnResponseMessageReceived = new EventHandler<DuplexChannelMessageEventArgs>()
{
@Override
public void onEvent(Object sender, DuplexChannelMessageEventArgs e)
{
try {
onResponseMessageReceived(sender, e);
} catch (IOException e1) {
System.out.println("NOPE");
e1.printStackTrace();
}
}
};
}
编译时我没有收到任何错误。它连接到服务器,打开相机,但它没有流。关闭程序后我得到了:
主流错误:无法预先填充缓冲区
非常感谢任何帮助。 感谢。