How to open a video stream

asked 2016-10-17 20:01:28 -0500

YKC gravatar image

updated 2016-10-18 01:59:32 -0500

LBerger gravatar image

I am trying to open the video being streamed from Intel Edison which is written in node.js. ffmpeg is used to encode video to MPEG1 whereas jsmpeg is used to decode the video. The video is rendered onto canvas element in the web browser.

The coding as follow. I can't view the video in openCV.

int main()  
{  
  VideoCapture vcap1;

   Mat stream1;
   Mat grains(480,640,CV_8UC3,Scalar::all(0));
   const string videoStreamAddress1 = "http://192.168.8.100:8082";
vcap1.set(CV_CAP_PROP_FOURCC, CV_FOURCC('P','I','M','1'));

 if(!vcap1.open(videoStreamAddress1)) {
    cout << "Error opening video stream1" << endl;
    }  
   if(!vcap2.open(videoStreamAddress2)) {
    cout << "Error opening video stream2 " << endl;
    }

   for(;;){   
     if(!vcap1.read(stream1)) {
         putText(grains, std::string("Stream  not avilable....."), cv::Point(150,200),  cv::FONT_HERSHEY_COMPLEX_SMALL, 1, cv::Scalar(0,255,0,255));
         imshow("Stream 1", grains);
     }
     else
      imshow("Stream 1", stream1);

if(waitKey(33) >= 0) break;
     }  
    return 0;
}
edit retag flag offensive close merge delete

Comments

some comments : You cannot set CV_CAP_PROP_FOURCC before stream is opened. what is videoStreamAddress2? You should tryy something like this:

  VideoCapture vcap1;

   Mat stream1;
   const string videoStreamAddress1 = "http://192.168.8.100:8082";

   if(!vcap1.open(videoStreamAddress1)) {
       cout << "Error opening video stream1" << endl;
    }  
   else
       for(char c=0;c!=27;){   
      cap1>>stream1;
      imshow("Stream 1", stream1);
      c = waitKey(33);
}

You can try this example too

LBerger gravatar imageLBerger ( 2016-10-18 02:06:32 -0500 )edit

hi Thanks for your reply. I still can't open the video using openCV. I just can view it in web browser.

Actually, can openCV open MPEG1 format video? since the video is encoded to MPEG1. Thanks

YKC gravatar imageYKC ( 2016-10-18 05:27:00 -0500 )edit