title: OpenCV VideoCapture works inconsistently
body: <p>I have been trying to get my application using OpenCV to work for a while now and a longstanding error which I cannot seem to fix is this one:</p>
  
  <p><strong>PROBLEM:</strong></p>
  
  <p>OpenCV's VideoCapture is inconsistent in splitting video into frames for different file formats and codecs.</p>
  
  <p><strong>Specifics:</strong></p>
  
  <p>My errors are in one part of the application: splitting videos into frames. There are three current scenarios when I choose a valid directory for VideoCapture and open it. It either: </p>
  
  <ul>
  <li><p>Opens and works perfectly. </p></li>
  <li><p>Is able to open the VideoCapture (cap.isOpened() = true) but receives an empty frame or two during the frame split which causes app to throw error.</p></li>
  <li><p>Does not open at all. </p></li>
  </ul>
  
  <p>A given video will only do one of those three things. AVI File formats seem to have most of the errors, though.</p>
  
  <p><strong>Fixes tried:</strong></p>
  
  <ul>
  <li><p>Installing K-Lite Codec Pack Full </p></li>
  <li><p>Putting OpenCV_FFMPEG.dll and OpenCV_FFMPEG_64.dll in project directory and in PATH </p></li>
  </ul>
  
  <p>The only explanation I can think of is this is an error with the way I installed OpenCV and FFmpeg.</p>
  
  <p>Any help would be greatly appreciated! Thanks.</p>
  
  <p>By the way, I am running Qt 5.8.0 and OpenCV 3.2.0 and this is my FrameSplit code. </p>
  
  <pre><code>vector&lt;int&gt; mainFrame::frameSplit(string filename, string location)
  {
  
  //Extract + Save Frames
  
  string vidDir = filename;
  string locationDir = location + "/frames/";
  VideoCapture cap(vidDir);
  
  if (!cap.isOpened())
  {
      qDebug() &lt;&lt; "OO";
      return {};
  }
  else
  {
      Mat firstFrame;
      Mat nextFrame;
      Mat frame;
      int count = 1;
  
      QProgressDialog progress("Extracting files...", "Abort", 0, cap.get(CV_CAP_PROP_FRAME_COUNT));
      progress.setWindowModality(Qt::WindowModal);
      progress.setAttribute(Qt::WA_DeleteOnClose, true);
      progress.setFixedSize(500, 100);
      progress.show();
  
      vector&lt;int&gt; compression_params;
      compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
      compression_params.push_back(100);
      qDebug() &lt;&lt; cap.get(CV_CAP_PROP_FRAME_COUNT);
      bool failure = false;
  
      for (count = 1; count &lt; cap.get(CV_CAP_PROP_FRAME_COUNT); count++)
      {
          cap &gt;&gt; frame;
          if(frame.empty()) {
              QMessageBox messageBox;
              messageBox.critical(this, "Error", "There was an error in analyzing the video. Please try and install the appropriate codecs and try again.");
              messageBox.setFixedSize(600,400);
              vector&lt;int&gt; empty;
              return empty;
          }
  
          string filePath = locationDir + to_string(count) + ".jpg";
          imwrite(filePath,frame,compression_params);
          progress.setValue(count);
      }
  
      progress.setValue(count);
      progress.close();
      vector&lt;int&gt; props;
      props.push_back(cap.get(CV_CAP_PROP_FRAME_COUNT));
      props.push_back(round(cap.get(CV_CAP_PROP_FPS)));
      props.push_back(cap.get(CV_CAP_PROP_FRAME_WIDTH));
      props.push_back(cap.get(CV_CAP_PROP_FRAME_HEIGHT));
  
      qDebug() &lt;&lt; props[0];
  
      return props;
  }
  </code></pre>
  
  <p>}</p>