【发布时间】:2013-08-21 16:12:25
【问题描述】:
我有一个相当冗长的定格动画应用方法,它在按下的各种选项、计时器、自拍等方面略有不同
可以定义方法的主体:
// initiate a still image capture, return immediately
// the completionHandler is called when a sample buffer has been captured
AVCaptureConnection *stillImageConnection = [stillImageOutput connectionWithMediaType:AVMediaTypeVideo];
[stillImageOutput captureStillImageAsynchronouslyFromConnection:stillImageConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *__strong error) {
// set up the AVAssetWriter using the format description from the first sample buffer captured
if ( !assetWriter ) {
outputURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%llu.mov", NSTemporaryDirectory(), mach_absolute_time()]];
//NSLog(@"Writing movie to \"%@\"", outputURL);
CMFormatDescriptionRef formatDescription = CMSampleBufferGetFormatDescription(imageDataSampleBuffer);
if ( NO == [self setupAssetWriterForURL:outputURL formatDescription:formatDescription] )
return;
}
// re-time the sample buffer - in this sample frameDuration is set to 5 fps
CMSampleTimingInfo timingInfo = kCMTimingInfoInvalid;
timingInfo.duration = frameDuration;
timingInfo.presentationTimeStamp = nextPTS;
CMSampleBufferRef sbufWithNewTiming = NULL;
OSStatus err = CMSampleBufferCreateCopyWithNewTiming(kCFAllocatorDefault,
imageDataSampleBuffer,
1, // numSampleTimingEntries
&timingInfo,
&sbufWithNewTiming);
if (err)
return;
// append the sample buffer if we can and increment presnetation time
if ( [assetWriterInput isReadyForMoreMediaData] ) {
if ([assetWriterInput appendSampleBuffer:sbufWithNewTiming]) {
nextPTS = CMTimeAdd(frameDuration, nextPTS);
}
else {
NSError *error = [assetWriter error];
NSLog(@"failed to append sbuf: %@", error);
}
}
// release the copy of the sample buffer we made
CFRelease(sbufWithNewTiming);
}];
只需使用计时器等对方法进行更改
首先我尝试制作一个单例,但虽然我得到了名为的方法,但我在保存和写入文件时遇到了其他问题。我可以用方法制作宏吗?
我在这里研究了 SO iOS create macro
我在正确的轨道上吗?我可以定义一个方法而不是那个例子中的图像吗
【问题讨论】:
-
您可能想要创建一个包含此方法的实用程序类,您可以创建该类的一个实例以进行实际处理。如果您不想实例化一个类,您可以使用类方法创建一个类(例如
+ (void)doSomeThing)并直接使用它们。
标签: ios objective-c cocoa-touch