GPUImageMovieWriter and avfiletypempeg4 file type

First of all, I would like to congratulate Brad on his amazing work on GPUImage.

I am trying to apply a rotation to this video file and get the mpeg4 file (AVFileTypeMPEG4) as output.

In doing so, I get the following message:

* - [AVAssetWriterInput appendSampleBuffer:] The input buffer must be in uncompressed format when outputSettings is not nil

This problem occurs when using the following init method for GPUImageMovieWriter with the file type set to AVFileTypeMPEG4:

- (id)initWithMovieURL:(NSURL *)newMovieURL size:(CGSize)newSize fileType:(NSString *)newFileType outputSettings:(NSMutableDictionary *)outputSettings; 

However, it works for another init method that actually generates a Quicktime movie (AVFileTypeQuickTimeMovie is set by default).

 - (id)initWithMovieURL:(NSURL *)newMovieURL size:(CGSize)newSize; 

Please someone tell me if GPUImageWriter can now output the mpeg4 movie file.

After many studies and attempts, you can see below one of several codes that I have made.

 movieFile = [[GPUImageMovie alloc] initWithURL:inputUrl]; movieFilter = [[GPUImageBrightnessFilter alloc] init]; [movieFilter setInputRotation:videoRotationMode atIndex:0]; [movieFile addTarget:movieFilter]; unlink([[outputUrl path] UTF8String]); // If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie NSMutableDictionary *videoSettings = [[NSMutableDictionary alloc] init];; [videoSettings setObject:AVVideoCodecH264 forKey:AVVideoCodecKey]; [videoSettings setObject:[NSNumber numberWithInteger:width] forKey:AVVideoWidthKey]; [videoSettings setObject:[NSNumber numberWithInteger:height] forKey:AVVideoHeightKey]; AudioChannelLayout channelLayout; memset(&channelLayout, 0, sizeof(AudioChannelLayout)); channelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo; NSDictionary *audioSettings = [NSDictionary dictionaryWithObjectsAndKeys: [ NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey, [ NSNumber numberWithInt: 2 ], AVNumberOfChannelsKey, [ NSNumber numberWithFloat: 16000.0 ], AVSampleRateKey, [ NSData dataWithBytes:&channelLayout length: sizeof( AudioChannelLayout ) ], AVChannelLayoutKey, [ NSNumber numberWithInt: 32000 ], AVEncoderBitRateKey, nil]; // Will create quicktime file movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:outputUrl size:CGSizeMake(640.0, 480.0) fileType:AVFileTypeMPEG4 outputSettings:videoSettings]; [movieFilter addTarget:movieWriter]; // Configure this for video from the movie file, where we want to preserve all video frames and audio samples movieWriter.shouldPassthroughAudio = NO; // default YES [movieWriter setHasAudioTrack:TRUE audioSettings:audioSettings]; movieFile.audioEncodingTarget = movieWriter; [movieFile enableSynchronizedEncodingUsingMovieWriter:movieWriter]; [movieWriter setDelegate:self]; [movieWriter startRecording]; [movieFile startProcessing]; 

Thank you in advance

PS: I am using iOS6

+3
source share

All Articles