简体   繁体   English

FFmpeg-混合视频和音频时大文件的ANR

[英]FFmpeg - ANR on large files when mixing video and audio

This command 这个命令

ffmpeg -i video.webm -i audio.m4a -c copy output.mkv ffmpeg -i video.webm -i audio.m4a -c复制output.mkv

will always produce an ANR error in android at the end of the conversion for any large files, say greater than 700mb. 转换结束时,对于任何大文件(例如大于700mb),在android中总是会产生ANR错误。

The ANR error is produced only at the finishing end of the conversion process after the output has been successfully generated, not in the middle or at the beginning etc. 仅在成功生成输出之后的转换过程的最后阶段才产生ANR错误,而不是在中间或开头等。

So I suspect it has got to do with some I/O stuff at the end. 因此,我怀疑它最终与某些I / O内容有关。 Can someone please shed some light into this, and help eliminate this ANR problem? 有人可以对此有所帮助,并帮助消除此ANR问题吗?

By default, ffmpeg produces progress output ~every 500ms. 默认情况下, ffmpeg每隔500ms产生进度输出。 The way FFmpeg-Android treats this output, it returns the progress message to your onProgress() callback, and also appends all these (relatively short) messages to a String, which is returned in onSuccess() . FFmpeg-Android处理此输出的方式是,将进度消息返回到onProgress()回调,还将所有这些(相对较短的)消息附加到String onSuccess()onSuccess()返回onSuccess()

What happens is, for a large video file the memory may get exhausted, or at least the Garbage Collector will work pretty hard. 发生的情况是,对于较大的视频文件,内存可能已用尽,或者至少垃圾回收器会非常努力地工作。 These String manipulations happen on the Main thread, which can easily cause ANR. 这些String操作发生在Main线程上,很容易导致ANR。

As a quick workaround, you can pass -nostats to the ffmpeg command line: 作为一种快速的解决方法,可以将-nostats传递给ffmpeg命令行:

ffmpeg -i video.webm -i audio.m4a -c copy output.mkv -nostats

To resolve the issue, look at https://github.com/bravobit/FFmpeg-Android/pull/128 . 要解决此问题,请查看https://github.com/bravobit/FFmpeg-Android/pull/128

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

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