Open insikmania opened 7 years ago
Could be please let us know, How you create file URL?
I store the video URL to an array:
NSMutableDictionary fileInfo = [[NSMutableDictionary alloc] initWithDictionary:[self.videoURLArray firstObject]]; NSString originalFilename = fileInfo[@"original_filename"]; NSDictionary lastURL = [_videoURLArray lastObject]; NSURL videoURL = lastURL[@"updated_video"] ?: lastURL[@"original_video"]; NSString *path = [NSString stringWithFormat:@"Documents/%@-%lu.mov", originalFilename, filterAttempts];
here's where I store the edited video:
NSString pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:path]; unlink([pathToMovie UTF8String]); // If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie NSURL movieURL = [NSURL fileURLWithPath:pathToMovie];
See Attached Files Archive.zip
Try this! Simple solution :)
NSMutableDictionary *fileInfo = [[NSMutableDictionary alloc] initWithDictionary:[self.videoURLArray firstObject]];
NSString *originalFilename = fileInfo[@"original_filename"];
NSDictionary *lastURL = [_videoURLArray lastObject];
NSURL *videoURL = lastURL[@"updated_video"] ?: lastURL[@"original_video"];
// Don't assume path / NSString path = [NSString stringWithFormat:@"Documents/%@-%lu.mov", originalFilename, filterAttempts]; */
// Generate file path
NSURL *pathToMovie = [NSURL fileURLWithPath:NSHomeDirectory() isDirectory:true];
NSURL *path = [[pathToMovie URLByAppendingPathComponent:@"Documents"] URLByAppendingPathComponent:[NSString stringWithFormat:@"%@-%lu.mov", originalFilename, filterAttempts]];
NSLog(@"---%@",[path absoluteString]);
Don't convert path to NSString and convert to URL. This bad behaviour. Please maintain NSURL.
- (NSDictionary *)setupMovieFileAndReturnVideoURL {
NSMutableDictionary *fileInfo = [[NSMutableDictionary alloc] initWithDictionary:[self.videoURLArray firstObject]];
NSString *originalFilename = fileInfo[@"original_filename"];//[VideoWorker filenameOfOriginalAsset:self.videoURLArray];
NSDictionary *lastURL = [_videoURLArray lastObject];
NSURL *videoURL = lastURL[@"updated_video"] ?: lastURL[@"original_video"];
NSURL *pathToMovie = [NSURL fileURLWithPath:NSHomeDirectory() isDirectory:true];
NSURL *path = [[pathToMovie URLByAppendingPathComponent:@"Documents"] URLByAppendingPathComponent:[NSString stringWithFormat:@"%@-%lu.mov", originalFilename, filterAttempts]];
NSLog(@"---%@",[path absoluteString]);
return @{@"videoURL": videoURL, @"path": path};
}
- (void)applyTransformFilter:(TransformToolFilter)filterSelected completion:(void(^)(NSURL *transformedVideo))completion {
NSDictionary *dictionary = [self setupMovieFileAndReturnVideoURL];
NSURL *videoURL = dictionary[@"videoURL"];
NSURL *path = dictionary[@"path"]; // NSURL
[self processAndApplyAdjustmentsAndTransformationsToVideoWithVideoURL:videoURL path:path isUsedForMusic:NO completion:completion];
}
- (void)processAndApplyAdjustmentsAndTransformationsToVideoWithVideoURL:(NSURL *)videoURL path:(NSURL *)movieURL isUsedForMusic:(BOOL)usedForMusic completion:(void(^)(NSURL *filteredVideo))completion {
@autoreleasepool {
AVAsset *anAsset = [AVAsset assetWithURL:videoURL];
AVAssetTrack *videoTrack = [[anAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
mw = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:[videoTrack naturalSize]];
}
}
@vigneshuvi Thanks for the reply, I've tried this solution but still doesn't solve the issue it freezes at 15 attempts. :(
But I notice this changes maybe you can help me with this:
Ive tried every solution posted here but still cant solve this issue. Any help?