diff --git a/src/plugins/avfoundation/camera/avfcameraservice.mm b/src/plugins/avfoundation/camera/avfcameraservice.mm
index 966202e..ab67b58 100644
--- a/src/plugins/avfoundation/camera/avfcameraservice.mm
+++ b/src/plugins/avfoundation/camera/avfcameraservice.mm
@@ -124,6 +124,7 @@ QMediaControl *AVFCameraService::requestControl(const char *name)
             m_videoOutput = new AVFVideoRendererControl(this);
 
         if (m_videoOutput) {
+            m_videoOutput->setRecordingDelegate(m_recorderControl);
             m_session->setVideoOutput(m_videoOutput);
             return m_videoOutput;
         }
diff --git a/src/plugins/avfoundation/camera/avfmediarecordercontrol.h b/src/plugins/avfoundation/camera/avfmediarecordercontrol.h
old mode 100644
new mode 100755
index a4c7b7f..6468cce
--- a/src/plugins/avfoundation/camera/avfmediarecordercontrol.h
+++ b/src/plugins/avfoundation/camera/avfmediarecordercontrol.h
@@ -35,13 +35,12 @@
 #define AVFMEDIARECORDERCONTROL_H
 
 #include <QtCore/qurl.h>
+#include <QtCore/qdatetime.h>
 #include <QtMultimedia/qmediarecordercontrol.h>
 
 #import <AVFoundation/AVFoundation.h>
 #include "avfstoragelocation.h"
 
-@class AVFMediaRecorderDelegate;
-
 QT_BEGIN_NAMESPACE
 
 class AVFCameraSession;
@@ -68,6 +67,8 @@ public:
 
     void applySettings();
 
+    void writeFrame(CMSampleBufferRef frame);
+
 public Q_SLOTS:
     void setState(QMediaRecorder::State state);
     void setMuted(bool muted);
@@ -78,12 +79,17 @@ public Q_SLOTS:
     void handleRecordingFailed(const QString &message);
 
 private Q_SLOTS:
-    void reconnectMovieOutput();
     void updateStatus();
 
 private:
+    QTime durationTimer;
+    bool recording;
+    bool initialized;
     AVFCameraControl *m_cameraControl;
     AVFCameraSession *m_session;
+    AVAssetWriterInput *assetWriterInput;
+    AVAssetWriterInputPixelBufferAdaptor *pixelBufferAdaptor;
+    AVAssetWriter *assetWriter;
 
     bool m_connected;
     QUrl m_outputLocation;
@@ -96,8 +102,6 @@ private:
     bool m_muted;
     qreal m_volume;
 
-    AVCaptureMovieFileOutput *m_movieOutput;
-    AVFMediaRecorderDelegate *m_recorderDelagate;
     AVFStorageLocation m_storageLocation;
 };
 
diff --git a/src/plugins/avfoundation/camera/avfmediarecordercontrol.mm b/src/plugins/avfoundation/camera/avfmediarecordercontrol.mm
old mode 100644
new mode 100755
index d65d238..e11c6ee
--- a/src/plugins/avfoundation/camera/avfmediarecordercontrol.mm
+++ b/src/plugins/avfoundation/camera/avfmediarecordercontrol.mm
@@ -45,6 +45,10 @@
 #include "avfcameraservice.h"
 #include "avfcameracontrol.h"
 
+#include <UIKit/UIKit.h>
+#include <Accelerate/accelerate.h>
+
+#include <QtCore/QDebug>
 #include <QtCore/qurl.h>
 #include <QtCore/qfileinfo.h>
 #include <QtMultimedia/qcameracontrol.h>
@@ -52,78 +56,13 @@
 
 QT_USE_NAMESPACE
 
