Delay to load and delayed stream

asked 2015-12-13 14:21:27 -0500

maco1717 gravatar image

updated 2015-12-17 12:55:09 -0500

Im running this code:

#include <iostream>
#include <sstream>
#include <ctime>
#include <string>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;
using namespace std;

int main()
    //create matrix for storage
    Mat feed, feed2;

    //initialize capture
    VideoCapture cap, cap2;"");"");

    // check if we succeeded
    if (!cap.isOpened()){
        cerr << "Failed to open video capture" << std::endl;
        cout << "cannot open camera";
        return -1;
    if (!cap2.isOpened()){
        cerr << "Failed to open video capture" << std::endl;
        cout << "cannot open camera";
        return -1;

    //create window to show image
    namedWindow("VIDEO", 1); 

    while (true){

        //copy webcam stream to image
        cap >> feed;
        cap2 >> feed2;

        resize(feed, feed, Size(1270, 700), 0, 0, INTER_CUBIC);
        resize(feed2, feed2, Size(320, 170), 0, 0, INTER_CUBIC);

        feed2.copyTo(feed(cv::Rect(874,463,feed2.cols, feed2.rows)));
        //small_image.copyTo(big_image(cv::Rect(x,y,small_image.cols, small_image.rows)));

        imshow("VIDEO", feed);

        //exit it key pressed
        if (waitKey(30) >= 0){


I've got a Raspberry pi with a USB composite capturer running FFMPEG on server with the following setup:


Port 80
MaxClients 10
MaxBandwidth 50000

<Feed webcam.ffm>
file /tmp/webcam.ffm
FileMaxSize 10M

<Stream webcam.mjpeg>
Feed webcam.ffm
#Format mpjpeg
Format avi
VideoSize 320x170
VideoBufferSize 5
VideoFrameRate 10
VideoBitRate 500
VideoQMin 1
VideoQMax 10

and the command:

ffserver -f /etc/ffserver.conf & ffmpeg -v verbose -r 10 -s 320x170 -f video4lilinux2 -i /dev/video0 http://localhost/webcam.ffm

When I use only one of the stream I can get delays or should I say I have a delay of 5 seconds which is acceptable, but when I have both stream I get a 20 seconds delay. I have looked around and there seam to be some bugs but looks like 2 years ago.

Is there any way to know what could be causing this? and how could I solve it? reducing the size buffer? I've noticed the the one of the stream from an IP camera come without delay

edit retag flag offensive close merge delete


The IPCam creating the issues is a USB/Composite capture on a Raspberry Pi with FFMPEG, I think FFMPEG is the source of the issue.

maco1717 gravatar imagemaco1717 ( 2015-12-15 08:03:14 -0500 )edit

I'm going to re-edit my post later today, I've done some progress, looks like the ffmpeg server was properly setup or there was better ways of setting it up. Im going to re-edit my post later my program is still hanging and im getting a 20second delay on that stream...

maco1717 gravatar imagemaco1717 ( 2015-12-17 03:46:35 -0500 )edit

I've edited with progress and new findings, changed the title as it;s not hanging anymore... xP

maco1717 gravatar imagemaco1717 ( 2015-12-17 12:57:37 -0500 )edit