首先,我要祝贺Brad在GPUImage上的出色工作。
我尝试将旋转应用于给定的视频文件并获取mpeg4(AVFileTypeMPEG4)文件作为输出。
执行此操作时,我会收到以下消息:
* - [AVAssetWriterInput appendSampleBuffer:]当outputSettings不为nil时,输入缓冲区必须采用未压缩格式
使用以下文件类型设置为AVFileTypeMPEG4的GPUImageMovieWriter的init方法时会发生此问题:
- (id)initWithMovieURL:(NSURL *)newMovieURL size:(CGSize)newSize fileType:(NSString *)newFileType outputSettings:(NSMutableDictionary *)outputSettings;
但是它适用于另一个实际生成quicktime影片的init方法(默认设置AVFileTypeQuickTimeMovie)。
- (id)initWithMovieURL:(NSURL *)newMovieURL size:(CGSize)newSize;
如果GPUImageWriter能够从现在开始输出mpeg4电影文件,请有人能说我。
经过多次调查和尝试后,您可以看到我制作的几个代码中的一个。
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];
提前致谢
PS:我使用的是iOS6