BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.25k stars 4.61k forks source link

No support ".mp4"? #1673

Closed xujingzhou closed 10 years ago

xujingzhou commented 10 years ago

Why does the follow code occur error for input and output file is '.mp4'?

NSURL *inputMovieURL = [[NSBundle mainBundle] URLForResource:@"1405314140692" withExtension:@"mp4"]; movieFile = [[GPUImageMovie alloc] initWithURL:inputMovieURL]; movieFile.runBenchmark = NO; movieFile.playAtActualSpeed = YES;

filter = [[GPUImageGlassSphereFilter alloc] init]; [(GPUImageGlassSphereFilter *)filter setRadius:0.45];

[movieFile addTarget:filter];

// Only rotate the video for display, leave orientation the same for recording
GPUImageView *filterView = (GPUImageView *)self.view;
[filter addTarget:filterView];

// In addition to displaying to the screen, write out a processed version of the movie to disk
NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.mp4"];
unlink([pathToMovie UTF8String]); // If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie
NSURL *outputMovieURL = [NSURL fileURLWithPath:pathToMovie];

movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:outputMovieURL size:CGSizeMake(360.0, 480.0) fileType:AVFileTypeMPEG4 outputSettings:nil]; [filter addTarget:movieWriter];

// Configure this for video from the movie file, where we want to preserve all video frames and audio samples
movieWriter.shouldPassthroughAudio = YES;
movieFile.audioEncodingTarget = movieWriter;
[movieFile enableSynchronizedEncodingUsingMovieWriter:movieWriter];

[movieWriter startRecording];
[movieFile startProcessing];

timer = [NSTimer scheduledTimerWithTimeInterval:0.3f
                                         target:self
                                       selector:@selector(retrievingProgress)
                                       userInfo:nil
                                        repeats:YES];

[movieWriter setCompletionBlock:^{
    [filter removeTarget:movieWriter];
    [movieWriter finishRecording];

    dispatch_async(dispatch_get_main_queue(), ^{
        [timer invalidate];
        self.progressLabel.text = @"100%";

        ALAssetsLibrary *_assetLibrary = [[ALAssetsLibrary alloc] init];
        [_assetLibrary writeVideoAtPathToSavedPhotosAlbum:[NSURL URLWithString:pathToMovie] completionBlock:^(NSURL *assetURL, NSError *error1) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Saved!" message: @"Saved to the photos album."
                                                           delegate:self
                                                  cancelButtonTitle:nil
                                                  otherButtonTitles:@"OK", nil];
            [alert show];
        }];

    });
}];
xujingzhou commented 10 years ago

I modified code according to the follow demo in web link, But It still doesn't work because App will dead after progress to "99%". I checked code and find "setCompletionBlock" function hasn't been execute. Who can tell me how to solve this issue?

http://stackoverflow.com/questions/13490798/gpuimagemoviewriter-and-avfiletypempeg4-filetype

xujingzhou commented 10 years ago

I fixed this issue by add a step to convert from .mov to .mp4

Fairtoys commented 9 years ago

怎么解决的啊?麻烦大神说下