本文介绍了FFmpeg iOS - >输出文件无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在使用以下图书馆将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){ / /删除mp4文件} else if(error){ NSLog(@.MKV中的错误 - > .MP4转换发生:%@,error.localizedDescription); } else { NSLog(@.MKV中的未知错误 - > .MP4转换发生。 } }]; } 以下是LLDB中有关自动检测到的编解码器类型的值: (lldb)po inputStream.codecName aac (lldb)po outputStream.codecName $ a $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ vaapiencode_h264 视频和 faac 声音。 问题是文件根本不工作。我在控制台中收到大量日志,其中最重要的是: [aac @ 0x7f7f65019200]得分1,误检可能! 在图书馆内使用以下功能: int streamInfoValue = avformat_find_stream_info(inputFormatContext,NULL); 这一行完全与日志混在一起。显然,没有这一行,我收到一个无效参数的错误。 当该行打开时,会生成.mp4文件。它持续> 5分钟,而输入文件长达11秒。它不能在我的mac上使用VLC播放(似乎被打破)。我收到以下错误(我粘贴了几个,完整的轨迹可以找到 here 在这里报价太长了): [aac @ 0x7ff07c00b000]每个ADTS框架不止一个AAC RDB不实现。将您的FFmpeg版本从Git更新为最新版本。如果问题仍然发生,这意味着您的文件具有尚未实现的功能。 [aac @ 0x7ff07c00b000]通道元素0.0未分配 [aac @ 0x7ff07c00b000]程序配置元素中的采样率索引与容器配置的采样率索引不匹配。 [aac @ 0x7ff07c00b000]通道配置不一致。 [aac @ 0x7ff07c00b000] get_buffer()失败 [aac @ 0x7ff07c00b000]通道元素3.10未分配 [aac @ 0x7ff07c00b000]保留位设置。 [aac @ 0x7ff07c00b000]无效频带类型 [aac @ 0x7ff07c00b000]组(50)中的比例因子数量超过限制(41)。 [aac @ 0x7ff07c00b000]保留位置位。 [aac @ 0x7ff07c00b000]频带数(7)超过限制(4)。 [aac @ 0x7ff07c00b000]保留位置位。 [aac @ 0x7ff07c00b000]与LTP一起支持依赖耦合 任何想法如何简单地将mkv转换为mp4?我不知道为什么错误发生。我声称该文件不是aac,但是linux使用这种编码,所以它应该是有效的。解决方案我已检查您的文件。我可以看到的主要问题是: 没有音频比特率(即应设置128kbps) 不管怎样,元数据将AAC版本列为4(甚至是什么意思??)。 编解码器ID应为 40 而是在MKV的元数据中被列为 A_AAC / MPEG4 / LC 字节(即:前L + R) 无论如何ffmpeg(命令行)转换您的MKV没有任何错误。让我知道这个新的 重新编码MP4 ffmpeg设置简单: ffmpeg -i mkv_demo.mkv -c: v copy demo_new.mp4 不幸的是我不在iOS中编码,所以我无法显示一个固定的代码。也许有人可以稍后帮忙。看看这个其他 回答 以获得额外的提示(使其工作像上面显示的命令行代码段) ... I'm using following library to convert mkv to 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) po inputStream.codecNameaac(lldb) po outputStream.codecNameaacI should mention here, that originally the file is generated on Linux with following codecs: vaapiencode_h264 for video and faac for sound.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. It lasts > 5 minutes, while input file is 11 seconds long. It cannot be played using VLC on my mac (seems to be broken). 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 LTPAny idea how to simply convert mkv to 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. 解决方案 I've checked your file. The main issues I can see is that : There is no audio bitrate (ie: 128kbps should be set)Somehow the metadata lists the AAC version as 4 (what does that even mean??).The codec ID should be 40 but in the MKV's metadata it's listed as A_AAC/MPEG4/LC There is no flag for Channel Position in the bytes (ie: Front L+R)Anyways ffmpeg (command line) converted your MKV without any errors.Let me know if this new re-encoded MP4 version works okay on your side.The ffmpeg settings were simply : ffmpeg -i mkv_demo.mkv -c:v copy demo_new.mp4Unfortunately I don't code in iOS so I couldn't show you a "fixed" code. Maybe someone can help later on. Look at this other Answer for extra hints (make it work like shown command line snippet above)... 这篇关于FFmpeg iOS - >输出文件无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-18 13:40