Video Capture read() does not maintain average fps in live source (rtsp)

asked 2019-03-29 06:05:11 -0600

isra60 gravatar image

I have a Videcapture from a gstreamer pipeline decoding a rtsp live video source like this.

     std::string url = "rtspsrc location=\"rtsp://10.50.84.90:554/video\" ! rtph264depay ! 
h264parse ! omxh264dec !nvvidconv ! appsink";

    cap = cv::VideoCapture(url, cv::CAP_GSTREAMER);

This RTSP source is 25 FPS.

So when I read the VideoCapture

while(GetIsEnabled())
    {   
        auto start = Time::now();

        cap.read(frame); // get a new frame from camera

        auto stop = Time::now();
        fsec duration = stop - start;
        double sec = duration.count();

        std::cout << sec << std::endl;

    }

So is a simple code. The read function should takes 1/25 seconds (40 ms) which is correct FPS for this live source.

But the problem is that about 45 frames the read() functions takes 0.040 s but next frames one frames takes about 1,2 seconds and then again 0.040 s for about 45 frames and then 1,2 seconds on a ciclical way. So is like a buffering problem on the videoCapture....

First 1.94455 0.0365482 0.0398777 0.0399188 0.0398196 0.0398707 0.03987 0.0398344 0.0398238 0.0398676 0.0398434 0.0398025 0.039824 0.0398552 0.0398008 0.0398447 0.0398314 0.0397902 0.0397909 0.0398242 0.0396902 0.0398541 0.0397996 0.0397923 0.0398382 0.0398741 0.0398043 0.039907 0.0398481 0.0396058 0.0398907 0.0398943 0.039851 0.0398694 0.0398956 0.0398612 0.0398758 0.0398799 0.0399229 0.0398939 0.0398739 0.0407076 0.0390691 0.0398869 0.0399134 0.0398756 0.0398228 0.0398746 0.0399477 0.0398827 1.05469 0.0387482 0.0393513 0.0399019 0.0397187 0.0398703 0.0398886 0.0400598 0.0397441 0.0398578 0.0401261 0.0395911 0.0395848 0.0397852 0.0398798 0.0398565 0.0398583 0.0398787 0.039886 0.0398738 0.0398994 0.0398276 0.0398856 0.039886 0.0398599 0.0417738 0.0379762 0.039914 0.0399085 0.0398066 0.0398577 0.039905 0.0397811 0.0398493 0.0399005 0.0398563 0.0398839 0.0398544 0.0399005 0.0398594 0.0401235 0.039611 0.039879 0.0398736 0.0398621 0.0398791 0.0398836 1.07945 0.0387574 0.0392607 0.0398517 0.0399115 0.0397899 0.0399933 0.0393552 0.0398316 0.0399184 0.0398585 0.0399113 0.0398585 0.0399204 0.0398939 0.03988 0.0398431 0.0398953 0.0398903 0.0398801 0.0398683 0.0399001 0.0398979 0.039884 0.0398578 0.0398722 0.0398792 0.0399119 0.0398538 0.039918 0.0400012 0.0397819 0.0398938 0.0398457 0.0399094 0.0398285 0.0399329 0.0398495 0.039903 0.0398749 0.041429 0.0400453 0.0381844 0.0418925 1.03989 0.0386266 0.0390446 0.0398802 0.0398858 0.0405464 0.0392022 0.0399134 0.0398917 0.0398823 0.0398996 0.0398835 0.0398919 0.0398987 0.0398619 0.0398852 0.0399033 0.0398144 0.039934 0.0398858 0.0398342 0.0399304 0.0410084 0.0387642 0.0409218 0.0388674 0.0400005 0.0397526 ...

(more)
edit retag flag offensive close merge delete