Latest 0.0.1
License MIT
Platforms ios 7.0, requires ARC
Frameworks Foundation, AVFoundation, CoreGraphics, CoreMedia, CoreVideo, CoreImage, ImageIO, MobileCoreServices, QuartzCore, OpenGLES, UIKit

XMVideoRecorder is an iOS camera engine library allows preview the process of the pixelBuffer from camera in real time and generate video with the pixelBuffer processed. What you see is what you get.


  • [x] zoom support
  • [x] capture frame as photo
  • [x] customizable UI and user interactions
  • [x] torch support
  • [x] white balance, focus, and exposure adjustment support
  • [x] mirroring support

The sample project provides a way to deal with pixelBuffer from camera. You can use other ways except CoreImage, such as CPU-based, OpenGL, and OpenCV.



XMVideoRecorder is available and recommended for installation using the Cocoa dependency manager CocoaPods.

To integrate, just add the following line to your Podfile:

pod 'XMVideoRecorder'


Import the header.

#import "XMVideoRecorder.h"

Setup the camera preview using [[XMVideoRecorder sharedInstance] preview].

    // preview 
    preview = [[XMVideoRecorder sharedInstance] preview];
    preview.frame = self.view.bounds;
    [self.view addSubview:preview];

Setup and configure the XMVideoRecorder controller, then start the camera preview.

- (void)initXMVideoRecorder
    XMVideoRecorder *videoRecorder = [XMVideoRecorder sharedInstance];
    videoRecorder.delegate = self;
    videoRecorder.cameraDevice = XMCameraDeviceBack;
    videoRecorder.cameraOrientation = XMCameraOrientationPortrait;
    videoRecorder.outputFormat = XMOutputFormatPreset;
    videoRecorder.captureDirectory = NSTemporaryDirectory();
    videoRecorder.captureSessionPreset = AVCaptureSessionPreset640x480;
    videoRecorder.videoBitRate = XMVideoBitRate640x480;

Start/pause/resume recording.

    [[XMVideoRecorder sharedInstance] startVideoCapture];
    [[XMVideoRecorder sharedInstance] pauseVideoCapture];
    [[XMVideoRecorder sharedInstance] resumeVideoCapture];

End recording.

    [[XMVideoRecorder sharedInstance] endVideoCapture];

Handle the final video output or error accordingly.

- (void)recorder:(XMVideoRecorder *)recorder capturedVideo:(NSDictionary *)videoDict error:(NSError *)error
    NSString *videoPath = [videoDict objectForKey:XMVideoRecorderVideoPathKey];
    CGFloat videoDuration = [[videoDict objectForKey:XMVideoRecorderVideoCapturedDurationKey] floatValue];

    if (error && [error.domain isEqual:XMVideoRecorderErrorDomain] && error.code == XMVideoRecorderErrorCancelled) {
        NSLog(@"recording session cancelled");
    } else if (error) {
        NSLog(@"encounted an error in video capture (%@)", error);

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    __weak typeof(self) weakSelf = self;
    [library writeVideoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:videoPath]
                                completionBlock:^(NSURL *assetURL, NSError *error){
                                    if (error) {
                                        NSString *mssg = [NSString stringWithFormat:@"Error saving the video to the photo library. %@", error];
                                        [weakSelf showAlertViewWithMessage:mssg title:nil];
                                    else {
                                        [weakSelf showAlertViewWithMessage:@"视频保存到相册了" title:@"告诉你一声"];


XMVideoRecorder is available under the MIT license, see the License file for more information.

Latest podspec

    "name": "XMVideoRecorder",
    "version": "0.0.1",
    "summary": "iOS camera engine,real-time processing CVPixelBuffer from camera,preview and generate video.",
    "homepage": "",
    "license": "MIT",
    "authors": {
        "u5f90u94ed": "[email protected]"
    "platforms": {
        "ios": "7.0"
    "source": {
        "git": "",
        "tag": "0.0.1"
    "source_files": "Source",
    "frameworks": [
    "requires_arc": true

Pin It on Pinterest

Share This