GPUImage
GPUImage copied to clipboard
Exported Video has no sound.
I am using filters to filter a local video on the iOS device. When i export that video and save it to the phones camera roll it no longer has any sound.
-(void) filter: (NSURL *)videoUrl andFilePath : (NSString *) filepath{
GPUImageSepiaFilter *sepia = [[GPUImageSepiaFilter alloc] init];
GPUImageColorInvertFilter *invert = [[GPUImageColorInvertFilter alloc] init];
GPUImageGrayscaleFilter *grayScale = [[GPUImageGrayscaleFilter alloc] init];
GPUImageHazeFilter *haze = [[GPUImageHazeFilter alloc] init];
GPUImageMonochromeFilter *monochrome = [[GPUImageMonochromeFilter alloc] init];
if ([self.story.filterName isEqualToString:@"Sepia"]) {
videoFilter = sepia;
}
else if ([self.story.filterName isEqualToString:@"Invert"]) {
videoFilter = invert;
}
else if ([self.story.filterName isEqualToString:@"Gray Scale"]) {
videoFilter = grayScale;
}
else if ([self.story.filterName isEqualToString:@"Haze"]) {
videoFilter = haze;
}
else if ([self.story.filterName isEqualToString:@"Monochrome"]) {
videoFilter = monochrome;
}
_movieFile = [[GPUImageMovie alloc] initWithURL:videoUrl];
[_movieFile addTarget:videoFilter];
NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.m4v"];
unlink([pathToMovie UTF8String]);
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(1920, 1080)];
[videoFilter addTarget:movieWriter];
movieWriter.shouldPassthroughAudio = YES;
_movieFile.audioEncodingTarget = movieWriter;
[_movieFile enableSynchronizedEncodingUsingMovieWriter:movieWriter];
[movieWriter startRecording];
[_movieFile startProcessing];
NSString *fileName = [NSString stringWithFormat:@"toloVideo%-d.mp4",arc4random() % 10000];
__unsafe_unretained typeof(self) weakSelf = self;
[movieWriter setCompletionBlock:^{
NSLog(@"HELLO");
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:movieURL]) {
[library writeVideoAtPathToSavedPhotosAlbum:movieURL completionBlock:^(NSURL *assetURL, NSError *error)
{
[library assetForURL:assetURL
resultBlock:^(ALAsset *asset) {
[weakSelf.story addExportedUrlInContext:[AppDelegate sharedDelegate].managedObjectContext withStory:weakSelf.story andURL:[assetURL absoluteString] andFilePath:fileName];
dispatch_async(dispatch_get_main_queue(), ^{
ALAssetRepresentation *representation = asset.defaultRepresentation;
weakSelf->_completedStoryVideoImage.image = [UIImage imageWithCGImage:representation.fullResolutionImage
scale:1.0f
orientation:(UIImageOrientation)representation.orientation];
});
NSLog(@"ASSET URL %@",assetURL);
if (error)
{
NSLog(@"ERROR %@ ", error);
}else{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
BOOL success = [fileManager removeItemAtPath:filepath error:&error];
if (success) {
NSLog(@"Deleted");
}
else
{
NSLog(@"Could not delete file -:%@ ",[error localizedDescription]);
}
NSLog(@"VIDEO SAVED ");
}
}
failureBlock:^(NSError* error) {
NSLog(@"failed to retrieve image asset:\nError: %@ ", [error localizedDescription]);
}];
}];
NSLog(@"Video Merge SuccessFully");
[MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
}
[weakSelf->videoFilter removeTarget:weakSelf->movieWriter];
[weakSelf->movieWriter finishRecording];
}];
}
Seems like this should be possible and work. If not then there seems to be a bug.
Seems like something a few people have complained about lately. Perhaps something changed in the timing in a recent iOS update. Unfortunately, I'm not much good with the AV Foundation audio side of things, and almost all that code was contributed by other developers. I don't record movies with sound in any of my applications.
Sadly, movies without sound look meaningless @BradLarson
@imChay did you found any solution for the same?