2013-11-25 67 views
2

我想捕捉AXIS相機&流式傳輸。我對RED5相當陌生。我得到以下錯誤:RED5 AXIS相機捕捉和流式傳輸

Exception in thread "main" java.lang.NullPointerException at org.vikulin.rtmp.publisher.Publisher2.packetReceived(Publisher2.java:23) at org.red5.server.presentation.output.flv.FLVStream.dispatchEvent(FLVStream.java:243) at org.red5.server.presentation.output.flv.FLVStream.sendAVCDecoderConfig(FLVStream.java:162) at org.red5.server.presentation.output.flv.FLVStream.addEvent(FLVStream.java:76) at org.red5.server.presentation.MediaPresentation.onMediaEvent(MediaPresentation.java:43) at org.red5.server.presentation.input.avp.codecs.H264.addPacket(H264.java:206) at org.red5.server.presentation.RTSPStream.onRTSPEvent(RTSPStream.java:100) at org.red5.server.net.rtsp.proxy.RtspTcp.setupAndPlay(RtspTcp.java:287) at org.red5.server.presentation.RTSPStream.onSDP(RTSPStream.java:138) at org.red5.server.net.rtsp.proxy.RtspTcp.parseDescription(RtspTcp.java:128) at org.red5.server.net.rtsp.proxy.RtspTcp.describe(RtspTcp.java:64) at org.red5.server.presentation.RTSPStream.startInput(RTSPStream.java:77) at org.red5.server.presentation.RTSPStream.start(RTSPStream.java:82) at org.vikulin.rtmp.publisher.Publisher2.main(Publisher2.java:49)

下面是代碼:

import java.io.IOException; 
import org.red5.server.api.stream.IBroadcastStream; 
import org.red5.server.api.stream.IStreamListener; 
import org.red5.server.api.stream.IStreamPacket; 
import org.red5.server.net.rtmp.event.VideoData; 
import org.red5.server.presentation.RTSPStream; 
import org.red5.server.stream.message.RTMPMessage; 
import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 

public class Publisher2 implements IStreamListener { 

    PublishClient client; 

    @Override 
    public void packetReceived(IBroadcastStream arg0, IStreamPacket arg1) { 
     System.out.println("" + arg1); 
     VideoData data = new VideoData(arg1.getData()); 
     RTMPMessage message = RTMPMessage.build(data); 
     try { 
      client.pushMessage(message); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 

    public static void main(String[] args) throws IOException, InterruptedException { 

     Logger log = LoggerFactory.getLogger(Publisher2.class); 
     String publishName = "testb"; 
     String host = "127.0.0.1"; 
     int port = 1935; 
     String app = "live"; 
     PublishClient client = new PublishClient(); 
     client.setHost(host); 
     client.setPort(port); 
     client.setApp(app); 
     client.start(publishName, "live", null); 
     while (client.getState() != PublishClient.PUBLISHED) { 
      Thread.sleep(500); 
     } 

     Publisher2 test = new Publisher2(); 
     final RTSPStream camera = new RTSPStream("192.168.254.115", 554, 
       "rtsp://192.168.254.115/axis-media/media.amp?videocodec=h264&videokeyframeinterval=30&fps=30"); 
     camera.addStreamListener(test); 

     new Thread(new Runnable() { 
      @Override 
      public void run() { 
       camera.start(); 
      } 
     }).start(); 

     try { 
      Thread.sleep(30000); 
     } catch (InterruptedException e) { 
      e.printStackTrace(); 
     } 
     camera.stop(); 
     try {//wait for write out. 
      Thread.sleep(3000); 
     } catch (InterruptedException e) { 
      e.printStackTrace(); 
     } 
     client.stop(); 
    } 
} 

如果您有任何想法,請幫助我!

+0

請讓我知道它是否會工作。 – Yoda

+0

你能否請你多發一些你的項目速度分享哪些caputers相機數據..我爲它爭取了第3天。 – Yoda

+0

請發佈它我無法修復該項目的構建路徑。 – Yoda

回答

2

您在主方法中聲明瞭client變量,但在您的packetReceived方法中,引用了類變量。此時,類變量仍爲空。因此,有可能改變這一行:

PublishClient client = new PublishClient(); 

這樣:

client = new PublishClient(); 

或通過客戶端在你的方法,並從類中刪除變量聲明。

+0

非常感謝,它正在工作! :) – Kalman