【问题标题】:[iOS]How convert Video to LivePhoto?[iOS]如何将视频转换为LivePhoto?
【发布时间】:2016-01-14 09:25:51
【问题描述】:

如何将video 转换为LivePhoto

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

}

谢谢。

【问题讨论】:

  • 你的意思是问,如何像facebook那样播放视频?
  • 不,使用 ImagePicker。视频文件到 LivePhoto(ios9)

标签: ios objective-c phlivephoto


【解决方案1】:
/// 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;

【讨论】:

【解决方案2】:

使用 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;

【讨论】:

    【解决方案3】:

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

    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 以获取代码参考。

    【讨论】:

      【解决方案4】:

      在最新的 iOS SDK 中无法将其他文件转换为 Live Photo,但是一些工具应用程序可以做到这一点,例如 Live Studio。并且可能有一些在线教程解释了如何从其他文件中制作Live Photo,您可以从中学习。也许你可以用 iOS 来研究一种方法。

      祝你好运!

      【讨论】:

      • 谢谢您的回答。我想知道最新的iOS SDK是没有办法的吗?那么,最旧的 iOS SDK 可用了吗?
      • 我的意思是最新的 iOS SDK 没有提供简单的 API 来直接将文件转换为 Live Photo,但可能还有其他一些方法,例如 AVFoundation.Anyway,需要了解更多关于 frame rate 的信息!
      猜你喜欢
      • 2015-11-07
      • 2017-10-17
      • 2014-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多