I am familiar with the simple solution of just streaming over the devices screen, and bringing up a preview window and just showing the camera preview.
let picker: UIImagePickerController = CustomUIImagePickerController()
picker.delegate = self;
picker.sourceType = .camera
picker.setNavigationBarHidden(true, animated: false)
picker.mediaTypes = [kUTTypeMovie as String, kUTTypeImage as String]
picker.cameraCaptureMode = UIImagePickerController.CameraCaptureMode.video
picker.videoQuality = UIImagePickerController.QualityType.typeHigh
picker.showsCameraControls = false
picker.cameraViewTransform.ty += 100;
present(picker, animated: true, completion: nil)
The above solution only streams at a resolution of the device screen. I need a way to use the iPhone back camera as a 4k 30fps webcam. I know I can use AVCam to Write a video to file with 4k # 30fps, but I don't know how to stream it over USB.
Related
In an app ported to Mac Catalyst, the camera interface always turned out to be blank.
I have checked: the capabilities includes "Camera", the privacy setting in info.plist is there (the iPad app shows the camera fine), and I even try to include front camera for UIImagePickerController.
if UIImagePickerController.isSourceTypeAvailable(.camera) {
let imagePicker = UIImagePickerController()
imagePicker.sourceType = .camera
imagePicker.delegate = self
imagePicker.cameraDevice = .front // added for Mac
self.present(imagePicker, animated:true, completion:nil)
}
The error I got is: "[Generic] Could not create video device input: Error Domain=AVFoundationErrorDomain Code=-11814"
I have the same mistake, I'm afraid it's a bug ...
Everything works correctly on iOS and iPadOS.
For the moment I think there's no way to make it work...
You need Requesting Authorization for Media Capture on macOS
import AVFoundation
AVCaptureDevice.requestAccess(for: .video) { granted in
let ctrl = UIImagePickerController()
ctrl.sourceType = .camera
self.present(ctrl, animated: true, completion: nil)
}
Add to info.plist
<key>NSCameraUsageDescription</key>
<string> .... </string>
As shown Screen shot i want to hide seek bar from camera, when i choose to capture video from my App through UIImagepickerController but am unable to hide this video and photo option
Use following code to get your expected output, set mediaTypes property as [kUTTypeMovie as String] to capture only video.
let controller = UIImagePickerController()
controller.sourceType = .camera
controller.videoMaximumDuration = 30.0 .
controller.allowsEditing = true
controller.mediaTypes = [kUTTypeMovie as String]
controller.delegate = self
controller.isEditing = true
present(controller, animated: true, completion: nil)
I'm trying to upload my video chosen from library or recorded from camera to firebase. When I get the video from library there's a "choose" button on the image picker or when I record the video it says "Use video".
I think to run those buttons function you have to write the didFinishPickingMediaWithInfo function. But nothing happens when I record a video and click "choose" this is what I have as my code:
if (UIImagePickerController.isSourceTypeAvailable(.camera)) {
if UIImagePickerController.availableCaptureModes(for: .rear) != nil {
//if the camera is available, and if the rear camera is available, the let the image picker do this
imagePicker.sourceType = .camera
imagePicker.mediaTypes = [kUTTypeMovie as String]
imagePicker.allowsEditing = false
imagePicker.delegate = self as? UIImagePickerControllerDelegate & UINavigationControllerDelegate
imagePicker.videoMaximumDuration = 60
imagePicker.videoQuality = .typeIFrame1280x720
present(imagePicker, animated: true, completion: nil)
} else {
postAlert("Rear camera doesn't exist", message: "Application cannot access the camera.")
}
} else {
postAlert("Camera inaccessable", message: "Application cannot access the camera.")
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
print("didFinishPickingMediaWithInfo")
}
I want it to at least print to know that the video "choose button" is working. Any ideas on how to get the choose button to work? Any help would be kind. Thank you in advance!
Following code works good when capturing photo using camera, but app crashes when user taps on video.
let imagePicker = UIImagePickerController()
imagePicker.modalPresentationStyle = .currentContext
imagePicker.delegate = self
if let _ = UIImagePickerController.availableMediaTypes(for: .camera) {
imagePicker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .camera)!
if UIImagePickerController.isSourceTypeAvailable(.camera) {
imagePicker.sourceType = .camera
present(imagePicker, animated: true, completion: nil)
}
}
I had a similar problem and it was due to not asking for microphone usage permission in my Info.plist.
Check that you have a proper value for:
NSCameraUsageDescription (Privacy - Camera Usage Description)
NSMicrophoneUsageDescription (Privacy - Microphone Usage Description)
NSPhotoLibraryUsageDescription (Privacy - Photo Library Usage Description)
Then when you change from photo mode to video mode your app will ask for microphone access instead of just crashing.
Looking for help with an image picker. The picker is functioning properly - however - it allows the user to pick from Panorama photos as well as normal photos on their device.
I want to have the picker only allow the user to choose non panorama pictures.
I looked through the dev document and couldn't find anything about this. Any help appreciated! Here's my code:
#IBAction func selectImage(sender: AnyObject) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType =
UIImagePickerControllerSourceType.PhotoLibrary
imagePicker.mediaTypes = [kUTTypeImage as NSString]
imagePicker.allowsEditing = false
self.clearBtn.hidden = false
self.presentViewController(imagePicker, animated: true,
completion: nil)
}
func imagePickerController(picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
self.dismissViewControllerAnimated(true, completion: nil)
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
self.postImage.contentMode = .ScaleAspectFit
self.postImage.image = image
self.hasPicture = true
}
I know that changing the UIImagePickerControllerSourceType to .PhotoLibrary will only allow picking from the camera roll, but I was hoping to still allow shared photo streams and such that just weren't panoramic.
As Christian posted in a comment - there is no native way for a UIImagePicker to only allow certain types of pictures (excluding panorama).
You have to handle validating the image after it is returned.