Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`PHAssetChangeRequest.creationRequestForAssetFromVideo(url:)` fails for high FPS videos on iPhone SE

We have gotten reports of issues with recording slow motion videos in our application. We have tested the issue on iPhone X, iPhone 6, and iPhone SE. The 6 and the X both work fine, but the SE fails when attempting to add the recorded video to Photos.


The video file to be added to Photos:

  • h.264 with recommended settings
  • Quicktime (.mov)
  • 120/200/240 FPS
  • No custom metadata
  • AAC audio with recommended settings

Our code adding the video:

PHPhotoLibrary.shared().performChanges {  
    PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: url)  
}  

The returned error doesn't provide much useful information, which appears to be a recurring issue when working with Photos.

Error Domain=NSCocoaErrorDomain Code=-1 "(null)"  

We apply an aspect ratio to the videos using the encoder setting's clean aperture parameters. Apparently, changing the video aspect ratio affects the result (see the list at the bottom).


We have tried:

  • Because the aspect ratio affected the result, we thought the issue might be related to the amount of data to be stored. Reducing the bitrate/file size did not change anything
  • Perhaps something was still using the file? We waited a few seconds before adding the file, but were awarded the same errors
  • Scoured the docs, dev forum, SO, blogs, and general google to no avail

Once again - everything works fine on iPhone X and 6.

The resolution-fps-ratio combinations and their result:

1080p

720p


Have you got any clue what the issue might be?

like image 894
Oyvindkg Avatar asked Jan 13 '18 20:01

Oyvindkg


1 Answers

EDIT #4

Ok this one came back to bite me again, and I probably spent another two hours trying to figure out how it regressed since the code was not touched and previously confirmed working. I initially thought it had to be device or encoding related. I ended up "fixing" it, but it makes zero sense to me. The issue was resolved after I appended .mov to the local file that was being used to store the remote video after downloading. Why appending an arbitrary extension to the file path makes a difference is beyond me.

let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let temporaryFilename = "\(ProcessInfo().globallyUniqueString).mov"
let fileURL = documentsURL.appendingPathComponent(temporaryFilename)
like image 61
Ryan Romanchuk Avatar answered Oct 14 '22 23:10

Ryan Romanchuk