RTSP stream in Java (Eclipse) VideoCapture.read() error

asked 2015-09-20 03:11:20 -0600

zebox gravatar image

updated 2015-09-20 03:30:10 -0600

Hi for All!

I try develope application on Java with OpenCV wich must grab rtsp stream from DVR. My code as every example:

import org.opencv.videoio.VideoCapture;

    public class Main {
    static {

        System.loadLibrary("opencv_java300");
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        VideoCapture cap = new VideoCapture("rtsp://admin:[email protected]/h264/ch1/main/av_stream");
                try {
            System.out.println("Delay waiting..");
            Thread.sleep(10000); // wait while stream open from dvr
            System.out.println("Delay end..");
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }

        if (!cap.isOpened()) {
            System.exit(-1);
        }
         System.out.println("Prepare to Get frame..");
        // Matrix for storing image
                Mat image = new Mat();
                // Frame for displaying image
                MyFrame frame = new MyFrame(); // Some frame creation custom class
                frame.setVisible(true);

                // Main loop
                while (true) {
                    // Read current camera frame into matrix

                    cap.read(image);  
                     System.out.println("Geting frame..");
                        try {
                            System.out.println("Frame delay waiting..");
                            Thread.sleep(500);
                            System.out.println("Delay end..");
                        } catch(InterruptedException ex) {
                            Thread.currentThread().interrupt();
                        }
                    // Render frame if the camera is still acquiring images
                    if (image != null) {
                        frame.render(image);
                    } else {
                        System.out.println("No captured frame -- camera disconnected");
                        break;
                    }
                }
    }

But I get some frames to my (JFram+JPanel) window and run stop at this line

cap.read(image);

after some wait I get error:

GStreamer Plugin: Embedded video playback halted; module source reported: Could not read from resource.
OpenCV Error: Unspecified error (GStreamer: unable to start pipeline) in icvStartPipeline, file /home/myuser/git/opencv/modules/videoio/src/cap_gstreamer.cpp, line 383
Exception in thread "main"

I understand, this error report about rtsp sourcce problem, but if I get this stream in VLC, video work fine.

This problem only rtsp stream. If I try grab local media file or webcam all work fine. :(

OS: LinuxMint 17.2, OpenCV 3.0.0

Please help!

edit retag flag offensive close merge delete