[iOS]如何将视频转换为LivePhoto?

时间:2016-01-14 09:25:51

标签: ios objective-c phlivephoto

如何将video转换为LivePhoto

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

}

谢谢。

4 个答案:

答案 0 :(得分: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;

答案 1 :(得分:0)

使用PHLivePhoto类方法,您可以创建任何MOV视频到实时照片

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

答案 2 :(得分:0)

转换视频是一项有点棘手的任务。流程如下

  1. 制作现场照片需要第一个 imageUrl 和一个 videoUrl
  2. 向该图像文件添加一个元数据,即内容标识符
  3. 向视频文件添加相同的内容标识符元数据
  4. 向视频添加另一个元数据,即图像的帧时间戳,该图像将显示为缩略图(第一步中使用的图像)

在图片和视频文件中添加元数据后使用下面的api

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

请查看 this answer,其中对制作实时照片对象所需的元数据进行了精美的解释。

您可以查看 following GitHub project 以获取代码参考。

答案 3 :(得分:-2)

在最新的iOS SDK中无法将其他文件转换为Live Photo,但某些工具应用程序可以执行此操作,例如Live Studio。并且可能有一些在线教程解释如何从其他文件中创建Live Photo,您可以学习。也许你可以通过iOS激发一种方式。

祝你好运!