Ask Your Question

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


I'm using a pre-compiled version of OpenCV I got from here:

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);
cvConvertImage(mCvCaptureImage, mCvConvertImage, CV_CVTIMG_SWAP_RB);
cvWriteFrame(writer, mCvConvertImage );

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?


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

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


Nice Solution. Here is the snippet for python:

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

if cap.isOpened(): width = cap.get( # float height = cap.get( # float fname = 'result.m4v' 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


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

Seen: 1,399 times

Last updated: Mar 08 '13