ios Apple Live Photo 文件格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32508375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 07:35:46  来源:igfitidea点击:

Apple Live Photo file format

iosios9photokitphlivephoto

提问by Clay Bridges

Apple will introduce Live Photoin iOS 9/iPhone 6s. Where is the file format documented?

Apple 将在 iOS 9/iPhone 6s 中引入Live Photo。文件格式记录在哪里?

采纳答案by Sam0711er

Here's the link. Otherwise, here's the text:

这是链接。否则,这里是文本:

Live Photos

Live Photos is a new feature of iOS 9 that allows users to capture and relive their favorite moments with richer context than traditional photos. When the user presses the shutter button, the Camera app captures much more content along with the regular photo, including audio and additional frames before and after the photo. When browsing through these photos, users can interact with them and play back all the captured content, making the photos come to life.

iOS 9.1 introduces APIs that allow apps to incorporate playback of Live Photos, as well as export the data for sharing. There is new support in the Photos framework to fetch a PHLivePhoto object from the PHImageManager object, which is used to represent all the data that comprises a Live Photo. You can use a PHLivePhotoView object (defined in the PhotosUI framework) to display the contents of a Live Photo. The PHLivePhotoView view takes care of displaying the image, handling all user interaction, and applying the visual treatments to play back the content.

You can also use PHAssetResource to access the data of a PHLivePhoto object for sharing purposes. You can request a PHLivePhoto object for an asset in the user's photo library by using PHImageManager or UIImagePickerController. If you have a sharing extension, you can also get PHLivePhoto objects by using NSItemProvider. On the receiving side of a share, you can recreate a PHLivePhoto object from the set of files originally exported by the sender.

Guidelines for Displaying Live Photos

It's important to remember that a Live Photo is still a photo. If you have to display a Live Photo in an environment that doesn't support PHLivePhotoView, it's recommended that you present it as a regular photo.

Don't display the extra frames and audio of a Live Photo separately. It's important that the content of the Live Photo be presented in a consistent way that uses the same visual treatment and interaction model in all apps.

It's recommended that you identify a photo as a Live Photo by placing the badge provided by the PHLivePhotoView class method livePhotoBadgeImageWithOptions:PHLivePhotoBadgeOptionsOverContent in the top-left corner of the photo.

Note that there is no support for providing the visual effect that users experience as they swipe through photos in the Photos app.

Guidelines for Sharing Live Photos

The data of a Live Photo is exported as a set of files in a PHAssetResource object. The set of files must be preserved as a unit when you upload them to a server. When you rebuild a PHLivePhoto with these files on the receiver side, the files are validated; loading fails if the files don't come from the same asset.

If your app lets users apply effects or adjustments to a photo before sharing it, be sure to apply the same adjustments to all frames of the Live Photo. Alternatively, if you don't support adjusting the entire contents of a Live Photo, share it as a regular photo and show an appropriate indication to the user.

If your app has UI for picking photos to share, you should let users play back the entire contents so they know exactly what they are sharing.When selecting photos to share in your app, users should also be able to turn a Live Photo off, so they can post it as a traditional photo.

实况照片

Live Photos 是 iOS 9 的一项新功能,它允许用户用比传统照片更丰富的背景来捕捉和重温他们最喜欢的时刻。当用户按下快门按钮时,相机应用程序会与常规照片一起捕获更多内容,包括音频和照片前后的附加帧。在浏览这些照片时,用户可以与它们互动并回放所有捕获的内容,使照片变得栩栩如生。

iOS 9.1 引入了允许应用程序合并实时照片播放以及导出数据以进行共享的 API。照片框架中新增了从 PHImageManager 对象获取 PHLivePhoto 对象的支持,该对象用于表示构成 Live Photo 的所有数据。您可以使用 PHLivePhotoView 对象(在 PhotosUI 框架中定义)来显示 Live Photo 的内容。PHLivePhotoView 视图负责显示图像、处理所有用户交互以及应用视觉处理来回放内容。

您还可以使用 PHAssetResource 访问 PHLivePhoto 对象的数据以进行共享。您可以使用 PHImageManager 或 UIImagePickerController 为用户照片库中的资产请求 PHLivePhoto 对象。如果你有共享扩展,你也可以通过使用 NSItemProvider 来获取 PHLivePhoto 对象。在共享的接收端,您可以从最初由发送者导出的文件集重新创建一个 PHLivePhoto 对象。

显示实时照片的准则

重要的是要记住 Live Photo 仍然是照片。如果您必须在不支持 PHLivePhotoView 的环境中显示 Live Photo,建议您将其呈现为普通照片。

不要单独显示 Live Photo 的额外帧和音频。Live Photo 的内容以一致的方式呈现,在所有应用程序中使用相同的视觉处理和交互模型,这一点很重要。

建议您通过将 PHLivePhotoView 类方法 livePhotoBadgeImageWithOptions:PHLivePhotoBadgeOptionsOverContent 提供的徽章放置在照片的左上角来将照片识别为实况照片。

