简体   繁体   English

FFmpeg iOS - >输出文件无效

[英]FFmpeg iOS -> output file is invalid

I'm using following library to convert mkv to mp4: https://github.com/SterlingOnLoop/FFmpegWrapper . 我正在使用以下库将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.");
        }
    }];
}

Here are the values from LLDB about the automatically detected codec types: 以下是LLDB关于自动检测到的编解码器类型的值:

(lldb) po inputStream.codecName
aac

(lldb) po outputStream.codecName
aac

I should mention here, that originally the file is generated on Linux with following codecs: vaapiencode_h264 for video and faac for sound. 我应该在这里提一下,在Linux上,产生最初的文件与下列编解码器: vaapiencode_h264视频和faac的声音。

The issue is that the file simply does not work. 问题是文件根本不起作用。 I get huge amount of logs in the console, where most important is: 我在控制台中获得了大量日志,其中最重要的是:

[aac @ 0x7f7f65019200] Format aac detected only with low score of 1, misdetection possible!

Inside the library, the following function is used: 在库中,使用以下函数:

int streamInfoValue = avformat_find_stream_info(inputFormatContext, NULL);

And exactly this line does the whole mess with the logs. 确切地说,这条线与日志完全混乱。 Obviously, without this line I receive an error with invalid argument. 显然,如果没有这行,我会收到带有无效参数的错误。

When that line is turned on, the .mp4 file is generated. 打开该行时,将生成.mp4文件。 It lasts > 5 minutes, while input file is 11 seconds long. 它持续> 5分钟,而输入文件长11秒。 It cannot be played using VLC on my mac (seems to be broken). 它无法在我的Mac上使用VLC播放(似乎已被破坏)。 I get following errors (I'm pasting few of them, full track can be found here , it's too long to quote it 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

Any idea how to simply convert mkv to mp4? 知道如何简单地将mkv转换为mp4吗? I don't have any idea why the errors occurs. 我不知道为什么会出错。 I'd claim that the file is not aac, but the linux uses this encoding, so it should be valid. 我声称该文件不是aac,但linux使用这种编码,所以它应该是有效的。

I've checked your file. 我检查了你的档案。 The main issues I can see is that : 我能看到的主要问题是:

  • There is no audio bitrate (ie: 128kbps should be set) 没有音频比特率(即:应设置128kbps)
  • Somehow the metadata lists the AAC version as 4 (what does that even mean??). 不知何故,元数据将AAC版本列为4(这甚至意味着什么?)。
  • The codec ID should be 40 but in the MKV's metadata it's listed as A_AAC/MPEG4/LC 编解码器ID应为40但在MKV的元数据中,它被列为A_AAC/MPEG4/LC
  • There is no flag for Channel Position in the bytes (ie: Front L+R) 字节中的通道位置没有标志(即:前L + R)

Anyways ffmpeg (command line) converted your MKV without any errors. 无论如何ffmpeg(命令行)转换你的MKV没有任何错误。
Let me know if this new re-encoded MP4 version works okay on your side. 让我知道这个新的重新编码的MP4版本是否适合您。

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

Unfortunately I don't code in iOS so I couldn't show you a "fixed" code. 不幸的是我不在iOS中编码,因此我无法向您显示“固定”代码。 Maybe someone can help later on. 也许有人可以在以后帮忙。 Look at this other Answer for extra hints (make it work like shown command line snippet above)... 看看这个额外提示的其他答案 (让它像上面显示的命令行代码段一样工作)...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM