RED5 AXIS相机捕捉&流

时间:2013-11-25 14:54:39

标签: java red5

我想拍摄一张AXIS相机&流吧。我对RED5很新。我收到以下错误:

  

线程“main”中的异常java.lang.NullPointerException at   org.vikulin.rtmp.publisher.Publisher2.packetReceived(Publisher2.java:23)     在   org.red5.server.presentation.output.flv.FLVStream.dispatchEvent(FLVStream.java:243)     在   org.red5.server.presentation.output.flv.FLVStream.sendAVCDecoderConfig(FLVStream.java:162)     在   org.red5.server.presentation.output.flv.FLVStream.addEvent(FLVStream.java:76)at   org.red5.server.presentation.MediaPresentation.onMediaEvent(MediaPresentation.java:43)     在   org.red5.server.presentation.input.avp.codecs.H264.addPacket(H264.java:206)     在   org.red5.server.presentation.RTSPStream.onRTSPEvent(RTSPStream.java:100)     在   org.red5.server.net.rtsp.proxy.RtspTcp.setupAndPlay(RtspTcp.java:287)     在org.red5.server.presentation.RTSPStream.onSDP(RTSPStream.java:138)     在   org.red5.server.net.rtsp.proxy.RtspTcp.parseDescription(RtspTcp.java:128)     在org.red5.server.net.rtsp.proxy.RtspTcp.describe(RtspTcp.java:64)     在   org.red5.server.presentation.RTSPStream.startInput(RTSPStream.java:77)     在org.red5.server.presentation.RTSPStream.start(RTSPStream.java:82)     在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();
    }
}

如果您有任何想法,请帮助我!

1 个答案:

答案 0 :(得分:2)

您在main方法中声明了一个client变量,但是在您的packetReceived方法中,您引用了类变量。此时类变量仍为null。所以,可能会改变这一行:

PublishClient client = new PublishClient();

到此:

client = new PublishClient();

或将客户端传递给您的方法,并从您的类中删除变量声明。