4

現在、画面をキャプチャしてビデオに変換するプログラムを作成しています。10 秒未満であれば、ビデオを正常に保存できます。しかし、それ以上の場合、メモリの警告とアプリケーションのクラッシュが発生しました。このコードを次のように書きました。データをリリースするにはどこに行方不明ですか? やり方を知りたいです。

-(void)captureAndSaveImage
{

if(!stopCapturing){

if (assetWriterInput.readyForMoreMediaData)
{
    keepTrackOfBackGroundMood++;
    NSLog(@"keepTrackOfBackGroundMood is %d",keepTrackOfBackGroundMood);

    CVReturn cvErr = kCVReturnSuccess;

    CGSize imageSize = screenCaptureAndDraw.bounds.size;


    CGFloat imageScale = 0; //if zero, it reduce processing time

    if (NULL != UIGraphicsBeginImageContextWithOptions)
    {
        UIGraphicsBeginImageContextWithOptions(imageSize, NO, imageScale);
    }
    else
    {
        UIGraphicsBeginImageContext(imageSize);
    }

    [self.hiddenView.layer renderInContext:UIGraphicsGetCurrentContext()];

    [self.screenCaptureAndDraw.layer renderInContext:UIGraphicsGetCurrentContext()];


    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();



     image = (CGImageRef) [img CGImage];

    CVPixelBufferRef pixelBuffer = NULL;
    CFDataRef imageData= CGDataProviderCopyData(CGImageGetDataProvider(image));
    cvErr = CVPixelBufferCreateWithBytes(kCFAllocatorDefault,
                                         FRAME_WIDTH2,
                                         FRAME_HEIGHT2,
                                         kCVPixelFormatType_32BGRA,
                                         (void*)CFDataGetBytePtr(imageData),
                                         CGImageGetBytesPerRow(image),
                                         NULL,
                                         NULL,
                                         NULL,
                                         &pixelBuffer);


    //CFRelease(imageData);
    //CGImageRelease(image);  //I can't write this code because I am not creating it and when I check online, it say it is not my responsibility to release. If I write, the application crash immediately


    // calculate the time
    CFAbsoluteTime thisFrameWallClockTime = CFAbsoluteTimeGetCurrent();
    CFTimeInterval elapsedTime = thisFrameWallClockTime - firstFrameWallClockTime;


    // write the sample

    BOOL appended = [assetWriterPixelBufferAdaptor appendPixelBuffer:pixelBuffer withPresentationTime:presentationTime];

    if (appended) {
        NSLog (@"appended sample at time %lf and keepTrackofappended is %d", CMTimeGetSeconds(presentationTime),keepTrackofappended);
        keepTrackofappended++;
    } else {
        NSLog (@"failed to append");
        [self stopRecording];
        //self.startStopButton.selected = NO;
        screenRecord=false;
    }



}

}//stop capturing
// });


}
4

1 に答える 1