First, I know many people asked similar question - but I couldn't find any question that is similar.
When calling this interface:
- (void) captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
    CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
    CVPixelBufferLockBaseAddress(pixelBuffer, 0);
    // get buffer dimensions
    size_t bufferHeight = CVPixelBufferGetHeight(pixelBuffer);
    size_t bufferWidth  = CVPixelBufferGetWidth(pixelBuffer);
...
When the phone is in "portrait mode" - I get height of 480, and width of 640.
The weird thing - is that when I check [connection videoOrientation] it is set correctly to portrait.
- Why does the connection orientation does not affect the sampled buffer?
 - Should I rotate the image myself?
 - Is there a way to configure the sample to be given by the device orientation?
 
Thanks
@Gabriel : I already have this code:
-(void) viewWillLayoutSubviews
{
    // Handle camera
    if (_videoPreviewLayer)
    {
        _videoPreviewLayer.frame = self.view.bounds;
        for (AVCaptureOutput* outcap in _captureSession.outputs)
        {
            for(AVCaptureConnection* con in outcap.connections)
            {
                switch ([[UIDevice currentDevice] orientation])
                {
                    case UIInterfaceOrientationPortrait:
                        [con setVideoOrientation:AVCaptureVideoOrientationPortrait];
                        break;
                    case UIInterfaceOrientationLandscapeRight:
                        [con setVideoOrientation:AVCaptureVideoOrientationLandscapeRight]; //home button on right. Refer to .h not doc
                        break;
                    case UIInterfaceOrientationLandscapeLeft:
                        [con setVideoOrientation:AVCaptureVideoOrientationLandscapeLeft]; //home button on left. Refer to .h not doc
                        break;
                    case UIInterfaceOrientationPortraitUpsideDown:
                        [con setVideoOrientation:AVCaptureVideoOrientationPortraitUpsideDown]; //home button on left. Refer to .h not doc
                        break;
                    default:
                        [con setVideoOrientation:AVCaptureVideoOrientationPortrait]; //for portrait upside down. Refer to .h not doc
                        break;
                }
            }
        }
    }
}
and as I mentioned above, when checking the connection - it is the right orientation, the image although is the wrong orientation..
Did you refer by fixing it manually - using what method would I use for it, to automatically change to the right orientation?
The thing is that the display is good, it's only the taking of the picture...