Adding code to deal with audio output
This commit is contained in:
parent
b69ffe6376
commit
9682430a69
@ -68,6 +68,7 @@
|
||||
@property (nonatomic, readonly) BOOL captureSessionLoaded;
|
||||
|
||||
@property (nonatomic, assign) int defaultFPS;
|
||||
@property (nonatomic, readonly) AVCaptureVideoPreviewLayer *captureVideoPreviewLayer;
|
||||
@property (nonatomic, assign) AVCaptureDevicePosition defaultAVCaptureDevicePosition;
|
||||
@property (nonatomic, assign) AVCaptureVideoOrientation defaultAVCaptureVideoOrientation;
|
||||
@property (nonatomic, assign) BOOL useAVCaptureVideoPreviewLayer;
|
||||
@ -110,7 +111,7 @@
|
||||
|
||||
@end
|
||||
|
||||
@interface CvVideoCamera : CvAbstractCamera<AVCaptureVideoDataOutputSampleBufferDelegate>
|
||||
@interface CvVideoCamera : CvAbstractCamera<AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureFileOutputRecordingDelegate>
|
||||
{
|
||||
AVCaptureVideoDataOutput *videoDataOutput;
|
||||
|
||||
|
@ -272,6 +272,14 @@
|
||||
} else {
|
||||
NSLog(@"[Camera] Error: could not set session preset");
|
||||
}
|
||||
|
||||
AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
|
||||
NSError *error = nil;
|
||||
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioCaptureDevice error:&error];
|
||||
if (audioInput) {
|
||||
NSLog(@"Adding audio capture devices ");
|
||||
[self.captureSession addInput:audioInput];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)createCaptureDevice;
|
||||
|
@ -41,14 +41,19 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
|
||||
|
||||
|
||||
|
||||
@interface CvVideoCamera ()
|
||||
@interface CvVideoCamera () {
|
||||
NSString* mediaPath;
|
||||
}
|
||||
|
||||
|
||||
- (void)createVideoDataOutput;
|
||||
- (void)createVideoFileOutput;
|
||||
|
||||
- (void)createMovieFileOutput;
|
||||
- (NSString*) mediaFileString;
|
||||
|
||||
@property (nonatomic, retain) CALayer *customPreviewLayer;
|
||||
@property (nonatomic, retain) AVCaptureVideoDataOutput *videoDataOutput;
|
||||
@property (nonatomic, retain) AVCaptureMovieFileOutput *movieFileOutput;
|
||||
|
||||
@end
|
||||
|
||||
@ -68,6 +73,7 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
|
||||
|
||||
@synthesize customPreviewLayer;
|
||||
@synthesize videoDataOutput;
|
||||
@synthesize movieFileOutput;
|
||||
|
||||
@synthesize recordVideo;
|
||||
@synthesize rotateVideo;
|
||||
@ -78,6 +84,7 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
|
||||
|
||||
|
||||
|
||||
|
||||
#pragma mark - Constructors
|
||||
|
||||
- (id)initWithParentView:(UIView*)parent;
|
||||
@ -105,9 +112,18 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:[self videoFileString]]) {
|
||||
[[NSFileManager defaultManager] removeItemAtPath:[self videoFileString] error:&error];
|
||||
}
|
||||
|
||||
if (error == nil) {
|
||||
NSLog(@"[Camera] Delete file %@", [self videoFileString]);
|
||||
}
|
||||
|
||||
#if 0
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:[self mediaFileString]]) {
|
||||
[[NSFileManager defaultManager] removeItemAtPath:[self mediaFileString] error:&error];
|
||||
}
|
||||
|
||||
[self.movieFileOutput startRecordingToOutputFileURL:[self mediaFileURL] recordingDelegate:self];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -333,6 +349,25 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
|
||||
}
|
||||
|
||||
|
||||
- (void)createMovieFileOutput;
|
||||
{
|
||||
self.movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
|
||||
CMTime maxDuration = CMTimeMake(30*60, 1);
|
||||
movieFileOutput.maxRecordedDuration = maxDuration;
|
||||
movieFileOutput.minFreeDiskSpaceLimit = (1024L)*(1024L*1024L);
|
||||
movieFileOutput.maxRecordedFileSize = (400L)*(1024L*1024L);
|
||||
|
||||
NSLog(@"createVideoFileOutput...");
|
||||
|
||||
if ([self.captureSession canAddOutput:movieFileOutput]) {
|
||||
[captureSession addOutput:movieFileOutput];
|
||||
NSLog(@"Successfully added movie output ");
|
||||
}
|
||||
else {
|
||||
NSLog(@"Couldn't add movie output ");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)createVideoFileOutput;
|
||||
{
|
||||
@ -378,6 +413,7 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
|
||||
[self createVideoDataOutput];
|
||||
if (self.recordVideo == YES) {
|
||||
[self createVideoFileOutput];
|
||||
//[self createMovieFileOutput];
|
||||
}
|
||||
}
|
||||
|
||||
@ -419,6 +455,24 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
|
||||
return pxbuffer;
|
||||
}
|
||||
|
||||
|
||||
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput
|
||||
didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
|
||||
fromConnections:(NSArray *)connections
|
||||
error:(NSError *)error {
|
||||
|
||||
#if 0
|
||||
BOOL recordedSuccessfully = YES;
|
||||
if ([error code] != noErr) {
|
||||
// A problem occurred: Find out if the recording was successful.
|
||||
id value = [[error userInfo] objectForKey:AVErrorRecordingSuccessfullyFinishedKey];
|
||||
if (value) {
|
||||
recordedSuccessfully = [value boolValue];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
NSLog(@"Capture File output done ");
|
||||
}
|
||||
#pragma mark - Protocol AVCaptureVideoDataOutputSampleBufferDelegate
|
||||
|
||||
|
||||
@ -601,7 +655,8 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
|
||||
|
||||
- (NSURL *)videoFileURL;
|
||||
{
|
||||
NSString *outputPath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"output.mov"];
|
||||
//NSString *outputPath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"output.mov"];
|
||||
NSString *outputPath = self.videoFileString;
|
||||
NSURL *outputURL = [NSURL fileURLWithPath:outputPath];
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
if ([fileManager fileExistsAtPath:outputPath]) {
|
||||
@ -611,6 +666,16 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
|
||||
}
|
||||
|
||||
|
||||
- (NSURL *)mediaFileURL;
|
||||
{
|
||||
NSString *outputPath = self.mediaFileString;
|
||||
NSURL *outputURL = [NSURL fileURLWithPath:outputPath];
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
if ([fileManager fileExistsAtPath:outputPath]) {
|
||||
NSLog(@"file exists");
|
||||
}
|
||||
return outputURL;
|
||||
}
|
||||
|
||||
- (NSString *)videoFileString;
|
||||
{
|
||||
@ -618,4 +683,9 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
|
||||
return outputPath;
|
||||
}
|
||||
|
||||
|
||||
- (NSString*) mediaFileString {
|
||||
NSString *outputPath = [[NSString alloc] initWithFormat:@"%@-%@", NSTemporaryDirectory(), @"media.mov"];
|
||||
return outputPath;
|
||||
}
|
||||
@end
|
||||
|
Loading…
Reference in New Issue
Block a user