Export AVCaptureSession video at a size that matches the preview level

I am recording video AVCaptureSessionwith pre-setting session AVCaptureSessionPreset640x480. I use AVCaptureVideoPreviewLayera non-standard size (300 x 300) with a gravity factor set to fill the aspect during recording. It is configured as follows:

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 play videos again in a non-standard size of 300 x 300. Since these videos will eventually be transferred over a network connection, it seems wasteful to store the full 640x480 video.

What is the best way to export video according to the 300 x 300 preview layer? I am an AVFoundation noob, so if I am going to do it wrong, please let me know. I just want the recorded video displayed at the preview level during recording to match the video that is exported to disk.

+5
source share
1 answer

Video resolution and video size are two different things. Resolution means clarity; higher resolution means higher definition. Whereas the size of the video is the boundaries for displaying the video. Depending on the video resolution and image format, the video will stretch or shrink when viewed in the viewer.

, , :

AVFoundation

:

  • .
  • .
  • .
  • , .

. , saveComposition - .

: videoComposition.renderSize = CGSizeMake(320, 240); videoComposition.renderSize = CGSizeMake(300, 300);

. , , . , dispatch_queue operationBlock

, .

+10

All Articles