Git Product home page Git Product logo

scaudiovideorecorder's Introduction

SCAudioVideoRecorder

A Vine like audio/video recorder in Objective-C.

These classes allow the recording of a video with pause/resume function. Although the project was initially made for the sake of taking videos only, you can now take pictures as well with some very useful utility functions that make the project totally suitable for a standalone camera engine. They are straightforward to use, only a few lines of code is needed to start recording.

They are compatible both for OS X and iOS. Examples for both OS X and IOS are provided.

Framework needed:

  • AssetsLibrary

Straightforward recording using SCCamera

Initialising the camera:

// Create the camera
SCCamera * camera = [SCCamera camera];

// Set the target UIView (or NSView for OS X) which will receive the video preview
camera.previewView = self.cameraView;

// Start the session and the flow of inputs
[camera initialize:^(NSError *audioError, NSError *videoError) {

}];

Interacting with the camera:

// Prepare the camera to record on the camera roll
NSError * error;
[camera prepareRecordingAtCameraRoll:&error];

// Prepare the camera to record on a temp file
// The returned url is the generated temp file
NSURL * outputUrl = [camera prepareRecordingOnTempDir:&error];

// Prepare the camera to record on the specified url
[camera prepareRecordingAtUrl:[NSURL URLWithString:@"file://output.mp4"] error:&error];

// Ask the camera to record (the camera must be prepared before)
[camera record];

// Ask the camera to pause
[camera pause];

// Ask the camera to finish the recording. After calling this,
// the camera wont be able to record on the file again and it will
// loose its "prepared" state. Therefore "prepareRecording" must be called
// before trying to record again.
[camera stop];

// Handle the recorded file
camera.delegate = self;
- (void) audioVideoRecorder:(SCAudioVideoRecorder *)audioVideoRecorder didFinishRecordingAtUrl:(NSURL *)recordedFile error:(NSError *)error {
	if (error == nil) {
		NSLog(@"Succesfully recorded file at %@", recordedFile);
	} else {
		NSLog(@"Failed to record file: %@", error);
	}
}

Taking pictures with the SCCamera

Not only the SCCamera can take videos, but it can be used for taking pictures as well.

// Taking a picture
[camera capturePhoto];

// Handle the captured photo
// The photoDict contains the multiple attributes of the captured photo as seen below
- (void)audioVideoRecorder:(SCAudioVideoRecorder *)audioVideoRecorder capturedPhoto:(NSDictionary *)photoDict error:(NSError *)error {
	NSDictionary * metadata = [photoDict objectForKey:SCAudioVideoRecorderPhotoMetadataKey];
	NSData * jpegData = [photoDict objectForKey:SCAudioVideoRecorderPhotoJPEGKey];
	UIImage * image = [photoDict objectForKey:SCAudioVideoRecorderPhotoImageKey];
	UIImage * thumbnail = [photoDict objectForKey:SCAudioVideoRecorderPhotoThumbnailKey];
)

// Focus
[camera autoFocusAtPoint:CGPointMake(40, 40)];
[camera continuousFocusAtPoint:CGPointMake(40, 40)];

// Handling focus change (useful for showing an animation for instance)
- (void)cameraWillStartFocus:(SCCamera *)camera {
	
}

- (void)cameraDidStopFocus:(SCCamera *)camera {

}

Configuring SCCamera

// Changing from back to front camera
camera.cameraDevice = SCCameraDeviceBack;
camera.cameraDevice = SCCameraDeviceFront;

// Just switch between front and back device
[camera switchCamera];

// Setting the flash mode
camera.flashMode = SCFlashModeOff; // Totally disable the flash
camera.flashMode = SCFlashModeOn; // Will flash when taking a picture
camera.flashMode = SCFlashModeAuto; // The device will figure out if the flash is needed or not when taking a picture
camera.flashMode = SCFlashModeLight; // The flash will be always on

Manually handling AVCaptureSession with SCAudioVideoRecorder

The SCCamera seen just before inherits from SCAudioVideoRecorder. The whole "interacting with the camera" part is thus valable for the SCAudioVideoRecorder as well. The SCCamera just adds an automatic handling of the AVCaptureSession. If you want to manually handle the CaptureSession yourself, here is how you can do:

AVCaptureSession * session = [[AVCaptureSession alloc] init];
SCAudioVideoRecorder * avr = [[SCAudioVideoRecorder alloc] init];

// Adding the support for the audio
[session addOutput:avr.audioOutput];

// Adding the support for the video
[session addOutput:avr.videoOutput];

scaudiovideorecorder's People

Contributors

rflex avatar xhzengaib avatar lilejia avatar

Watchers

Fred Chen avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.