GPUImageMovieWriter and avfiletypempeg4 filetype

No replies
DeepThought
User offline. Last seen 8 years 27 weeks ago. Offline
Joined: 11/21/2012
Posts:

HI,

First of all I would like congratulate you Brad for the amazing work.

I'm trying to apply a rotation to a given video file and obtain an mpeg4 (AVFileTypeMPEG4) file as output.

When doing this I obtain the following message :

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

This problem occurs when using the following init method of GPUImageMovieWriter with filetype set to AVFileTypeMPEG4 :
- (id)initWithMovieURL:(NSURL *)newMovieURL size:(CGSize)newSize fileType:(NSString *)newFileType outputSettings:(NSMutableDictionary *)outputSettings;

However it works for the another init method which in fact generate quicktime movie (AVFileTypeQuickTimeMovie is set by default).

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

Please can anybody say me if GPUImageWriter is capable from now to output mpeg4 movie file.

After many investigation and tries you can see below one of the several code I 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];

Thanks in advance

Syndicate content