简体   繁体   English

使用JavaCV Library接收RTSP流

[英]Recieving RTSP stream With JavaCV Library

I am currently trying to obtain an RTSP stream from an IP camera on my network so that I can apply facial recognition algorithms to the frames (I am using the JavaCV library for this). 我目前正在尝试从网络上的IP摄像头获取RTSP流,以便我可以将面部识别算法应用于帧(我正在使用JavaCV库)。

When I attempt to obtain the RTSP stream, I start getting an error depending upon the method that I tried to use. 当我尝试获取RTSP流时,我开始收到错误,具体取决于我尝试使用的方法。

Here is the code that should work: 这是应该工作的代码:

try {
    FFmpegFrameGrabber streamGrabber = new FFmpegFrameGrabber("rtsp://admin:12345@(ip)/ch1/main/av_stream");
    streamGrabber.setFormat("h264");
    streamGrabber.setFrameRate(30);
    streamGrabber.setImageWidth(getWidth());
    streamGrabber.setImageHeight(getHeight());
    streamGrabber.start();
} catch (Exception e) {
    e.printStackTrace();
}

That particular piece of code gives me this error: 那段特殊的代码给了我这个错误:

org.bytedeco.javacv.FrameGrabber$Exception: avformat_open_input() error -1330794744: Could not open input "rtsp://admin:12345@192.168.64.96/ch1/main/av_stream". (Has setFormat() been called?)
    at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:393)
    at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:341)
    at main.FaceApplet.init(FaceApplet.java:87)
    at sun.applet.AppletPanel.run(AppletPanel.java:425)
    at java.lang.Thread.run(Thread.java:695)

I have tried: 我努力了:

  • Using OpenCVFrameGrabber instead - error says "Could not create camera capture" 改为使用OpenCVFrameGrabber - 错误说“无法创建摄像头捕获”

  • Using IPCameraFrameGrabber - requires http url 使用IPCameraFrameGrabber - 需要http url

  • Changing Protocol: 改变议定书:

    • FTP: Authentication Failed FTP:身份验证失败

    • TCP: Freezes the program TCP:冻结程序

    • UDP: Authentication Failed UDP:身份验证失败

What am I doing wrong, is this a code issue or a camera issue? 我做错了什么,这是代码问题还是相机问题?

Update 更新

I Finally got it working... the magic formula seems to be using the FFMpeggrabber to obtain a stream... to avoid the error, just don't set the video format using the function. 我终于让它工作......神奇的公式似乎是使用FFMpeggrabber来获取流...以避免错误,只是不要使用该功能设置视频格式。 Initializer code should look something like this: 初始化代码应如下所示:

streamGrabber = new FFmpegFrameGrabber("rtsp://admin:12345@(ip):554/live.sdp");
streamGrabber.setFrameRate(30);
streamGrabber.setImageWidth(getWidth());

try {
    streamGrabber.start();
} catch (FrameGrabber.Exception e) {
    e.printStackTrace();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM