performance of videoCapture with gst pipeline

asked 2019-05-22 23:17:13 -0600

abu abdulla gravatar image

updated 2019-05-24 22:22:29 -0600

Hi,

i have 2 files "t1.ts" & "t1_small.ts". t1_small.ts is a 1fps version of the t1.ts (which is 8fps) and generated by gst pipeline:

gst-launch-1.0 -v filesrc location="t1.ts" ! decodebin  ! videorate ! video/x-raw,framerate=1/1 ! omxh264enc ! h264parse ! mpegtsmux ! filesink location=t1_small.ts

Now I'm just reading the frames of those files using

VideoCapture videoCapture = new VideoCapture("t1_small.ts", CAP_GSTREAMER);

and

VideoCapture videoCapture = new VideoCapture("filesrc location=t1.ts ! decodebin ! videorate ! video/x-raw,framerate=1/1 ! videoconvert ! video/x-raw, format=(string)BGR ! appsink", CAP_GSTREAMER);

My question: the first one took 14 seconds (with t1_small) and the second took 28 seconds (t1.ts) even though it read the same number of frames (28 frames total in both cases). the pipeline which generated the smaller file is the same one that we passed to VideoCapture. why there is a big difference in performance

the code that i used for testing

Test(final String path)
{
    final Mat f = new Mat(640, 480, CvType.CV_8UC3);
    final long start = System.nanoTime();

    final VideoCapture videoCapture = new VideoCapture("filesrc location="+path+" ! decodebin ! videorate ! video/x-raw,framerate=1/1 ! videoconvert ! video/x-raw, format=(string)BGR ! appsink", CAP_GSTREAMER);
    //final VideoCapture videoCapture = new VideoCapture(path, CAP_GSTREAMER);

    if (videoCapture.isOpened())
    {
        while (videoCapture.read(f))
        {
            double pos_frame = videoCapture.get(CAP_PROP_POS_FRAMES);
            System.out.println("pos_frame: " + pos_frame);
        }
    }

    f.release();
    videoCapture.release();
    final long milliseconds = (System.nanoTime() - start) / 1000000L;
    System.out.println("[Time]: " + milliseconds / 1000f + " s");
}

Edit: gst pipeline that generates the smaller file took less than a second, hence im expecting OpenCV will take less than 15 seconds instead of the actual 28 sec

edit retag flag offensive close merge delete

Comments

Try appsink sync=false

mshabunin gravatar imagemshabunin ( 2019-05-27 04:47:13 -0600 )edit

appreciated, that's solved the latency issue. now it is 3 seconds instead of 28 seconds

abu abdulla gravatar imageabu abdulla ( 2019-05-27 05:32:47 -0600 )edit