在我应用效果的应用程序中,我的应用程序在第10张图像后崩溃

时间:2015-10-12 05:32:19

标签: ios

-(void)imageToVideoConversion:(NSMutableArray *)arrayOfImages
{

NSLog(@"(((((((((((((((((((())))))))))))))))))))) no of images:%lu",(unsigned long)[arrayOfImages count]);

NSArray *paths = nil;
NSString *documentsDirectory = nil;


paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

documentsDirectory = [paths objectAtIndex:0];

NSString *videoOutputPath =  [documentsDirectory stringByAppendingPathComponent:
                    [NSString stringWithFormat:@"ImageVideo-%d.mov",arc4random() % 1000]];



NSError *error = nil;
NSUInteger fps = 30;


imageSize = CGSizeMake(640, 640);

NSLog(@"Start building video from defined frames.");

videoWriter = [[AVAssetWriter alloc] initWithURL:
               [NSURL fileURLWithPath:videoOutputPath] fileType:AVFileTypeQuickTimeMovie
                                           error:&error];
NSParameterAssert(videoWriter);

NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                               AVVideoCodecH264, AVVideoCodecKey,
                               [NSNumber numberWithInt:imageSize.width], AVVideoWidthKey,
                               [NSNumber numberWithInt:imageSize.height], AVVideoHeightKey,
                               nil];

AVAssetWriterInput* videoWriterInput = [AVAssetWriterInput
                                        assetWriterInputWithMediaType:AVMediaTypeVideo
                                        outputSettings:videoSettings];


AVAssetWriterInputPixelBufferAdaptor *adaptor = [AVAssetWriterInputPixelBufferAdaptor
                                                 assetWriterInputPixelBufferAdaptorWithAssetWriterInput:videoWriterInput
                                                 sourcePixelBufferAttributes:nil];

NSParameterAssert(videoWriterInput);
NSParameterAssert([videoWriter canAddInput:videoWriterInput]);
videoWriterInput.expectsMediaDataInRealTime = YES;
[videoWriter addInput:videoWriterInput];

//Start a session:
[videoWriter startWriting];
[videoWriter startSessionAtSourceTime:kCMTimeZero];


int frameCount = 0;
double numberOfSecondsPerFrame =  1.0 * 3.0;

NSLog(@"Frame per seconds:%f", numberOfSecondsPerFrame);

double frameDuration = fps * numberOfSecondsPerFrame;



for(int i = 0; i<=[arrayOfImages count]; i++)
{
    UIImage *originalImage = nil;
    NSString *nameImage = nil;
    UILabel *title = nil;
    UIColor *cur_color;



    if (i == 0)
    {
        nameImage = [NSString stringWithFormat:@"TitleImage_%d.png",[[SingletonClass sharedManager] titleValue]+1];
        cur_color = [UIColor colorWithRed:(rgbValues[[[SingletonClass sharedManager] titleValue]].redValue/255) green:(rgbValues[[[SingletonClass sharedManager] titleValue]].greenValue/255) blue:(rgbValues[[[SingletonClass sharedManager] titleValue]].bluevalue/255) alpha:1.0];

        UIImageView *snapshotView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 640.0, 640.0)];
        snapshotView.image = [UIImage imageNamed:nameImage];



        title = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 640.0, 100.0)];
        title.center = CGPointMake(snapshotView.frame.size.width/2, snapshotView.frame.size.height/2);
        title.text = self.titleText.text;
        title.textColor = cur_color;
        title.textAlignment = NSTextAlignmentCenter;
        title.font = [UIFont fontWithName:[NSString stringWithFormat:@"%@",(font_styles)[[[SingletonClass sharedManager] titleValue]].fontStyle] size:75];
        title.backgroundColor = [UIColor clearColor];
        [snapshotView addSubview:title];



        UIGraphicsBeginImageContext(snapshotView.frame.size);
        [snapshotView.layer renderInContext:UIGraphicsGetCurrentContext()];
        originalImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();


    }

在我生成视频时没有应用效果,它正常工作。 我在仪器上运行它显示低内存警告,现在正是我必须要做的,任何人都知道请帮助我,提前谢谢。

0 个答案:

没有答案