2

How to convert a video to a LivePhoto?

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {

}

Thank you.

jcaron
  • 17,302
  • 6
  • 32
  • 46
minjoongkim
  • 121
  • 1
  • 12

4 Answers4

0
/// Requests a Live Photo from the given resource URLs. The result handler will be called multiple times to deliver new PHLivePhoto instances with increasingly more content. If a placeholder image is provided, the result handler will first be invoked synchronously to deliver a live photo containing only the placeholder image. Subsequent invocations of the result handler will occur on the main queue.
//  The targetSize and contentMode parameters are used to resize the live photo content if needed. If targetSize is equal to CGRectZero, content will not be resized.
//  When using this method to provide content for a PHLivePhotoView, each live photo instance delivered via the result handler should be passed to -[PHLivePhotoView setLivePhoto:].
+ (PHLivePhotoRequestID)requestLivePhotoWithResourceFileURLs:(NSArray<NSURL *> *)fileURLs placeholderImage:(UIImage *__nullable)image targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode resultHandler:(void(^)(PHLivePhoto *__nullable livePhoto, NSDictionary *info))resultHandler;
Ankit Srivastava
  • 12,347
  • 11
  • 63
  • 115
  • But another app can convert. and https://github.com/genadyo/LivePhotoDemo project is possible. but i don't know objective-c convert. – minjoongkim Jan 14 '16 at 09:35
  • can you give the URL..? Maybe they have created a custom component of their own. But I didn't see anything in the apple API. – Ankit Srivastava Jan 14 '16 at 09:36
  • and This App is possible. https://itunes.apple.com/kr/app/intolive-turns-your-videos/id1061859052?l=en&mt=8 – minjoongkim Jan 14 '16 at 09:38
  • and i find this way. http://stackoverflow.com/questions/32893993/is-there-a-way-to-save-a-live-photo-to-the-photo-library but not work. – minjoongkim Jan 14 '16 at 09:41
  • The answer saves this data to photo library . There is no clue as to how they do it. Maybe you can look at my edited answer and use it – Ankit Srivastava Jan 14 '16 at 09:53
0

using PHLivePhoto class method you can create any MOV video to live photo

+(PHLivePhotoRequestID)requestLivePhotoWithResourceFileURLs:(NSArray<NSURL *> *)fileURLs placeholderImage:(UIImage *__nullable)image targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode
 resultHandler:(void(^)(PHLivePhoto *__nullable livePhoto, NSDictionary *info))resultHandler;
Chandan
  • 500
  • 3
  • 10
0

Converting a video is a little tricky task. The process is following

  1. first one imageUrl and one videoUrl is required to make a live photo
  2. add one metadata to that image file which is content identifier
  3. add the same content identifier metadata to the video file
  4. add another metadata to the video which is the frame timestamp for the image which will be shown as thumbnail(the image used in the 1st step)

After adding the metadata in the image and video file use the following api

PHLivePhoto.request(withResourceFileURLs fileURLs: [URL], placeholderImage image: UIImage?, targetSize: CGSize, contentMode: PHImageContentMode, resultHandler: @escaping (PHLivePhoto?, [AnyHashable : Any]) -> Void) -> PHLivePhotoRequestID

Please check this answer which has a beautiful explanation of the required metadata for making live photo object.

And you can check the following GitHub project for the code reference.

Learner
  • 621
  • 6
  • 9
-4

There is no way to convert other files to Live Photo in newest iOS SDK, however some tool applications can do that such as Live Studio. And there maybe some tutorials online that explain how to make Live Photo from other files, which you can learn with. Perhaps you can excogitate one way with iOS.

Wish For You!

SeraZheng
  • 187
  • 8
  • Thank you your Answer. i wonder is newest iOS SDK is no way? So, oldest iOS SDK is available? – minjoongkim Jan 14 '16 at 09:57
  • I mean that newest iOS SDK doesn't provide simpleness API to directly convert files to Live Photo but there maybe some other ways, such as AVFoundation.Anyway, that needs learn more about `frame rate` or something! – SeraZheng Jan 14 '16 at 10:02