1

AVAssetWriter用来编码图像集中的视频:

[assetWriter finishWriting];

这个方法在 iOS 6 中会产生警告。

[assetWriter finishWritingWithCompletionHandler:<#^(void)handler#>];

这就是我应该如何在 iOS 6 中应用它的方式。谁能帮我应用它

4

2 回答 2

10

You don't need to check whether it's finished. The completion handler is a block. It will be called by the system when the writing is finished. Try it.

[assetWriter finishWritingWithCompletionHandler:^(){
    NSLog (@"finished writing");
}];
于 2012-11-08T11:21:09.660 回答
1

这是作家开始代码

 NSURL *movieURL = [NSURL fileURLWithPath:myPathDocs1];
    NSError *movieError = nil;
    [assetWriter release];
    assetWriter = [[AVAssetWriter alloc] initWithURL:movieURL
                                            fileType: AVFileTypeQuickTimeMovie
                                               error: &movieError];
    NSDictionary *assetWriterInputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                              AVVideoCodecH264, AVVideoCodecKey,
                                              [NSNumber numberWithInt:FRAME_WIDTH], AVVideoWidthKey,
                                              [NSNumber numberWithInt:FRAME_HEIGHT], AVVideoHeightKey,
                                              nil];
    assetWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType: AVMediaTypeVideo
                                                          outputSettings:assetWriterInputSettings];
    assetWriterInput.expectsMediaDataInRealTime = YES;
    [assetWriter addInput:assetWriterInput];

    [assetWriterPixelBufferAdaptor release];
    assetWriterPixelBufferAdaptor = [[AVAssetWriterInputPixelBufferAdaptor  alloc]
                                     initWithAssetWriterInput:assetWriterInput
                                     sourcePixelBufferAttributes:nil];
    [assetWriter startWriting];

    firstFrameWallClockTime = CFAbsoluteTimeGetCurrent();
    [assetWriter startSessionAtSourceTime: CMTimeMake(0, TIME_SCALE)];

    // start writing samples to it
    [assetWriterTimer release];
    assetWriterTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f/60.0f
                                                        target:self
                                                      selector:@selector (writeSample:)
                                                      userInfo:nil
                                                       repeats:YES] ;

这是作家停止代码

  if (isRecording) {
        isRecording = NO;
        [_session stopRunning];
        [assetWriterTimer invalidate];
        assetWriterTimer = nil;


        [assetWriter finishWritingWithCompletionHandler:^(){
            NSLog (@"finished writing");
        }];


        [self loadOvelay];

    }
于 2012-11-10T04:22:00.397 回答