0

I am recording video using avfoundation and I set captureSession with AVCaptureSessionPreset640x480. But after recording, when I see my video its dimensions are changed to 480x640.

Edit: Problem withe recording using portrait mode is that you will always get the 480X640. because of the orientation of the device, therefore need to rotate the video according to the orientation size.

I have solved this issue however it was not off-topic at all.

- (CGAffineTransform)transformFromCurrentVideoOrientationToOrientation:(AVCaptureVideoOrientation)orientation
{


    CGAffineTransform transform = CGAffineTransformIdentity;

    // Calculate offsets from an arbitrary reference orientation (portrait)
    CGFloat orientationAngleOffset = [self angleOffsetFromPortraitOrientationToOrientation:orientation];
    CGFloat videoOrientationAngleOffset = [self angleOffsetFromPortraitOrientationToOrientation:self.videoOrientation];

    // Find the difference in angle between the passed in orientation and the current video orientation
    CGFloat angleOffset = orientationAngleOffset - videoOrientationAngleOffset;
    transform = CGAffineTransformMakeRotation(angleOffset);

    return transform;
}
nsgulliver
  • 12,655
  • 23
  • 43
  • 64

2 Answers2

1

Were you holding the phone vertically (portrait orientatin)?

Video is captured in the device orientation detected using the accelerometer. You can force it to use landscape orientation.

Community
  • 1
  • 1
onon15
  • 3,620
  • 1
  • 18
  • 22
  • Yes it is portrait, and if I want to record in the portrait mode? – nsgulliver Nov 21 '12 at 14:32
  • If you want to crop a 3:4 frame out of the 4:3 frame being captured, AFAIK you need to do it in post-processing the result video. (And resolution will be low, as your width is 480, your maximum resolution can be 320x480) – onon15 Nov 21 '12 at 14:37
  • 1
    is there anyway that I can record in portrait mode but don't get 480*640? I tried to set presets of AvCapture but they don't seem to work for me, I mean if I do recording using Landscape mode then it is giving right aspect ratio but only that it is 90 rotated, is there anyway to rotate the video 90 degree before saving? – nsgulliver Nov 21 '12 at 14:38
  • what is the way to do post -processing? so it will be only capturing the frames from video as thumbnails? and then capture audio someway and after resizing and finally joining thumbnails and audio to make required size video? or is there any better way to do it? – nsgulliver Nov 21 '12 at 14:40
  • There are better ways. I am not well enough acquainted with video processing libraries that do that on the iOS but consider posting a separate question for that on SO. Offline, there are too many tools for that... – onon15 Nov 21 '12 at 14:47
1

Problem withe recording using portrait mode is that you will always get the 480X640. because of the orientation of the device, therefore need to rotate the video according to the orientation size.

I have solved this issue however it was not off-topic at all.

- (CGAffineTransform)transformFromCurrentVideoOrientationToOrientation:(AVCaptureVideoOrientation)orientation
{
    CGAffineTransform transform = CGAffineTransformIdentity;

    // Calculate offsets from an arbitrary reference orientation (portrait)
    CGFloat orientationAngleOffset = [self angleOffsetFromPortraitOrientationToOrientation:orientation];
    CGFloat videoOrientationAngleOffset = [self angleOffsetFromPortraitOrientationToOrientation:self.videoOrientation];

    // Find the difference in angle between the passed in orientation and the current video orientation
    CGFloat angleOffset = orientationAngleOffset - videoOrientationAngleOffset;
    transform = CGAffineTransformMakeRotation(angleOffset);

    return transform;
}
nsgulliver
  • 12,655
  • 23
  • 43
  • 64