AVFoundation Camera Preview Screen gives wrong zoom - iphone

I'm currently developing an app that has a camera functionality, with a custom camera screen, featuring a preview screen and an overlay.
I'm using the AVFoundation classes and methods as per the eradication of UIScreenCapture.
The problem I have is that the preview data I get from AVCaptureSession is too zoomed in. If i take a picture with that screen, and another with the iPhone's default camera app, without moving the iPhone, the difference in zoom is far too much.
I need the zoom of my app to be the same as is default for iPhone camera app.
I've tried changing the AVCaptureVideoPreviewLayer.videoGravity, to any of it's 3 possible values, to no avail.
Please, any leads on this problem are truly appreciated.

Arcantos' solution was mostly correct. That will work assuming you're on an iPhone 3G (or any device with a camera that supports 640x480). An iPhone 4 may run into some issues there.
A more correct way would be to test for the availability of and apply this preset:
captureSession.sessionPreset = AVCaptureSessionPresetPhoto;
This will use the raw camera data, regardless of the native resolution.

Turned out to be a resolution issue.
It was fixed by using
myCaptureSession.sessionPreset = AVCaptureSessionPreset640x480
Note that iPhone 3g does not support that, so you have to ask wheter the device supports it
[[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] supportsAvCaptureSessionPreset:AVCaptureSessionPreset640x480]

Is the aspect ratio of your preview pane identical to that of the camera capture data? If not, the OS may be changing the zoom to fit the data rect into your requested aspect ratio.

Related

Is it possible to programmatically capture iPhone 5S slow motion video?

I couldn't find an answer to this question, and looking at Apples own apps like iMovie on iOS, the video picker does not offer a slow motion option on the iPhone 5S.
The image picker offers very little control over the video. If you are willing to dive deeper into the APIs you can use AVFoundation to capture your video and manipulate the camera properties as you see fit.
iOS 7 introduces a new AVCaptureDeviceFormat class that will give you the maximum and minimum supported frame-rates for the capture device, and you can use these to set a custom frame rate on the camera itself. I don't have an iPhone 5S to hand so I can't actually verify whether this API goes all the way down to 120FPS.

Problem in camera activities in ios4

hi so far i have used UIImagePickerController for camera activities in IOS3. But in IOS4 the ImagePickerController is not working properly. When i tried to capture image it shows either a white image or else the app gets crashed often.
So i started using the AVCapture device for my camera activities. In this too i started facing new problems. When i capture the image in landscape the image preview shows the image to be portrait and vice versa. And some times it shows memory level warning.
Both the UIImagePickerController and the AVCapture are making problems. I want to know how to solve these problems. Else is there any other way to handle camera activities in IOS4.
Please help me friends.....
If you just want to enable the user to take photos, UIImagePickerController is the way to go. AVFoundation is quite low level and requires you to handle a lot of things yourself (e.g. compensating for the device orientation).
I've used UIImagePickerController extensively on iOS 4 and it works just fine for me. I suspect the white image/crashing problems are due to something else in your code. If you post a few code snippets we can try to figure out what's going on.

Sepia in Camera Preview View

So I've set up a basic live camera preview view (based on apple's own code from the dev center) and I am now looking for a way to add a nice sepia effect to the live feed.
Is this at all possible? I know it'll be processor and memory heavy but the app is only for iPhone 4, the latest iPod Touch and the iPad 2.
Thanks,
Roy
I dont know how to add filters to camera preview View..But for sepia I think this SO link will be helpful.
Also you will have to go through pixel by pixel. This thread goes through image processing in detail..One good enough to bookmark..

Applying Effect to iPhone Camera Preview "Video" Using OpenGL

My goal is to write a custom camera view controller that:
Can take photos in all four interface orientations with both the back and, when available, front camera.
Properly rotates and scales the preview "video" as well as the full resolution photo.
Allows a (simple) effect to be applied to BOTH the preview "video" and full resolution photo.
My previous effort is documented in this question. My latest attempt was to modify Apple's sample GLVideoFrame (from WWDC 2010). However, I have not been able to get the iPhone 4 to display the preview "video" properly when the session preset is AVCaptureSessionPresetPhoto.
Has anyone tried this or know why the example doesn't work with this preset?
Apple's example uses a preset with 640x480 video dimensions and a default texture size of 1280x720. The iPhone 4 back camera delivers only 852x640 when the preset is AVCaptureSessionPresetPhoto.
iOS device camera video/photo dimensions when preset is AVCaptureSessionPresetPhoto:
iPhone 4 back: video is 852x640 & photos are 2592x1936
iPhone 4 front: video & photos are 640x480
iPod Touch 4G back: video & photos are 960x720
iPod Touch 4G front: video & photos are 640x480
iPhone 3GS: video is 512x384 & photos are 2048x1536
Update
I got the same garbled video result when switching Brad Larson's ColorTracking example (blog post) to use the AVCaptureSessionPresetPhoto.
The issue is that AVCaptureSessionPresetPhoto is now context-aware and runs in different resolutions based on whether you are displaying video or still image captures.
The live preview is different for this mode because it pads the rows with extra bytes. I'm guessing this is some sort of hardware optimization.
In any case, you can see how I solved the problem here:
iOS CVImageBuffer distorted from AVCaptureSessionDataOutput with AVCaptureSessionPresetPhoto
The AVCaptureSessionPresetPhoto is for taking pictures, not capturing live feed. You can read about it here: http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/03_MediaCapture.html
(My belief is that this is actually two different cams or sensors, as they behave very differently, and there's a couple of seconds delay just for switching between the Photo and, say, 640x480).
You can't even use both presets at the same time, and switching between them is a headache as well - How to get both the video output and full photo resolution image in AVFoundation Framework
HTH, although not what you wanted to hear...
Oded.

Is it possible to make persistent full-screen camera like System camera app?

I am building a custom camera app, and would like to have the camera view similar to the native camera app in iPhone. (i.e., picks videos as a non-modal view, stays in the camera view after each video taken. I found the retake and use views unnecessary). Is there any possible way to do it? Thanks.
you can't do it for videos at present, but you can do it for still pictures in OS 3.1. if you search for "takePicture" and "cameraOverlayView" you should find helpful information; you can resize the preview window to be any size you like.