ios - FFmpeg iOS -> 输出文件无效

标签 ios objective-c ffmpeg mp4 aac

我正在使用以下库将 mkv 转换为 mp4: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 ,在这里引用它太长了):

[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 使用此编码,因此它应该是有效的。

最佳答案

我已经检查了你的文件。我能看到的主要问题是:

  • 没有音频比特率(即:应设置为 128kbps)
  • 元数据以某种方式将 AAC 版本列为 4(这到底是什么意思??)。
  • 编解码器 ID 应为 40 但在 MKV 的元数据中它被列为 A_AAC/MPEG4/LC
  • 字节中没有Channel Position标志(即:Front L+R)

无论如何 ffmpeg(命令行)转换您的 MKV 没有任何错误。
如果这个新的 re-encoded MP4 让我知道 版本在您这边工作正常。

ffmpeg 设置很简单:ffmpeg -i mkv_demo.mkv -c:v copy demo_new.mp4

很遗憾,我不会在 iOS 中编写代码,因此无法向您展示“固定”代码。也许以后有人可以提供帮助。看看这个其他 Answer 额外的提示(让它像上面显示的命令行片段一样工作)...

关于ios - FFmpeg iOS -> 输出文件无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38326396/

相关文章:

ios - HTTP 请求采用默认方法 GET 而不是 POST

objective-c - MKNetworkKit:请求链,其中每个后续请求都需要来自前一个请求的数据

objective-c - TWIN PRIMES BETWEEN 2 VALUES 错误的结果

ios - 切换到 64 位时 MoPub 错误

在 mpegvideo.c 文件之外调用 ff_print_debug_info2

FFMPEG:我需要音频 channel 7 和 8 作为视频的主要音轨

ios - 在 iOS Action Extension 中使用 SwiftUI 内容 View 而不是 Action ViewController 启动

ios - 有什么方法可以防止新用户下载应用程序,但仍然为现有用户提供错误修复?

iphone - 如何对齐 UIAlertView 中的消息?

video - FFMPEG - 将 MKV 转换为带有所有流(字幕)和水印的 MP4