不推荐使用finishWriting:首先在iOS 6.0中弃用

时间:2012-11-08 10:40:47

标签: ios iphone ios6 avassetwriter

我使用AVAssetWriter对图像集中的视频进行编码:

[assetWriter finishWriting];

此方法在iOS 6中生成警告。

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

这就是我应该如何在iOS 6中应用它的方式。任何人都可以帮我应用它

2 个答案:

答案 0 :(得分:10)

您无需检查是否已完成。完成处理程序是一个块。写入完成后,系统将调用它。试试吧。

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

答案 1 :(得分: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];

    }
相关问题