Reputation: 302
We've asked a freelancer to build a video encoder with FFMPeg for iOS but there is a bug and the freelancer is no longer available. I very inexperienced in FFMpeg and video encoding and am trying to debug this error.
From what I understand, we're attempting to create an output file and create a header for it however, avformat_write_header is always less than zero. If I comment it out, it does not work
- (BOOL) writeHeaderWithError:(NSError *__autoreleasing *)error {
AVDictionary *options = NULL;
// Write header for output file
int writeHeaderValue = avformat_write_header(self.formatContext, &options);
if (writeHeaderValue < 0) {
if (error != NULL) {
*error = [FFUtilities errorForAVError:writeHeaderValue];
}
av_dict_free(&options);
return NO;
}
av_dict_free(&options);
return YES;
}
Below is some relevant code of how we instantiate a FFOutputFile
- (AVFormatContext*) formatContextForOutputPath:(NSString*)outputPath options:(NSDictionary*)options {
AVFormatContext *outputFormatContext = NULL;
NSString *outputFormatString = [options objectForKey:kFFmpegOutputFormatKey];
int openOutputValue = avformat_alloc_output_context2(&outputFormatContext, NULL, [outputFormatString UTF8String], [outputPath UTF8String]);
if (openOutputValue < 0) {
avformat_free_context(outputFormatContext);
return nil;
}
return outputFormatContext;
}
- (void) addOutputStream:(FFOutputStream*)outputStream {
[self.streams addObject:outputStream];
}
- (id) initWithPath:(NSString *)path options:(NSDictionary *)options {
if (self = [super initWithPath:path options:options]) {
self.formatContext = [self formatContextForOutputPath:path options:options];
self.streams = [NSMutableArray array];
self.bitstreamFilters = [NSMutableSet set];
}
return self;
}
Upvotes: 0
Views: 2231
Reputation: 404
If avformat_write_header returns < 0, The problem could be one of these
I recommend you to run in debug mode. It will show the detailed error message. Add it the below code in where you can assure that it runs before FFMPEG code run.
av_log_set_level(AV_LOG_DEBUG);
I believe that you will find the error message about AVFormatContext.
Upvotes: 3