Ask Your Question
0

CvVideoWriter WriteFrame for iOS not working

asked 2013-02-22 02:23:04 -0500

koppen gravatar image

updated 2013-02-22 02:26:59 -0500

Hi!

I'm using a pre-compiled version of OpenCV I got from here: http://aptogo.co.uk/2011/09/opencv-framework-for-ios/

I'm working on a Ogre3D Application, and I'm trying to grab screens from the app to stitch together to make a video. I've successfully gotten this to work on Windows using OpenCV's CvVideoWriter.

Unfortunately, I'm running into some problems on the iOS version of this. My code is as follows:

IplImage *mCvCaptureImage, *mCvConvertImage;
mCvCaptureImage = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
mCvConvertImage = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
PixelFormat pf = win->suggestPixelFormat();
PixelBox pb(width, height, 1, pf, mCvCaptureImage->imageData);
                        win->copyContentsToMemory(pb);
cvConvertImage(mCvCaptureImage, mCvConvertImage, CV_CVTIMG_SWAP_RB);
cvWriteFrame(writer, mCvConvertImage );
cvReleaseImage(&mCvConvertImage);
cvReleaseImage(&mCvCaptureImage);

The cvWriteFrame call is throwing an error due to writer status check. I checked the source code, and this seems to be the problem:

// writer status check
if (![mMovieWriterInput isReadyForMoreMediaData] || mMovieWriter.status !=  AVAssetWriterStatusWriting ) {
         NSLog(@"[mMovieWriterInput isReadyForMoreMediaData] Not ready for media data or ...");
         NSLog(@"mMovieWriter.status: %d. Error: %@", mMovieWriter.status, [mMovieWriter.error localizedDescription]);
         [localpool drain];
         return false;
}

Anyone has any ideas why this is happening and how it can be fixed?

Thanks!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-03-08 06:27:32 -0500

atrebbi gravatar image

Change the file extension to m4v and delete existing file before calling cvCreateVideoWriter()

( opencv chooses filetype looking at file extension )

edit flag offensive delete link more

Comments

Nice Solution. Here is the snippet for python:

import cv2, os cap = cv2.VideoCapture('myvideo.mp4')

if cap.isOpened(): width = cap.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH) # float height = cap.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT) # float fname = 'result.m4v' fourcc = cv2.cv.CV_FOURCC(*'XVID') out = cv2.VideoWriter(fname,fourcc, 20.0, (int(width), int(height)))

if os.path.exists(fname): os.remove(fname)

PatrickT gravatar imagePatrickT ( 2017-03-03 07:28:21 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-02-22 02:23:04 -0500

Seen: 1,460 times

Last updated: Mar 08 '13