使用JAVA的RPi摄像头的客户端服务器实时流

使用JAVA的RPi摄像头的客户端服务器实时流,java,video-streaming,vlc,Java,Video Streaming,Vlc,我正在尝试用java从RPi摄像头进行直播,但我遇到了问题,因为我对这种编程非常陌生,没有找到对我有帮助的答案 我已从该页面获取我的服务器应用程序: 它可以与.NET一起使用,但我想用Java(在我的例子中是UDP版本)完成整个工作。 我正在跟踪上的文档,但它仍然不起作用 以下是我的客户端应用程序代码: public class CamService { public static IDuplexOutputChannel myVideoChannel; public static Strin

我正在尝试用java从RPi摄像头进行直播,但我遇到了问题,因为我对这种编程非常陌生,没有找到对我有帮助的答案

我已从该页面获取我的服务器应用程序:

它可以与.NET一起使用,但我想用Java(在我的例子中是UDP版本)完成整个工作。 我正在跟踪上的文档,但它仍然不起作用

以下是我的客户端应用程序代码:

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();
        }           

     }
 };
公共类服务{
公共静态IDuplexOutputChannel myVideoChannel;
公共静态字符串StreamAddr=”udp://192.168.0.145:8093/";
公共静态输出流myVideoStream;
公共静态缓冲输出流;
公共静态字符串pName;
公共静态void main(字符串[]args)引发异常{
JFrame框架;
嵌入式mediaPlayerComponent mediaPlayerComponent;
新国家发现().discover();
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(),“c:\\ProgramFiles(x86)\\videolan\\vlc\\”;
loadLibrary(RuntimeUtil.getLibVlcLibraryName(),LibVlc.class);
IMessagingSystemFactory aMessaging=新的UdpMessagingSystemFactory();
myVideoChannel=aMessaging.createDuplexOutputChannel(StreamAddr);
myVideoChannel.responseMessageReceived().subscribe(MyResponseMessageReceived);
frame=newjframe(“AWWWW!”);
框架.立根(100100600400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mediaPlayerComponent=新嵌入的mediaPlayerComponent();
frame.addWindowListener(新的WindowAdapter(){
@凌驾
公共无效窗口关闭(WindowEvent e){
mediaPlayerComponent.release();
myVideoChannel.closeConnection();
系统出口(0);
}
});      
frame.setContentPane(mediaPlayerComponent);
frame.setVisible(true);
字符串[]mediaOptions={
“:sout=#transcode{vcodec=h264,venc=x264{preset=ultrafast},vb=512}”
+“:std{access=udp,mux=ts}”;
媒体=新的SimpleMedia(StreamAddr、mediaOptions);
mediaPlayerComponent.getMediaPlayer().playMedia(媒体);
myVideoChannel.openConnection();
}
私有静态void onResponseMessageReceived(对象发送方,DuplexChannelMessageEventArgs e)引发IOException
{
字节[]A消息=(字节[])e.getMessage();
System.out.println(“字节消息:“+aMessage”);
myVideoStream.write(aMessage,0,aMessage.length);
bOut=新的缓冲输出流(myVideoStream);
System.out.println(“缓冲输出:“+myVideoStream”);
}
私有静态事件处理程序myOnResponseMessageReceived=新事件处理程序()
{ 
@凌驾
public void onEvent(对象发送方,DuplexChannelMessageEventArgs e)
{
试一试{
onResponseMessageReceived(发件人,e);
}捕获(IOE1异常){
系统输出打印号(“NOPE”);
e1.printStackTrace();
}           
}
};
}

我在编译时没有收到任何错误。它连接到服务器,打开摄像机,但不传输。结束课程后,我得到:

主流错误:无法预填充缓冲区

我将非常感谢您在这方面的帮助。 谢谢