标签: avfoundationit | 分类: iphone开发 |
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in imageOutput_.connections)
{
for (AVCaptureInputPort *port in [connectioninputPorts])
{
if ([[port mediaType] isEqual:AVMediaTypeVideo] )
{
videoConnection = connection;
break;
}
}
if (videoConnection) { break; }
}
//锁定connection后就可以获取静态图了。
[imageOutput_ captureStillImageAsynchr
NSDictionary *exifAttachments = (__bridgeNSDictionary*)CMGetAttachment(imageSampleBuffer, kCGImagePropertyExifDict
}];
最后,如果想抓取视频的话,请参考苹果的文档:
Starting a Recording
You start recording a QuickTime movie using startRecordingToOutputFi
. You need to supply a file-based URL and a delegate. The URL must not identify an existing file, as the movie file output does not overwrite existing resources. You must also have permission to write to the specified location. The delegate must conform to the AVCaptureFileOutputRecor
captureOutput:didFinishRecordingToOutp
AVCaptureMovieFileOutput |
NSURL *fileURL = <#A file URL that identifies the output location#>; |
[aMovieFileOutput startRecordingToOutputFi |
In the implementation of captureOutput:didFinishRecordingToOutp
, the delegate might write the resulting movie to the camera roll. It should also check for any errors that might have occurred.
Ensuring the File Was Written Successfully
To determine whether the file was saved successfully, in the implementation of captureOutput:didFinishRecordingToOutp
AVErrorRecordingSuccessf
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput |
didFinishRecordingToOutp |
fromConnections:(NSArray *)connections |
error:(NSError *)error { |
|
BOOL recordedSuccessfully = YES; |
if ([error code] != noErr) { |
// A problem occurred: Find out if the recording was successful. |
id value = [[error userInfo] objectForKey:AVErrorRecordingSuccessf |
if (value) { |
recordedSuccessfully = [value boolValue]; |
} |
} |
// Continue as appropriate... |
You should check the value of the AVErrorRecordingSuccessf
AVErrorMaximumDurationRe
AVErrorMaximumFileSizeRe
. Other reasons the recording might stop are:
-
The disk is full—
AVErrorDiskFull
. -
The recording device was disconnected (for example, the microphone was removed from an iPod touch)—
AVErrorDeviceWasDisconne
.cted -
The session was interrupted (for example, a phone call was received)—
AVErrorSessionWasInterru
.pted