When saving recorded video that is too long, app crashes

前端 未结 2 1592
Happy的楠姐
Happy的楠姐 2021-01-05 12:02

The problem:

When saving a video that is recorded in my app, if the video size/duration is too big/long, my app crashes without a log/exception.

相关标签:
2条回答
  • 2021-01-05 12:22

    why bother pulling the entire contents of the media stream from
    [[info objectForKey:UIImagePickerControllerMediaURL] path] into an NSData* and then writing them back out? your media stream is going to be huge!

    the reason this is happening at save is because you are recording the data, it is going to "disk", and then you read it into memory to write it back out to another disk file.

    have you considered using NSFileManager to copy the file from [[info objectForKey:UIImagePickerControlMediaURL] path] to the name you create (fullPath) ? this should avoid pulling the whole thing into memory; it should be a "file-to-file" transfer.

    0 讨论(0)
  • 2021-01-05 12:29

    Your problem is this line:

    [NSData dataWithContentsOfPath:self.tempVideoPath]
    

    You are clearly trying to load the contents of this file to memory all at once, but iOS will never let you load that much at one time. Your saveVideo method seems to only copy the file from temporary location to the documents directory. If this is the only thing that you need to do there, then take a look at copyItemAtPath:toPath:error method of NSFileManager. Your could change the saveVideo method to take the temporary file path as a parameter, rather than the data.

    0 讨论(0)
提交回复
热议问题