Photos & Camera

RSS for tag

Explore technical aspects of capturing high-quality photos and videos, including exposure control, focus modes, and RAW capture options.

Post

Replies

Boosts

Views

Activity

Taking Lossless Picture
I am following these directions to code picture taking: https://www.appcoda.com/avfoundation-swift-guide/ These directions are for taking jpeg shots. But what is needed is to output to a lossless format such as DNG, PNG, or BMP. How would those instructions be modified to output pictures in a lossless format? Is there a tutorial similar to the one linked to above that explains how to do lossless formats?
1
0
615
Jul ’23
PHAssetChangeRequest.creationRequestForAsset() Crashes
There is a crash on the closing brace of the photo capture completion handler where commented below. // Initiate image capture: cameraController.captureImage(){ ( image: UIImage?, error: Error? ) in // This closure is the completion handler, it is called when // the picture taking is completed. print( "camera completion handler called." ) guard let image = image else { print(error ?? "Image capture error") return } try? PHPhotoLibrary.shared().performChangesAndWait { PHAssetChangeRequest.creationRequestForAsset(from: image) } // crash here } When step through pauses on that closing brace, and the next step is taken, there is a crash. Once crashed what I see next is assembly code as shown in the below disassembly: libsystem_kernel.dylib`: 0x1e7d4a39c <+0>: mov x16, #0x209 0x1e7d4a3a0 <+4>: svc #0x80 -> 0x1e7d4a3a4 <+8>: b.lo 0x1e7d4a3c4 ; <+40> Thread 11: signal SIGABRT 0x1e7d4a3a8 <+12>: pacibsp 0x1e7d4a3ac <+16>: stp x29, x30, [sp, #-0x10]! 0x1e7d4a3b0 <+20>: mov x29, sp 0x1e7d4a3b4 <+24>: bl 0x1e7d3d984 ; cerror_nocancel 0x1e7d4a3b8 <+28>: mov sp, x29 0x1e7d4a3bc <+32>: ldp x29, x30, [sp], #0x10 0x1e7d4a3c0 <+36>: retab 0x1e7d4a3c4 <+40>: ret Obviously I have screwed up picture taking somewhere. I would much appreciate suggestions on what diagnostics will lead to the resolution of this problem. I can make the entire picture taking code available on request as an attachment. It is too lengthy to post here.
1
0
635
Jul ’23
Can the permission dialog to access the photo library be bypassed?
This handler in my photo app: cameraController.captureImage(){ ( image: UIImage?, error: Error? ) in // This closure is the completion handler, it is called when the picture taking is completed. if let error = error { print( "camera completion handler called with error: " + error.localizedDescription ) }else{ print( "camera completion handler called." ) } // If no image was captured return here: guard let image = image else { print(error ?? "Image capture error") return } var phpPhotoLib = PHPhotoLibrary.shared() if( phpPhotoLib.unavailabilityReason.debugDescription != "nil" ){ print( "phpPhotoLib.unavailabilityReason.debugDescription = " + phpPhotoLib.unavailabilityReason.debugDescription ) }else{ // There will be a crash right here unless the key "Privacy - Photo Library Usage Description" exists in this app's .plist file try? phpPhotoLib.performChangesAndWait{ PHAssetChangeRequest.creationRequestForAsset(from: image) } } } asks the user for permission to store the captured photo data in the library. It does this once. It does not ask on subsequent photo captures. Is there a way for app to bypass this user permission request dialog, or at least present it to the user in advance of triggering a photo capture when the app first runs? In this situation the camera is being used to capture science data in a laboratory setting. The scientist using this app already expects, and needs, the photo to be stored. The redundant permission request dialog makes the data collection cumbersome, and inconvenient, due to the extra effort required to reach the camera where it is located.
1
0
557
Jul ’23
How to look up Photo Pixel Formate Types?
I listed the AVCapturePhotoSettings.availablePhotoPixelFormatTypes array in my iPhone 14 during a running photo session and I got these type numbers: 875704422 875704438 1111970369 I have no idea what these numbers mean. How can I use these numbers to look up a human readable string that can tell me what these types are in a way I am familiar with, such as jpeg, tiff, png, bmp, dng, etc, so I know which of these numbers to choose when I instantiate the class: AVCaptureSession?
1
0
972
Jul ’23
Virtual machine device passthrough
Hi there-- Ive been trying to recreate an issue with a camera app im developing on a clean install. I can easily start up a new VM with VirtualBuddy, UTM or Parallels but Im having trouble getting a camera device to passthrough. Parallels seems to be the most promising but whenever I try to connect it, there is an error. Does anyone have advice on the best VM provider to use to passthrough usb devices or native cameras? Thanks!
0
0
927
Jul ’23
How to Instantiate AVCapturePhotoSettings( format: [string:string] )
I tried various ways to instantiate the class: AVCapturePhotoSettings as listed below: let settings = AVCapturePhotoSettings(format: [ kCVPixelBufferPixelFormatTypeKey : "BGRA"] ) let settings = AVCapturePhotoSettings(format: [ kCVPixelBufferPixelFormatTypeKey as String : "BGRA"] ) let settings = AVCapturePhotoSettings(format: [ String( kCVPixelBufferPixelFormatTypeKey) : "BGRA"] let settings = AVCapturePhotoSettings(format: [ "kCVPixelBufferPixelFormatTypeKey" : "BGRA"] ) The first method gets the error: Cannot convert value of type 'CFString' to expected dictionary key type 'String' and so the three other attempts below this were done, but each of these attempts got the run time error: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[AVCapturePhotoSettings photoSettingsWithFormat:] Either kCVPixelBufferPixelFormatTypeKey or AVVideoCodecKey must be specified' What is the correct way to use this initiator for the class: AVCapturePhotoSettings ?
0
0
507
Jul ’23
What are the available NSSortDescriptors for PHFetchOptions?
I'm working with Apple's sample code for PhotoBrowse. In the main view controller's viewDidLoad() method we have this code: let allPhotosOptions = PHFetchOptions() allPhotosOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)] This code sorts the photos by "creationDate". How do I determine/find the other valid values for these sort descriptors? For example, what if I wanted to sort photos by their file size, last modified date, etc.? TIA!
2
0
435
Aug ’23
PHAsset unique identifier across devices.
I know that I can uniquely identify a PHAsset on a given device using localIdentifier but if that asset is synched (through iCloud, say) to another device, how to I uniquely identify that asset across multiple devices? My app allows users to store their images in the standard photo gallery, but I have no way of referring to them when they sync their app profile to another iOS device with my app installed.
2
0
741
Aug ’23
Is there a technical reason why Photos.app/PhotoKit does not support displaying file sizes?
It is 2023 and Photos.app still provides no way to sort photos/movies by file size. I ended up writing some AppleScript that displays the file sizes of images/movies in a specific album. It is also simple to create a shell script to examine the photo library contents directly but mapping the UUID-based filenames back to the names used in Photos.app is not straightforward (to me at least). You can't even create a smart album based upon file size. Why is there no native support for this in Photos.app/PhotoKit? (And, yes, I have submitted many feature requests over the years)
0
0
392
Aug ’23
AVCam vs Apple Photo App for stabilized video recording
I have build a video recording app based on https://developer.apple.com/documentation/avfoundation/capture_setup/avcam_building_a_camera_app I have exteded the sample to use stabilization, but I am not near getting as good results as I get from using the Apple Photo App. The only thing I seem to be able to control from AVFoundation is https://developer.apple.com/documentation/avfoundation/avcaptureconnection/1620484-preferredvideostabilizationmode Do Apple use different APIs than what is available from AVFoundation? Best, Thomas Hagen
0
0
307
Aug ’23
AVCam vs Apple Photo App for stabilized video recording
Why do Apple’s builtin Photo app produce videos with better image stabilization than what I can get when I enable cinematicextended as preferred stabilization using the AVCapture API? Ref: https://developer.apple.com/documentation/avfoundation/avcapturevideostabilizationmode/cinematicextended I have based my work on https://developer.apple.com/documentation/avfoundation/capture_setup/avcam_building_a_camera_app Do the Apple Photo app use another API or some Apple properitary algoritms to achieve a better result than what’s available using the AvFoundation API? Best, Thomas Hagen
0
0
318
Aug ’23
Understanding PHPickerConfiguration.AssetRepresentationMode.current
The documentation for this API mentions: The system uses the current representation and avoids transcoding, if possible. What are the scenarios in which transcoding takes place? The reason for asking is that we've had a user reaching out saying they selected a video file from their Photos app, which resulted in a decrease in size from ~110MB to 35MB. We find it unlikely it's transcoding-related, but we want to gain more insights into the possible scenarios.
3
1
619
Aug ’23
setExposureTargetBias handler problem
Hello everybody! I use video session and in delegate method didOutputSampleBuffer I get CMSampleBuffer. That's all right. But at some point, I want to change the exposure to -2, +2 and make images from the buffer. I use the setExposureTargetBias method and everything changes successfully, but there is one problem - I need to understand when exactly the buffer with the changed value (-2.0, +2.0 etc.) will be. The description says what to use CMTime syncTime from the setExposureTargetBias closure, which will be the future timestamp of the buffer with applied changes, but here there is a complete mismatch - when I compare these syncTime timestamp with buffer from didOutputSampleBuffer, the exposure is still in the process of changing. How to determine that exactly this buffer (its time stamp) corresponds exactly to the time stamp at which exposure bias changes will already be applied?
0
0
303
Aug ’23
AVFoundation low-light mode to match native camera's
I'm trying to get AVFoundation to provide the same low-light boost provided in the native camera app. I have tried: isLowLightBoostSupported (which always returns false, regardless of my configuration) setExposureTargetBias set to max AVCaptureSessionPreset set to various options without success Is automaticallyEnablesLowLightBoostWhenAvailable outdated? The documentation claims "capture device that supports this feature may only engage boost mode for certain source formats or resolutions", but with no explanation of which formats or resolutions. I can't tell if the option is no longer supported, or if there is some configuration permutation I haven't yet found.
1
0
383
Sep ’23
Crash in photolibraryd Process During Import in Photos.app & PHAsset.fetchAssets() Call
Problem: While calling PHAsset.fetchAssets() and iterating over its results, if the Photos.app is simultaneously running an import operation (File | Import), the photolibraryd process crashes. I have already flagged this issue to Apple (FB13178379) but wanted to check if anyone else has encountered this behavior. Steps to Reproduce: Initiate an import in the Photos.app. Run the following code snippet in the Playground: import Photos PHPhotoLibrary.requestAuthorization(for: .readWrite) { authorizationStatus in guard authorizationStatus == .authorized else { return } let fetchResult = PHAsset.fetchAssets(with: nil) print(fetchResult) for i in 0..<fetchResult.count { print(fetchResult[i]) } } Upon doing this, I consistently receive the error: Connection to assetsd was interrupted - photolibraryd exited, died, or closed the photo library in the Console, causing my code to hang. Environment: macOS Version: 13.5.2 (22G91) Xcode Version: Version 14.3.1 (14E300c) Additional Info: After the crash, a report pops up in the Console, and typically, the Photos.app import operation freezes too. I've noticed that after terminating all processes and/or rebooting, the Photos.app displays "Restoring from iCloud…" and the recovery process lasts overnight. Seeking Suggestions: I'm exploring potential workarounds for this issue. I've attempted to use fetchLimit to obtain assets in batches, but the problem persists. Is there a method to detect that the Photos.app is executing an import, allowing my process to wait until completion? Alternatively, can I catch the photolibraryd crash and delay until it's restored? I'm operating in a batch processing mode for photos, so pausing and retrying later in the event of a Photos.app import isn't an issue. Any guidance or shared experiences would be greatly appreciated! Cheers and happy coding!
1
0
498
Sep ’23