videoCapture not opening correctly in iOS

asked 2016-04-20 16:19:57 -0600

Ben Carpenter gravatar image

I am working on an iOS app that records video then does some processing on that video to create another video file. I'm getting really odd behavior from videoCapture though. It acts like the file has been opened but get() calls seem to return 1 for all the properties I care about (and I know they are not 1). My code looks like this:

VideoCapture cap(fileIn); // open the video file for reading

if ( !cap.isOpened() )  // if not success, exit program
  {
    cout << "Cannot open the video file" << endl;
    return -1;
  }
  else{
    cout << "File Open " << fileIn << endl;
  }

  double dFps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video
  cout << "Frames per second = " << dFps << endl;

  double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
  double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
  cout << "Frame Size = " << dWidth << "x" << dHeight << endl;

  Size frameSize(static_cast<int>(dWidth), static_cast<int>(dHeight));

  double dFrameCount = cap.get(CV_CAP_PROP_FRAME_COUNT);
  cout << "Frame count = " << dFrameCount << endl;

  VideoWriter oVideoWriter (fileOut, CV_FOURCC('m','p', '4', 'v'), dFps, frameSize, true); //initialize the VideoWriter object

  if ( !oVideoWriter.isOpened() ) //if not initialize the VideoWriter successfully, exit the program
  {
    cout << "ERROR: Failed to write the video" << endl;
    return -1;
  }
  else{
    cout << "Output file open." << endl;
  }

and the console output is:

File Open /var/mobile/Containers/Data/Application/7CEE8B87-BD50-4172-8F62-A74AD7F
3C45A/Documents/15318B74-07D9-43EE-932F-224EDCA9CDA7.mov
Frames per second = 1
Frame Size = 1x1
Frame count = 1
Output file open.

I tried changing the file path to an invalid file in case it wasn't finding the file at all but that gave me "Cannot open the video file". Any ideas would be appreciated. I'm thinking it could possibly be a permissions issue because I saw similar behavior when I tried to access a video in the camera roll with this code but this file is in my app's documents directory so I should have full access to it.

edit retag flag offensive close merge delete

Comments

I just found this stackoverflow post where someone had this same problem 2 years ago http://stackoverflow.com/questions/22.... Is openCV videoCapture from a file just completely non-functional on iOS?

Ben Carpenter gravatar imageBen Carpenter ( 2016-04-21 19:41:24 -0600 )edit