Giter Site home page Giter Site logo

livephoto's Introduction

LivePhotoIcon

LivePhoto.swift

A single-file helper library to work with Apple Live Photos

A Live Photo is a paired camera photo ("key photo") and video recording ("paired video"). Learn more about Live Photos from our in-depth blog post.

Live Photo format

A Live Photo consists of two resources paired using an asset identifier (a UUID string):

  1. JPEG image with special metadata for kCGImagePropertyMakerAppleDictionary with [17 : assetIdentifier]
  2. Quicktime MOV with
    1. Quicktime metadata for ["com.apple.quicktime.content.identifier" : assetIdentifier]
    2. Timed metadata track with ["com.apple.quicktime.still-image-time" : 0xFF]. This lets the system know where the still image sits in the movie timeline.

LivePhoto.swift

The entire library is contained in the LivePhoto.swift file:

Extracting Resources from PHLivePhoto

LivePhoto.extractResources(from: livePhoto, completion: resources -> Void) {
  let pairedImageURL = resources.pairedImageURL
  let pairedVideoURL = resources.pairedVideoURL
}

Generating a Live Photo & Saving it to the Photo Library

LivePhoto.generate(from: photoURL, videoURL: videoURL, progress: { percent in }, completion: { livePhoto, resources in
  // Display the Live Photo in a PHLivePhotoView
  livePhotoView.livePhoto = livePhoto
  // Or save the resources to the Photo library
  LivePhoto.saveToLibrary(resources)
  })

livephoto's People

Contributors

jpagliaro avatar pagliara avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

livephoto's Issues

output LivePhoto cannot be used as Live Wallpaper on iOS 17

Hello,

the new iOS cannot set any live photo as a Live Wallpaper giving an error "Motion is not available"

after seeing Live Photo info that it can be set as a Live Wallpaper that is made from camera app

I found that the file extension is .heic

Nothing happens when paired video has no audio

If paired video has no sound, there is no completion in
func addAssetID(_ assetIdentifier: String, toVideo videoURL: URL, saveTo destinationURL: URL, progress: @escaping (CGFloat) -> Void, completion: @escaping (URL?) -> Void)

because of that line
guard writingAudioFinished && writingVideoFinished else { return } in
func didCompleteWriting()

Write input video metadata to Live Photo output

Is it possible to have the video or photo metadata embedded in the resulting Live Photo when assembling?
Items such as camera make/model, location, timestamp etc etc are all preserved in the resulting Live Photo.

I had a go at this myself, but I could never get the written metadata to show in the Photos app.

Get Crash about AVAssetReaderTrackOutput

image

2 kind of crash

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '*** -[AVAssetReaderTrackOutput copyNextSampleBuffer] cannot copy next sample buffer before adding this output to an instance of AVAssetReader (using -addOutput:) and calling -startReading on that asset reader'

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '*** -[AVAssetReader startReading] cannot be called again after reading has already started'
terminating with uncaught exception of type NSException

Doesn't work with files in project

I've tried with files in your project but it doesn't work

let p = Bundle.main.url(forResource: "keyPhoto", withExtension: "jpg", subdirectory: "")
		let f = Bundle.main.url(forResource: "pairedVideo", withExtension: "mov", subdirectory: "")
		
		LivePhoto.generate(from: p, videoURL: f!, progress: { (percent) in
			DispatchQueue.main.async {
				//self.progressView.progress = Float(percent)
			}
		}) { (livePhoto, resources) in
			if let resources = resources {
				LivePhoto.saveToLibrary(resources, completion: { (success) in
					if success {
						print("ok")
					}
					else {
						print("error")
					}
				})
			}
		}

No error, nothing saved

Crash `-[AVAssetReaderTrackOutput copyNextSampleBuffer] cannot copy next sample buffer before adding this output to an instance of AVAssetReader (using -addOutput:) and calling -startReading on that asset reader'` and `-[AVAssetReader startReading] cannot be called again after reading has already started'`

Hi, I've got crash with different messages (or 2 crashes) while I'm trying to generate live photo from video and image URLs. Can't understand what's the problem. Any ideas?