-@interface AVFMediaRecorderDelegate : NSObject <AVCaptureFileOutputRecordingDelegate>
-{
-@private
-    AVFMediaRecorderControl *m_recorder;
-}
-
-- (AVFMediaRecorderDelegate *) initWithRecorder:(AVFMediaRecorderControl*)recorder;
-
-- (void) captureOutput:(AVCaptureFileOutput *)captureOutput
-         didStartRecordingToOutputFileAtURL:(NSURL *)fileURL
-         fromConnections:(NSArray *)connections;
-
-- (void) captureOutput:(AVCaptureFileOutput *)captureOutput
-         didFinishRecordingToOutputFileAtURL:(NSURL *)fileURL
-         fromConnections:(NSArray *)connections
-         error:(NSError *)error;
-@end
-
-@implementation AVFMediaRecorderDelegate
-
-- (AVFMediaRecorderDelegate *) initWithRecorder:(AVFMediaRecorderControl*)recorder
-{
-    if (!(self = [super init]))
-        return nil;
-
-    self->m_recorder = recorder;
-    return self;
-}
-
-- (void) captureOutput:(AVCaptureFileOutput *)captureOutput
-         didStartRecordingToOutputFileAtURL:(NSURL *)fileURL
-         fromConnections:(NSArray *)connections
-{
-    Q_UNUSED(captureOutput);
-    Q_UNUSED(fileURL);
-    Q_UNUSED(connections)
-
-    QMetaObject::invokeMethod(m_recorder, "handleRecordingStarted", Qt::QueuedConnection);
-}
-
-- (void) captureOutput:(AVCaptureFileOutput *)captureOutput
-         didFinishRecordingToOutputFileAtURL:(NSURL *)fileURL
-         fromConnections:(NSArray *)connections
-         error:(NSError *)error
-{
-    Q_UNUSED(captureOutput);
-    Q_UNUSED(fileURL);
-    Q_UNUSED(connections)
-
-    if (error) {
-        QStringList messageParts;
-        messageParts << QString::fromUtf8([[error localizedDescription] UTF8String]);
-        messageParts << QString::fromUtf8([[error localizedFailureReason] UTF8String]);
-        messageParts << QString::fromUtf8([[error localizedRecoverySuggestion] UTF8String]);
-
-        QString errorMessage = messageParts.join(" ");
-
-        QMetaObject::invokeMethod(m_recorder, "handleRecordingFailed", Qt::QueuedConnection,
-                                  Q_ARG(QString, errorMessage));
-    } else {
-        QMetaObject::invokeMethod(m_recorder, "handleRecordingFinished", Qt::QueuedConnection);
-    }
-}
-
-@end
-
-
 AVFMediaRecorderControl::AVFMediaRecorderControl(AVFCameraService *service, QObject *parent)
    : QMediaRecorderControl(parent)
+   , recording(false)
+   , initialized(false)
    , m_cameraControl(service->cameraControl())
    , m_session(service->session())
-   , m_connected(false)
+   , m_connected(true)
    , m_state(QMediaRecorder::StoppedState)
    , m_lastStatus(QMediaRecorder::UnloadedStatus)
    , m_recordingStarted(false)
