我们已要求一名自由职业者使用 FFMPeg for iOS 构建一个视频编码器,但存在错误,该自由职业者不再可用。我对 FFMpeg 和视频编码非常缺乏经验,正在尝试调试此错误。
据我了解,我们正在尝试创建一个输出文件并为其创建一个标头,但是 avformat_write_header 始终小于零。如果我注释掉它,它就不起作用
- (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;
}
下面是我们如何实例化 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;
}
如果 avformat_write_header 返回 < 0, The problem could be one of these
我建议您在调试模式下运行。它将显示详细的错误消息。添加以下代码,您可以确保它在 FFMPEG 代码运行之前运行。
av_log_set_level(AV_LOG_DEBUG);
我相信你会发现关于AVFormatContext的错误信息。