Ask Your Question

Revision history [back]

Java Opencv 3.1 can't open rtsp streaming.

I tried to open rtsp streaming with Opencv 3.1 and Java. But it doesn't open. Meanwhile, I can open a local video with the same code. I also tested the same code with Opencv 2.4.9. there was no problem at all. But there is no VideoWriter in Opencv 2.4.9, so I have to use Opencv 3.X. Is there any solution? Thanks.

package test;
import org.opencv.core.Core;
import org.opencv.videoio.VideoCapture;   //Opencv 3.1
//import org.opencv.highgui.*;  //Opencv 2.4.9
import java.io.IOException;
public class test {
    public static void main(String[] args) throws IOException {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    //String url="C:\\test.avi";
    String url="rtsp://localhost:8554/";
    VideoCapture capture=new VideoCapture();
    capture.open(url);
    if(!capture.isOpened()) {
        System.out.println("Error, can't open the file:"+url);  
    return;
    }
    System.out.println("End");
    capture.release();
}
}

By the way. I believe the path setting is correct.