@@ -131,22 +70,14 @@ AVFMediaRecorderControl::AVFMediaRecorderControl(AVFCameraService *service, QObj
    , m_muted(false)
    , m_volume(1.0)
 {
-    m_movieOutput = [[AVCaptureMovieFileOutput alloc] init];
-    m_recorderDelagate = [[AVFMediaRecorderDelegate alloc] initWithRecorder:this];
 
     connect(m_cameraControl, SIGNAL(stateChanged(QCamera::State)), SLOT(updateStatus()));
     connect(m_cameraControl, SIGNAL(statusChanged(QCamera::Status)), SLOT(updateStatus()));
-    connect(m_cameraControl, SIGNAL(captureModeChanged(QCamera::CaptureModes)), SLOT(reconnectMovieOutput()));
-
-    reconnectMovieOutput();
 }
 
 AVFMediaRecorderControl::~AVFMediaRecorderControl()
 {
-    if (m_movieOutput)
-        [m_session->captureSession() removeOutput:m_movieOutput];
 
-    [m_recorderDelagate release];
 }
 
 QUrl AVFMediaRecorderControl::outputLocation() const
@@ -204,10 +135,7 @@ void AVFMediaRecorderControl::updateStatus()
 
 qint64 AVFMediaRecorderControl::duration() const
 {
-    if (!m_movieOutput)
-        return 0;
-
-    return qint64(CMTimeGetSeconds(m_movieOutput.recordedDuration) * 1000);
+    return qint64(recording ? durationTimer.elapsed() : 0);
 }
 
 bool AVFMediaRecorderControl::isMuted() const
@@ -250,8 +178,16 @@ void AVFMediaRecorderControl::setState(QMediaRecorder::State state)
 
             qDebugCamera() << "Video capture location:" << actualLocation.toString();
 
-            [m_movieOutput startRecordingToOutputFileURL:actualLocation.toNSURL()
-                           recordingDelegate:m_recorderDelagate];
+            NSError *error = nil;
+            assetWriter = [[AVAssetWriter alloc]
+                                            initWithURL:actualLocation.toNSURL()
+                                            fileType:AVFileTypeMPEG4
+                                            error:&error];
+
+            initialized = false;
+            durationTimer.start();
+            recording = true;
+            durationChanged(0);
 
             Q_EMIT actualLocationChanged(actualLocation);
         } else {
@@ -266,8 +202,16 @@ void AVFMediaRecorderControl::setState(QMediaRecorder::State state)
     } break;
     case QMediaRecorder::StoppedState:
     {
+        recording = false;
+        initialized = false;
+        [assetWriterInput markAsFinished];
+        [assetWriter finishWritingWithCompletionHandler:^{
+            [assetWriterInput release];
+            [assetWriter release];
+        }];
+
         m_state = QMediaRecorder::StoppedState;
-        [m_movieOutput stopRecording];
+        durationTimer = QTime();
     }
     }
 
@@ -315,26 +259,141 @@ void AVFMediaRecorderControl::handleRecordingFailed(const QString &message)
     Q_EMIT error(QMediaRecorder::ResourceError, message);
 }
 
