AVFoundation format for different aspect ratio - ios

I am using AVFoundation for my camera app. I am using live video frames to grab picture using AVCaptureVideoDataOutput.
Right now i do filter all supported formats for device and then pick highest supported resolution for format.
So for example i do get 4032*3024 resolution supported format on iPhone 8/7 which i am using as active format. i do filter from videoSupportedFramRateRanges.
I would like to know how i can render video with 4:3 resolution so i can see black bars on side of camera.
I did play with AVCaptureVideoPreviewlayer properties and found that if i use resizeAspectFill it shows camera full screen but if i just dont assign then it adds black bars on side. (I assume .resize is default property) but i am not sure whether this is right approach to show/hide black bars.
In my opinion this is working because currently i am picking highest supported resolution format which in this case is 4032*3024 due to which its working since its 4:3 aspect ratio.
Basically i want make sure i show video in 4:3 format size view in some scenario with black bars and in some scenario full screen which i am already doing.
Open questions
Is there any way i can make sure i can show always 4:3 aspect ratio video feed.
How i can show black bars with 4:3
also after showing black bar how I can get camera area without black bars?
Thanks!

Related

Export portrait video to square but with scaleAspectFit ratio

In my app I allow users to record videos in portrait mode. I use that within the app and that is fine. However, I'm implementing a feature to share the videos on Instagram, where videos must be square.
Cropping the video to square, lets say the center part, is an option, however as the user doesn't consider this when taking the video, it usually turns out bad.
Therefore, I'd like to export the video square, but with an aspect fit ratio and with two bars left and right. Optimally, is there any way to define the colors of the background (either by code or by UIImage).
The closest thing I was able to find is this, however I can't make much use of it as I'm unclear on how to set up the transformation.
Example (red box just to mark the image bounds):
Beside trying to add black bars and re-render the video you can use the cameraOverlayView property of UIImagePickerController.
So you can create a view that has 2 black bars in OR you can create a view that has a square frame over the camera view so they know to frame it in there because it will share to instagram.

How to set zoom level of camera using AVFoundation framework in IOS?

I am developing a custom camera in which the camera is set to the Image Capture mode. I need to increase the zoom level of camera preview according to the app requirements. The preview currently being displayed is perfect I just need to increase the zoom-out in current preview. I searched over internet but didn't find any solution. Please tell me how can I do this. I am attaching the example image for better understanding. first image is of my camera app and second image is of Scanner Pro app which shows view with more covered area while I focus both the apps for the same object on the same distance. My camera don't have any space but the Scanner camera has spacing all over the image. Both the camera are on the same distance from the paper.
i don't know whether you still need this answer. Probably not, but still for you and everyone else looking out:
When you set the Session Preset, try using SessionPresetPhotofor the device object. This should resolve the weird zoom issue.
Your preview view is probably spilling over the edge of the screen. Make sure it is a 4:3 aspect ratio and that it doesn’t overflow your screen edges. With that you should see more of your image.

How do you capture full screen camera photos on iOS?

On Snapchat, it allows you to take a full screen camera photo on iOS. The preview is full screen, and the image returned is full screen. There appears to be no cropping/stretching/etc... What you see is what you get.
Now I've looked all over the place, and I can't figure out how this is actually being done, seeing that the iPhone camera always returns an image with an aspect ratio of 4:3. Yes, you can use the camera view transform to have a full screen "preview", but the image returned is still 4:3 and needs to be cropped.
So my question is, how do you take a full screen camera photo on iOS without cropping? If your answer is that it can't be done, then how is Snapchat doing it (or appearing to do it)?
Snapchat isn't displaying everything the camera is picking up. By cropping a bit from the top/bottom or sides, they can create a 16:9 image from a 4:3 image. This is easy to verify.
Open up the snapchat and camera apps so it's easy to switch between them.
Place your phone on its side pointed at something with some marks for reference points.
Switch between the apps without moving the phone. There is content that you do not see on Snapchat.

How to set up the video size so that it works on all ios devices without black bars

I'm just wondering what size the video should be so that there won't be black bars on iphone 4/5 or ipad? Any suggestion will be appreciated. Thanks!
Since the iPhone 4, iPhone 5, and iPad all have different screen aspect ratios it's impossible to have a single size of video which in full-screen mode won't have black bars on some devices.
Instead, you can use the scalingMode property of MPMoviePlayerController to keep your video zoomed in to fit the screen (assuming that's what you're using to play back your video - similar analogues exist in other video playback classes). You probably want to use the MPMovieScalingModeAspectFill scaling mode, which will fill the video to fit the screen without distorting it.

iPad Video Sizing/Format

I need a full screen portrait video like the following:
What should my export settings be in Adobe After Effects. I know that iPad supports h.264 and up to 640x480. But I need it to fill the 1024x768 in portrait mode. As long as I get the final video looking just as it does in the screenshot is all that matters (meaning no black bars on the sides or anything, just fullscreen video).
The iPad will happily play 720x1280 h.264 video.
So, in your situation, you should be able to render your video out at a width of 768 pixels, and with a corresponding vertical size that matches your video's aspect ratio correctly.

Resources