julapy / ofxiOSVideoWriter

ofxiOSVideoWriter allows to screen record OF applications on iOS. (still very much a work in progress)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crashes on 2nd recording

aferriss opened this issue · comments

The addon works great for the first recording, but if I try to use it more than once after launching the app it crashes with :

'NSInvalidArgumentException', reason: '*** -[AVAssetWriter initWithURL:fileType:error:] invalid parameter not satisfying: outputURL != ((void *)0)'

FWIW I added the saveMovieToCameraRoll method call finishRecording() to ofxiOSVideoWriter.mm. So now it looks like

void ofxiOSVideoWriter::finishRecording() {
    if((videoWriter == nil) ||
       [videoWriter isWriting] == NO) {
        return;
    }

    [videoWriter finishRecording];
    [videoWriter saveMovieToCameraRoll];

    killTextureCache();
    cout<<"Finishing"<<endl;
}

And in my ofApp I'm calling the videoWriter like so in touchDown:

     save = !save;
      if(save){
          videoWriter.startRecording();
      } else {
          videoWriter.finishRecording();
      }

I logged the fileURL being passed into the startRecording method and found that on the second go round the url=null. I traced this to saveMovieToCameraRoll commented out line ~586 which was setting self.outputUrl = nil;. Once I did that is seems to save for multiple videos :D

commented

hey @aferriss, i had a chance to play with this addon again for one of my projects.
agree that it should not crash when recording the second time and i'll try to resolve that soon.
but the way ive been using it, is i create the ofxiOSVideoWriter for one recording and destroy it when im finished with it. maybe in the meantime you can apply the same approach and it should work fine.

@julapy thanks for the follow up, that makes sense. I also saw this on the apple docs.

You can only use a given instance of AVAssetWriter once to write to a single file. If you want to write to files multiple times, you must use a new instance of AVAssetWriter each time.

I think this can be closed. The solution here is just to do

writer = new ofxiOSVideoWriter();

when you want to save a new video.