2021-05-10 15:23:19.847032+0300 wawi[66088:2374894] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '*** -[AVAssetReaderTrackOutput copyNextSampleBuffer] cannot copy next sample buffer before adding this output to an instance of AVAssetReader (using -addOutput:) and calling -startReading on that asset reader'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff20422fba __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x00007fff20193ff5 objc_exception_throw + 48
	2   AVFCore                             0x00007fff58033cce -[AVAssetReaderOutput _figAssetReaderSampleBufferDidBecomeAvailableForExtractionID:] + 0
	3   AVFCore                             0x00007fff58034b1a -[AVAssetReaderTrackOutput copyNextSampleBuffer] + 68
	4   wawi                                0x0000000106969fd8 $s4wawi9LivePhotoC10addAssetID_7toVideo6saveTo8progress10completionySS_10Foundation3URLVAKy12CoreGraphics7CGFloatVcyAKSgctFyycfU_ + 712
	5   wawi                                0x000000010696c3d5 $s4wawi9LivePhotoC10addAssetID_7toVideo6saveTo8progress10completionySS_10Foundation3URLVAKy12CoreGraphics7CGFloatVcyAKSgctFyycfU_TA + 149
	6   wawi                                0x0000000106956be0 $sIeg_IeyB_TR + 48
	7   AVFCore                             0x00007fff58050061 -[AVAssetWriterInputMediaDataRequester requestMediaDataIfNecessary] + 84
	8   libdispatch.dylib                   0x0000000107f4b578 _dispatch_call_block_and_release + 12
	9   libdispatch.dylib                   0x0000000107f4c74e _dispatch_client_callout + 8
	10  libdispatch.dylib                   0x0000000107f52f9a _dispatch_lane_serial_drain + 796
	11  libdispatch.dylib                   0x0000000107f53c67 _dispatch_lane_invoke + 436
	12  libdispatch.dylib                   0x0000000107f5fa7a _dispatch_workloop_worker_thread + 872
	13  libsystem_pthread.dylib             0x00007fff603404c0 _pthread_wqthread + 314
	14  libsystem_pthread.dylib             0x00007fff6033f493 start_wqthread + 15
)
2021-05-10 15:23:19.847687+0300 wawi[66088:2374877] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '*** -[AVAssetReader startReading] cannot be called again after reading has already started'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff20422fba __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x00007fff20193ff5 objc_exception_throw + 48
	2   AVFCore                             0x00007fff58032c3c -[AVAssetReader cancelReading] + 0
	3   wawi                                0x0000000106967726 $s4wawi9LivePhotoC10addAssetID_7toVideo6saveTo8progress10completionySS_10Foundation3URLVAKy12CoreGraphics7CGFloatVcyAKSgctF + 6086
	4   wawi                                0x0000000106961705 $s4wawi9LivePhotoC8generate33_0AFEC2D7860C58E9650C095B4B75C939LL4from8videoURL8progress10completiony10Foundation0O0VSg_ALy12CoreGraphics7CGFloatVcySo06PHLiveC0CSg_AL11pairedImage_AL0W5VideotSgtctF + 2597
	5   wawi                                0x000000010695d02e $s4wawi9LivePhotoC8generate4from8videoURL8progress10completiony10Foundation0G0VSg_AKy12CoreGraphics7CGFloatVcySo06PHLiveC0CSg_AK11pairedImage_AK0O5VideotSgtctFZyycfU_ + 158
	6   wawi                                0x000000010695d37a $s4wawi9LivePhotoC8generate4from8videoURL8progress10completiony10Foundation0G0VSg_AKy12CoreGraphics7CGFloatVcySo06PHLiveC0CSg_AK11pairedImage_AK0O5VideotSgtctFZyycfU_TA + 202
	7   wawi                                0x0000000106956be0 $sIeg_IeyB_TR + 48
	8   libdispatch.dylib                   0x0000000107f4b578 _dispatch_call_block_and_release + 12
	9   libdispatch.dylib                   0x0000000107f4c74e _dispatch_client_callout + 8
	10  libdispatch.dylib                   0x0000000107f4f066 _dispatch_continuation_pop + 557
	11  libdispatch.dylib                   0x0000000107f4e47b _dispatch_async_redirect_invoke + 770
	12  libdispatch.dylib                   0x0000000107f5e1b0 _dispatch_root_queue_drain + 351
	13  libdispatch.dylib                   0x0000000107f5eb0f _dispatch_worker_thread2 + 135
	14  libsystem_pthread.dylib             0x00007fff6034047a _pthread_wqthread + 244
	15  libsystem_pthread.dylib             0x00007fff6033f493 start_wqthread + 15
)
libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '*** -[AVAssetReader startReading] cannot be called again after reading has already started'
terminating with uncaught exception of type NSException
CoreSimulator 757.5 - Device: iPhone 12 Pro (C113BE89-6822-4BD2-B7B0-1213E58C24D3) - Runtime: iOS 14.5 (18E182) - DeviceType: iPhone 12 Pro

How to set saved playback type when saving to the photo library

This is a fantastic insight into Live Photos like I've not seen anywhere else. Thankyou.

My only issue is, how do you go about setting the playback mode the LivePhoto is saved as?
I'd like to have all my LivePhotos saved in "Bounce" playback mode by default & not the standard saved "Live" mode. How can you accomplish this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.