I have a android program that streams video via RTSP to a Wowza media server, my OpenCV program then gets this RTSP feed to process.

The problem is the video feed almost immediately gets corrupted and the following errors are output:

```
[h264 @ 0x1f05320] Invalid level prefix
[h264 @ 0x1f05320] error while decoding MB 5 5
[h264 @ 0x1dfb940] Invalid level prefix
[h264 @ 0x1dfb940] error while decoding MB 6 1
[h264 @ 0x1dfbde0] corrupted macroblock 7 5 (total_coeff=-1)
[h264 @ 0x1dfbde0] error while decoding MB 7 5
[h264 @ 0x1dfafe0] corrupted macroblock 7 6 (total_coeff=-1)
 ...

```

I have tried adding `?tcp` to the end of the URL which removes the corrupt frames but leaves me with a large amount of lag that renders the feed useless (it's a real time application).

I have a different program that I use to test the stream and the RTSP feed works fine in that program (using OpenCV as well), it's only when I try to use the same feed in a separate program that computes ORB features that the feed gets corrupted beyond recognition. I'm getting the video like so:

```
  cv::Mat gray;
  CvCapture* img_scene = cvCaptureFromFile("rtsp://193.61.148.73:1935/serg/android_test"); //?tcp
  while(1) { //Create infinte loop for live streaming
    cv::Mat image = cvQueryFrame(img_scene);
    cvtColor(image, gray, CV_BGR2GRAY);

```

The program also streams fine in `ffmeg` using the `tcp`option.

EDIT:

capture thread:

```
Mat captureThread() {
  if(captureOpen == false){
    img_scene = cvCaptureFromFile("rtsp://193.61.148.73:1935/serg/android_test?tcp");
  }
  while(1) {
    image = cvQueryFrame(img_scene);
    cvtColor(image, gray, CV_BGR2GRAY);
    return gray;
  }

```

}

Processing thread:

```
Mat processingThread(Mat gray, Mat img_object) {
  //calculate keypoint and descriptors
  //match keypoints and descriptors
  //draw good matches
  //draw homography
    return imgMatches;
}

```

main:

```
int main(int argc, char *argv[]) {
  img_object = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
  while(1) {
    thread t1(captureThread); 
    t1.join();
    captureOpen = true;
    thread t2(processingThread, gray, img_object);
    t2.join();
    imshow("Output", imgMatches);
    key = cvWaitKey(5);
    if (char(key) == 27) {
      break;
    }  
  }
  return 0;
}

```