我正在使用以下库将 mkv 转换为 mp4:https://github.com/SterlingOnLoop/FFmpegWrapper https://github.com/SterlingOnLoop/FFmpegWrapper.
- (void)convertUsingFFmpegWrapper {
NSString *mp4Extension = @"mp4";
NSString *mkvExtension = @"mkv";
NSString *videoName = @"file1";
// NSString *videoName = @"file2";
NSString *mkvVideoFilePath = [[NSBundle mainBundle] pathForResource:videoName ofType:mkvExtension];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = paths[0];
NSString *mp4VideoFilePath = [NSString stringWithFormat:@"%@/%@.%@", documentsDirectory, videoName, mp4Extension];
FFmpegWrapper *ffmpegWrapper = [[FFmpegWrapper alloc] init];
NSDictionary *options = @{kFFmpegInputFormatKey: mkvExtension, kFFmpegOutputFormatKey: mp4Extension};
[ffmpegWrapper convertInputPath:mkvVideoFilePath outputPath:mp4VideoFilePath options:options progressBlock:nil completionBlock:^(BOOL success, NSError *error) {
if (success && !error) {
// delete mp4 file
} else if (error) {
NSLog(@"Error during .MKV -> .MP4 conversion occured: %@", error.localizedDescription);
} else {
NSLog(@"Unknown error during .MKV -> .MP4 conversion occured.");
}
}];
}
以下是 LLDB 中有关自动检测到的编解码器类型的值:
(lldb) po inputStream.codecName
aac
(lldb) po outputStream.codecName
aac
我应该在这里提到,最初该文件是在 Linux 上使用以下编解码器生成的:vaapiencode_h264
对于视频和faac
为了声音。
问题是该文件根本不起作用。我在控制台中收到大量日志,其中最重要的是:
[aac @ 0x7f7f65019200] Format aac detected only with low score of 1, misdetection possible!
在库内部,使用以下函数:
int streamInfoValue = avformat_find_stream_info(inputFormatContext, NULL);
正是这一行把日志搞得一团糟。显然,如果没有这一行,我会收到参数无效的错误。
当该行打开时,将生成 .mp4 文件。它持续> 5 分钟,而输入文件长11 秒。它无法在我的 Mac 上使用 VLC 播放(似乎已损坏)。我收到以下错误(我粘贴了其中的一些错误,可以找到完整的曲目here https://gist.github.com/natalia-osa/988b6f84f0e1da5519b3b7fbd2c574c8,这里太长了,无法引用):
[aac @ 0x7ff07c00b000] More than one AAC RDB per ADTS frame is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[aac @ 0x7ff07c00b000] channel element 0.0 is not allocated
[aac @ 0x7ff07c00b000] Sample rate index in program config element does not match the sample rate index configured by the container.
[aac @ 0x7ff07c00b000] Inconsistent channel configuration.
[aac @ 0x7ff07c00b000] get_buffer() failed
[aac @ 0x7ff07c00b000] channel element 3.10 is not allocated
[aac @ 0x7ff07c00b000] Reserved bit set.
[aac @ 0x7ff07c00b000] invalid band type
[aac @ 0x7ff07c00b000] Number of scalefactor bands in group (50) exceeds limit (41).
[aac @ 0x7ff07c00b000] Reserved bit set.
[aac @ 0x7ff07c00b000] Number of bands (7) exceeds limit (4).
[aac @ 0x7ff07c00b000] Reserved bit set.
[aac @ 0x7ff07c00b000] Dependent coupling is not supported together with LTP
知道如何简单地将 mkv 转换为 mp4 吗?我不知道为什么会出现错误。我声称该文件不是 aac,但 linux 使用这种编码,所以它应该是有效的。