1

それぞれが 150 ~ 200 フレームに相当する 2 つのビデオ フレームの配列があります。マージされたフレームの配列を取得するために、それらをマージしています。次のコードを使用しています。

NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"/Documents/movie.mp4"]];
NSURL *outputURL = [NSURL fileURLWithPath:filePath];
player = [[MPMoviePlayerController alloc]initWithContentURL:outputURL];

float frame = 0.00;
int count = 1;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
docPath = [docPath stringByAppendingPathComponent:@"OutPut"];
BOOL success = [fileManager fileExistsAtPath:docPath];
if (success) {
    [fileManager removeItemAtPath:docPath error:nil];
}
[fileManager createDirectoryAtPath:docPath withIntermediateDirectories:YES attributes:nil error:nil];
for (frame = frameStartTime; frame < (frameStartTime+7); frame+=0.033)
    {
    @autoreleasepool
        {
    UIImage * singleFrameImage = [player thumbnailImageAtTime:frame timeOption:MPMovieTimeOptionExact];
    [player pause];
    NSString *imageName = [NSString stringWithFormat:@"export2%d.png",count];
    UIImage *overlayImage = [UIImage imageNamed:imageName];
    count = count + 1;
    NSString *imagePath = [NSString stringWithFormat:@"outImage%f.png",frame];
   imagePath = [NSString stringWithFormat:@"%@/%@", docPath, imageName];
    if (overlayImage)
    {
        UIImage *  outImage = [self mergeImage:singleFrameImage withImage:overlayImage];
        NSData *imgData = UIImagePNGRepresentation(outImage);
       [fileManager createFileAtPath:imagePath contents:imgData attributes:nil];

    }
    else
    {
        NSData *imgData = UIImagePNGRepresentation(singleFrameImage);
         [fileManager createFileAtPath:imagePath contents:imgData attributes:nil];


    }

    [outputFramesArray addObject:imagePath];
}

}


[player release];
if([fileManager fileExistsAtPath:filePath])
{

    [fileManager removeItemAtPath:filePath error:nil];

}


NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"/Documents/movie1.mp4"]];
NSLog(@"filePath %@", path);

if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
    [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
}

[self writeImageAsMovie:outputFramesArray toPath:path size:CGSizeMake(480, 320) duration:10];
NSLog(@"hello Your layering is completed");

[outputFramesArray removeAllObjects];
[outputFramesArray release];
success = [fileManager fileExistsAtPath:docPath];

if (success) {
    [fileManager removeItemAtPath:docPath error:nil];
}

/// [self performSelectorOnMainThread:@selector(CompileFilesToMakeMovieWithAudio) withObject:nil waitUntilDone:YES];
[self CompileFilesToMakeMovieWithAudio];
  // [self compileFinalOutputMovie];
}



- (UIImage*)mergeImage:(UIImage*)first withImage:(UIImage*)second {
    CGSize mergedSize = CGSizeMake(480,320);   
    UIGraphicsBeginImageContext(mergedSize);
    [first drawInRect:CGRectMake(0, 0, 480, 320)];
    [second drawInRect:CGRectMake(0, 0, 480, 320)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

私の問題は、すべてのフレームをマージするのに時間がかかることです。

タスクを速くする方法はありますか?

ありがとうございました

4

0 に答える 0