Scale the video up from a smaller size(Re-scale) - ios

I'm actually looking for is to not just the quality but resize the entire video to a greater resolution using the AV foundation.
I have a videos in 320x240 and 176x144 in mp4 quality and I want to resize video upto size 1280x720, but AVAssetExportSession class not allow to scale the video up from a smaller size.

try AVMutableVideoCompositionLayerInstruction and CGAffineTransform.
This code will help the understanding.
https://gist.github.com/zrxq/9817265

Related

Objective-C How do I compress the video ONLY and not the video AND text overlay?

I am basically using AVAssetExportSession and AVMutableVideoComposition to add my text overlay on top of the video and then compress the video. At the moment, when I compressed the video to AVAssetExportPresetMediumQuality, it also ruined the quality of the text overlay... I dont want this to happen. I just want to lower the quality on the video ONLY and keep the text overlay on top of the video sharp and not pixelated.
Thank You
Compress the video, then add the text overlay.

Unable to render video with size greater than 640x640

I am using AVAssetExportSession to export a video saved in my documents directory. I wish to apply a CALayer to the video and hence am using AVMutableVideoComposition and setting necessary AVMutableVideoCompositionInstruction and video exports fine.
My issue is, say the original video is of resolution 1920x1080 now when I export this video by setting the rendersize of the video composition to 1920x640 it gives me a video of size 640x360.
I tried setting the rendersize to smaller values like 300x300 where I get the resultant exported video of size 300x300 of course by cropping extra contents. I then tried setting the rendersixe to 700x700 it resulted into a 640x640 video.
What I could understand is that it maintains the aspect ratio as per the render size we set, hence when i set the size to 1920x1080 it gives a 630x360 video maintaining the ratin of 16:9. Similarly when i set the size to be 700x700 it results in a video of size 640x640 with aspect ratio 1:1.
The Problem
I want the video size to be the same as its original size. But when I set the size of the mutablevideoComposition to the naturalSize of the original videotrack it limits me to a size below 640x640(if the size is beyond 640x640).
Is this a known behaviour? or am I missing something. If it is a known behaviour is there another way wherein I can export the video at its original size or size greater than 640x640.
Help will be deeply appreicated. Thanks in anticipation.
I figured it. It was a simple mistake. I was initializing the export session with AVAssetExportPreset640x480 instead of AVAssetExportPreset1920x1080.
When you set the preset the AVExportSession maintains the aspect ratio of your video which is bigger then the preset in your case that is how you were getting a 640x360 when your video was 1920x1080 thereby maintaining the aspect ratio.

Compress video like iOS's camera roll

Background:
I am recording a video and then uploading it.
Problem:
I compressed the video using this solution (medium quality) but it doesn't:
keep the original dimensions of the video
have as good a compression ratio as camera roll's.
I need similar compression (size and dimensions) like camera roll.
If it's not possible, do we have a workaround, say, automatically select the file from the iOS video picker (for upload)?
You can use AVAssetWriter and set custom compression settings. You can even compress the video while you're recording so you don't have to re-process the video before upload. Search around, there's tons of examples.

Exporting AVCaptureSession video in a size that matches the preview layer

I'm recording video using AVCaptureSession with the session preset AVCaptureSessionPreset640x480. I'm using an AVCaptureVideoPreviewLayer in a non-standard size (300 x 300) with the gravity set to aspect fill while recording. It's setup like this:
self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:_captureSession];
_previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
_previewLayer.frame = _previewView.bounds; // 300 x 300
[_previewView.layer addSublayer:_previewLayer];
After recording the video, I want to write it to a file in quicktime format. During playback, I'm once again playing the video in a 300 x 300 non-standard size layer. Because these videos will ultimately be transferred over a network connection, it seems wasteful to keep the full 640x480 video.
What's the best way to export a video to match my 300 x 300 preview layer? I'm an AVFoundation noob, so if I'm going about this the wrong way please let me know. I just want the recorded video displayed in the preview layer during recording to match the video that is exported on disk.
Video Resolution and Video Size are two different things. Resolution stands for clarity, higher resolution means higher clarity. Whereas, Video size is the bounds in which to display the video. Depending on the video resolution and aspect ratio of the video, the video will stretch or shrink, when seen in the viewer.
Now as the facts have been explained, You can find Your answer here:
How do I use AVFoundation to crop a video
Perform the steps in this order:
Record Video to disk.
Save from Disk to asset library.
Delete from disk.
Perform the steps mentioned in the above link.
NOTE: Perform the steps after recording and writing your video to asset library, saveComposition being the saved asset.
and provide your size in this step:videoComposition.renderSize = CGSizeMake(320, 240); as videoComposition.renderSize = CGSizeMake(300, 300);
And an advice. Since writing the file to disk, then to library, then again back to disk is kind of a lengthy operation. Try doing it all asynchronously using a dispatch_queue or operationBlock
Cheers, Have Fun.

How to crop a video in iOS

I was having a look at the RosyWriter Sample Code provided by Apple as a starting point and I'd like to find a way how to crop a video.
So i have the full resolution video from the iPhones Camera, but I just want to use a cropped part of it (and also rotate this subpart).
I figured that in captureOutput:didOutputSampleBuffer: fromConnection: i can modify each frame by modifying the CMSampleBufferRef that i get passed in.
So my questions now are:
Is this the right place to crop my video?
Where do I specify that the final video (that get's saved to disc) has a smaller resolution than the full video captured by AVCaptureSession? Setting the AVVideoWidthKey and AVVideoHeightKey has no effect.
How can I crop the video and still have good performance?
Any help is appreciated!
Thanks a lot!
EDIT:
Maybe I just need to know how I can make a video that was shot in portrait a landscape one by turning the images of the video by 90 degrees and then zoom in to fit the width again...?!?
In AVVideoSetttings.h there is the AVVideoScalingModeKey. This key combined with the defined values control how the video is scaled/cropped when encoding the images to the video container. For example if you specified a value of AVVideoScalingModeFit then cropping is used. Check out the header for how other values effect the video images.

Resources