请注意,不支持提供用户在“照片”应用中轻扫照片时所体验到的视觉效果。

共享实况照片的准则

Live Photo 的数据导出为 PHAssetResource 对象中的一组文件。将文件集上传到服务器时,必须将其作为一个单元保留。当您在接收器端使用这些文件重建 PHLivePhoto 时,这些文件将被验证;如果文件不是来自同一资产,则加载失败。

如果您的应用允许用户在共享照片之前对其应用效果或调整,请确保对 Live Photo 的所有帧应用相同的调整。或者,如果您不支持调整 Live Photo 的全部内容,请将其作为常规照片共享并向用户显示适当的指示。

如果你的应用有选择照片分享的用户界面,你应该让用户回放整个内容,这样他们就知道他们分享了什么。在你的应用中选择照片分享时,用户还应该能够关闭实时照片,这样他们就可以将其作为传统照片发布。

回答by russbishop

A live photo has two resources. They are tied together with an asset identifier (a UUID as a string).

实时照片有两个资源。它们与资产标识符(作为字符串的 UUID)绑定在一起。

  1. A JPEG; this must have a metadata entry for kCGImagePropertyMakerAppleDictionarywith [17 : assetIdentifier](17 is the Apple Maker Note Asset Identifier key).
  2. A Quicktime MOV encoded with H.264 at the appropriate framerate (12-15fps) and size (1080p). This MOV must have:
    • Top-level Quicktime Metadata entry for ["com.apple.quicktime.content.identifier" : assetIdentifier]. If using AVAssetyou can get this from asset.metadataForFormat(AVMetadataFormatQuickTimeMetadata)
    • Timed Metadata track with ["com.apple.quicktime.still-image-time" : 0xFF]; The actual still image time matches up to the presentation timestamp for this metadata item. The payload seems to just be a single 0xFFbyte (aka -1) and can be ignored. If using an AVAssetReaderyou can use CMSampleBufferGetOutputPresentationTimeStampto get this time.
  1. 一个JPEG;这必须有一个元数据条目kCGImagePropertyMakerAppleDictionary[17 : assetIdentifier](17是苹果机注资产识别键)。
  2. 以适当的帧速率 (12-15fps) 和大小 (1080p) 使用 H.264 编码的 Quicktime MOV。该 MOV 必须具有:
    • 的顶级 Quicktime 元数据条目["com.apple.quicktime.content.identifier" : assetIdentifier]。如果使用AVAsset你可以从asset.metadataForFormat(AVMetadataFormatQuickTimeMetadata)
    • 定时元数据跟踪["com.apple.quicktime.still-image-time" : 0xFF];实际静止图像时间与此元数据项的演示时间戳相匹配。有效载荷似乎只是一个0xFF字节(又名 -1),可以忽略。如果使用一个,AVAssetReader您可以使用它CMSampleBufferGetOutputPresentationTimeStamp来获得这个时间。

The assetIdentifieris what ties the two items together and the timed metadata track is what tells the system where the still image sits in the movie timeline.

assetIdentifier将两个项目联系在一起,定时元数据轨道告诉系统静止图像在电影时间轴中的位置。

回答by MobileVet

Outside of the documentation, Live Photos are made up of 2 resources, an image and an mov (quicktime movie file). So every Live Photo has 2 'actual' files connected by the wrapper of the Live Photo type.

在文档之外,Live Photos 由 2 个资源组成,一个图像和一个 mov(快速电影文件)。因此,每张 Live Photo 都有 2 个“实际”文件,由 Live Photo 类型的包装器连接。

回答by dongkang

Live Photos is actually two files. Original JPEG Image and Full HD Video.

Live Photos 实际上是两个文件。原始 JPEG 图像和全高清视频。

回答by pkamb

Uniform Type Identifier (UTI) for the format is kUTTypeLivePhoto/ com.apple.live-photo

格式的统一类型标识符 (UTI) 是kUTTypeLivePhoto/com.apple.live-photo

@available(OSX 10.12, *)
public let kUTTypeLivePhoto: CFString

/*
 *
 *  kUTTypeLivePhoto
 *
 *    Live Photo
 *
 *    UTI: com.apple.live-photo
 *
 *
 */

回答by Kyo

some additional info about live photos:

关于实时照片的一些附加信息:

  1. agree, it has .mov file extension
  2. it saved in directory /var/mobile/media/DCIM/100apple/ alongside with jpg version of photo
  3. live photos can be played even on device without 3D touch (I can play it on my ipad 2017 via long-pressing on the photo)
  4. it can be played even on old phones (such as iphone 5) even on iOS8 if you install PhotosLive tweak
  1. 同意,它有 .mov 文件扩展名
  2. 它与 jpg 版本的照片一起保存在目录 /var/mobile/media/DCIM/100apple/ 中
  3. 即使在没有 3D 触摸的设备上也可以播放实时照片(我可以通过长按照片在 ipad 2017 上播放)
  4. 如果您安装了 PhotosLive 调整,它甚至可以在旧手机(如 iphone 5)上播放,甚至在 iOS8 上