-void AVFMediaRecorderControl::reconnectMovieOutput()
+void AVFMediaRecorderControl::writeFrame(CMSampleBufferRef frame)
 {
-    //adding movie output causes high CPU usage even when while recording is not active,
-    //connect it only while video capture mode is enabled
-    AVCaptureSession *captureSession = m_session->captureSession();
-
-    if (!m_connected && m_cameraControl->captureMode().testFlag(QCamera::CaptureVideo)) {
-        if ([captureSession canAddOutput:m_movieOutput]) {
-            [captureSession addOutput:m_movieOutput];
-            m_connected = true;
-        } else {
-            Q_EMIT error(QMediaRecorder::ResourceError, tr("Could not connect the video recorder"));
-            qWarning() << "Could not connect the video recorder";
+    if (recording && frame)
+    {
+        CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(frame);
+
+        bool front = [m_session->videoCaptureDevice() position] == AVCaptureDevicePositionFront;
+
+        uint8_t rotation = 0;
+        switch ([UIApplication sharedApplication].keyWindow.rootViewController.interfaceOrientation) {
+        case UIInterfaceOrientationPortrait:
+            if (front)
+            {
+                rotation = 1;
+            }
+            else
+            {
+                rotation = 3;
+            }
+            break;
+        case UIInterfaceOrientationPortraitUpsideDown:
+            if (front)
+            {
+                rotation = 3;
+            }
+            else
+            {
+                rotation = 1;
+            }
+            break;
+        case UIInterfaceOrientationLandscapeRight:
+            if (front)
+            {
+                rotation = 2;
+            }
+            break;
+        case UIInterfaceOrientationLandscapeLeft:
+            if (!front)
+            {
+                rotation = 2;
+            }
+            break;
+        default:
+
+            break;
         }
-    } else if (m_connected && !m_cameraControl->captureMode().testFlag(QCamera::CaptureVideo)) {
-        [captureSession removeOutput:m_movieOutput];
-        m_connected = false;
-    }
 
-    updateStatus();
+        if (!initialized)
+        {
+            int width = CVPixelBufferGetWidth(imageBuffer);
+            int height = CVPixelBufferGetHeight(imageBuffer);
+            if (rotation % 2 == 1)
+            {
+                qSwap(width, height);
+            }
+
+            qDebug() << "DIMENSIONS: " << width << height;
+
+            NSDictionary *outputSettings =
+                [NSDictionary dictionaryWithObjectsAndKeys:
+
+                        [NSNumber numberWithInt:width], AVVideoWidthKey,
+                        [NSNumber numberWithInt:height], AVVideoHeightKey,
+                        AVVideoCodecH264, AVVideoCodecKey,
+
+                        nil];
+
+            assetWriterInput = [AVAssetWriterInput
+                                               assetWriterInputWithMediaType:AVMediaTypeVideo
+                                                              outputSettings:outputSettings];
+
+            /* I'm going to push pixel buffers to it, so will need a
+               AVAssetWriterPixelBufferAdaptor, to expect the same 32BGRA input as I've
+               asked the AVCaptureVideDataOutput to supply */
+            pixelBufferAdaptor =
+                       [[AVAssetWriterInputPixelBufferAdaptor alloc]
+                            initWithAssetWriterInput:assetWriterInput
+                            sourcePixelBufferAttributes:
+                                 [NSDictionary dictionaryWithObjectsAndKeys:
+                                      [NSNumber numberWithInt:kCVPixelFormatType_32BGRA],
+                                       kCVPixelBufferPixelFormatTypeKey,
+                                 nil]];
+
+            [assetWriter addInput:assetWriterInput];
+
+            /* we need to warn the input to expect real time data incoming, so that it tries
+               to avoid being unavailable at inopportune moments */
+            assetWriterInput.expectsMediaDataInRealTime = YES;
+
+            [assetWriter startWriting];
+            [assetWriter startSessionAtSourceTime:kCMTimeZero];
+            initialized = true;
+        }
+
+        if (rotation > 0)
+        {
+
+            CVPixelBufferLockBaseAddress(imageBuffer, 0);
+            size_t width = CVPixelBufferGetWidth(imageBuffer);
+            size_t height = CVPixelBufferGetHeight(imageBuffer);
+            size_t newWidth = rotation % 2 == 0 ? width : height;
+            size_t newHeight = rotation % 2 == 0 ? height : width;
+
+            size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
+            size_t currSize = bytesPerRow*height*sizeof(unsigned char);
+
+            size_t bytesPerRowOut = 4*newWidth*sizeof(unsigned char);
+
+
+            void *srcBuff = CVPixelBufferGetBaseAddress(imageBuffer);
+
+
+            unsigned char *outBuff = (unsigned char*)malloc(currSize);
+
+            vImage_Buffer ibuff = { srcBuff, height, width, bytesPerRow};
+            vImage_Buffer ubuff = { outBuff, newHeight, newWidth, bytesPerRowOut};
+
+            Pixel_8888 temp = {0, 0, 0, 0};
+            vImage_Error err= vImageRotate90_ARGB8888 (&ibuff, &ubuff, rotation, temp, 0);
+            if (err != kvImageNoError) NSLog(@"%ld", err);
+
+            CVPixelBufferRef buffer = NULL;
+            int res = CVPixelBufferCreateWithBytes(NULL, newWidth, newHeight, kCVPixelFormatType_32BGRA, outBuff, bytesPerRowOut, NULL, 0, NULL, &buffer);
+            if(assetWriterInput.readyForMoreMediaData)
+                [pixelBufferAdaptor appendPixelBuffer:buffer
+                                withPresentationTime:CMTimeMake(durationTimer.elapsed(), 1000)];
+            free(outBuff);
+        }
+        else
+        {
+            if(assetWriterInput.readyForMoreMediaData)
+                [pixelBufferAdaptor appendPixelBuffer:imageBuffer
+                                 withPresentationTime:CMTimeMake(durationTimer.elapsed(), 1000)];
+        }
+    }
 }
 
 #include "moc_avfmediarecordercontrol.cpp"
diff --git a/src/plugins/avfoundation/camera/avfvideorenderercontrol.h b/src/plugins/avfoundation/camera/avfvideorenderercontrol.h
index 0f4f6ba..c4bfecb 100644
--- a/src/plugins/avfoundation/camera/avfvideorenderercontrol.h
+++ b/src/plugins/avfoundation/camera/avfvideorenderercontrol.h
@@ -35,6 +35,7 @@
 #define AVFVIDEORENDERERCONTROL_H
 
 #include <QtMultimedia/qvideorenderercontrol.h>
+#include "avfmediarecordercontrol.h"
 #include <QtMultimedia/qvideoframe.h>
 #include <QtCore/qmutex.h>
 
@@ -57,6 +58,7 @@ public:
 
     QAbstractVideoSurface *surface() const;
     void setSurface(QAbstractVideoSurface *surface);
+    void setRecordingDelegate(AVFMediaRecorderControl* recordingDelegate);
 
     void configureAVCaptureSession(AVFCameraSession *cameraSession);
     void syncHandleViewfinderFrame(const QVideoFrame &frame);
diff --git a/src/plugins/avfoundation/camera/avfvideorenderercontrol.mm b/src/plugins/avfoundation/camera/avfvideorenderercontrol.mm
old mode 100644
new mode 100755
index 1a20544..b4904f1
--- a/src/plugins/avfoundation/camera/avfvideorenderercontrol.mm
+++ b/src/plugins/avfoundation/camera/avfvideorenderercontrol.mm
@@ -104,10 +104,13 @@ private:
 {
 @private
     AVFVideoRendererControl *m_renderer;
+    AVFMediaRecorderControl *m_recorder;
 }
 
 - (AVFCaptureFramesDelegate *) initWithRenderer:(AVFVideoRendererControl*)renderer;
 
+- (void) setRecordingDelegate:(AVFMediaRecorderControl*)recordingDelegate;
+
 - (void) captureOutput:(AVCaptureOutput *)captureOutput
          didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
          fromConnection:(AVCaptureConnection *)connection;
@@ -124,6 +127,11 @@ private:
     return self;
 }
 
+- (void) setRecordingDelegate:(AVFMediaRecorderControl*)recordingDelegate
+{
+    self->m_recorder = recordingDelegate;
+}
+
 - (void)captureOutput:(AVCaptureOutput *)captureOutput
          didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
          fromConnection:(AVCaptureConnection *)connection
@@ -139,6 +147,11 @@ private:
     QAbstractVideoBuffer *buffer = new CVPixelBufferVideoBuffer(imageBuffer);
     QVideoFrame frame(buffer, QSize(width, height), QVideoFrame::Format_RGB32);
     m_renderer->syncHandleViewfinderFrame(frame);
+
+    if (m_recorder)
+    {
+        m_recorder->writeFrame(sampleBuffer);
+    }
 }
 @end
 
@@ -170,6 +183,11 @@ void AVFVideoRendererControl::setSurface(QAbstractVideoSurface *surface)
     }
 }
 
+void AVFVideoRendererControl::setRecordingDelegate(AVFMediaRecorderControl* recordingDelegate)
+{
+    [m_viewfinderFramesDelegate setRecordingDelegate:recordingDelegate];
+}
+
 void AVFVideoRendererControl::configureAVCaptureSession(AVFCameraSession *cameraSession)
 {
     m_cameraSession = cameraSession;
