-
-
Notifications
You must be signed in to change notification settings - Fork 796
Issue when using mobile-ffmpeg, with Unity3D on Android #258
Comments
I have the same problem. I used all the different versions of Unity (2018 LTS to 2019.2), built it for ARMv7 and ARM64 and reduced my app to the minimum. The encoding process is working with sync or async calls and I can repeat them without any problem. But it seems mobileffmpeg/ffmpeg is using resources or memory that belong to Unity. It crashed when I call:
As long as there was no encoding process started, everything runs fine, but with the start of mobileffmpeg Unity becomes unstable. I spend so much time right now to fix that in Unity, but without success. There must be something within the plugin, not unlinking or discard resources. I'm happy that I'm not alone anymore with that huge problem. My logs look the same:
|
@cyliax Haha yeah i saw your posts on being able to work with the library Asynchronously and thought you had everything resolved. (If we get this resolved I'll probably ask you about how you got it running asynchronously haha) On your crashes, I think its always the same thing. I was recording images from a RenderTexture and it always crashed on the 13th image, but i noticed on the memory profiler that every 13th image, without me calling the ffmpeg library previously, the GC allocation got released. So either that means Unity was internally calling UnloadUnusedAssets, or C# was doing GC.Collect and UnloadUnusedAssets calls GC.Collect internally as well. Reloading a scene in a non-additive fashion causes Unity to call UnloadUnusedAssets as well. After much testing Im also sure the plugin is mishandling memory in some way that causes the app to panic when garbage collection is done. Have you manage to find anything in your tests? Today Im gonna try out a couple of things and will post here if I find anything. |
Your right, I thought everything is resolved, but with that crashes all the time, it is not. So I wasn't that happy and I haven't shared my solution yet (but I will). You might be right, that all our problems are coming from the same Resources.UnloadUnusedAsset and GC.Collect somehow. That leads me to disable garbage collection in my single scene with:
for a test, and you know what: IT IS WORKING! (as long as I'm not reloading the scene) But of course, that can't be the solution. I would be interesting if a non Unity app using the plugin is crashing as well, when calling Javas System.gc(). |
@cyliax Huh really? I did test disabling Garbage Collection but got the crash anyways, but even then disabling garbage collection makes the app a ticking bomb until it crashes haha |
Tried a lot of things to resolve this, unfortunately I wasn't successful. |
So yeah, I retried @cyliax 's mode of disabling the Garbage Collection and it works. Ive also managed to get it running asynchronously but without disabling the garbage collector the app crashes without finishing processing the video. Ive tried researching a lot on what could be causing this, and apparently it should be an error from the unmanaged part of code (the C part) but obviously the ffmpeg library is immense and would take a long time to figure out which part causes the issue. So ideally we should try and find where the issue is. Ive got this trace: `11-25 16:00:47.029 8062 8081 E CRASH : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0013c288 11-25 16:00:47.029 8062 8081 E CRASH : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 11-25 16:00:47.029 8062 8081 E CRASH : Build type 'Release', Scripting Backend 'il2cpp', CPU 'armeabi-v7a' 11-25 16:00:47.029 8062 8081 E CRASH : Build fingerprint: 'samsung/beyond2qlteue/beyond2q:9/redacted/Gredacted:user/release-keys' 11-25 16:00:47.029 8062 8081 E CRASH : Revision: '17' 11-25 16:00:47.029 8062 8081 E CRASH : pid: 8062, tid: 8081, name: UnityMain >>> com.redacted.redacted <<< 11-25 16:00:47.029 8062 8081 E CRASH : r0 c8906bc0 r1 00000000 r2 00000000 r3 00000000 11-25 16:00:47.029 8062 8081 E CRASH : r4 00000000 r5 c8905aa0 r6 c962e680 r7 00000005 11-25 16:00:47.029 8062 8081 E CRASH : r8 00000000 r9 00000000 sl 00000001 fp caafe970 11-25 16:00:47.029 8062 8081 E CRASH : ip c9628e2c sp caafe950 lr c8906868 pc 0013c288 cpsr c06f8700 11-25 16:00:47.029 8062 8081 E CRASH : 11-25 16:00:47.029 8062 8081 E CRASH : backtrace:` If we can find a way to translate the trace to something more readable that could help. |
Hello, |
Has anybody had success with this garbage collection/crash problem? I could cry because I'm loosing day after day and nothing helps. Extracted AAR to JAR, using instance calls except of static, switching back to sync calls, updating Unity to 2019.3.6f1, updating mobile-ffmpeg to 4.3.1, checking and unchecking options in unity... and so on. At the moment I'm still switching off garbage collection at app start, then I have an overlay button to enable garbage collection and call Resources.UnloadUnusedAssets() or GC.Collect(), and switching it off again. I can press that button as often as I like before mobile-ffmpeg was running. But when I started a successful ffmpeg conversion and I press that button once or twice... crash, without a helpful crash log via ADB. @tanersener if I could send you a simple Unity example scene with everything you need, It would be awesome if you'd have a look. Would it help to support you with some money via your donation channel? Any help is highly appreciated, thank you for your great work. |
@cyliax created my own sample project to demonstrate this issue. Unfortunately, I don't have any ideas about the solution. This integration is too complex for me. I think someone who has experience in loading native libraries inside Unity can help us solve this. |
I have a question about the crash scenario. As far as I understand, application crashes when My question is; what happens when |
I found a workaround and it this also answers your question a bit (I will build your scenario today): My workaround for now: Now back to your question: I'll try calling GC during encoding... |
Hey @tanersener! I've experienced something similar, where Android is crashing silently when trying to load an asset after using ffmpeg (doesn't have to be the asset that was just generated). No error is given or exception thrown before the crash so it makes it very difficult to track, but after some research we were able to figure out that it was only ever happening when making certain calls AFTER using mobile-ffmpeg. The same call made before using ffmpeg does not cause the app to crash. |
Hey guys. I use ffmpeg for operations on audio data, e.g. generating .ogg files. In my cases, @cyliax 's solution doesn't work. Has anyone else succeeded in making Unity not crash after encoding? I build mobile-ffmpeg.arr with lots of comments on the native side written in c and tried different things. In the "fftools_ffmpeg_opt.c" file in "ffmpeg_parse_options(int argc, char **argv)" method, I removed call to "term_init ();". After that it seems to work with Unity without crash. I'm not a "c" guy, don't understand why it's not crashing after that and don't know consequences of removing this call.
P.S. @tanersener I love you man for this project :) |
I did further tests, which showed that after removing the following line, Unity no longer crash after encoding and calling Resources.UnloadUnusedAssets(). file fftools_ffmpeg.c -> void term_init(void) Anybody knows what's going on? SIGXCPU signal means "CPU time limit exceeded". This is signal handler:
|
That are great news, Thanks for your test to find out where those crashes come from. Unfortunately I'm not a C guy as well, so I can't give you support. But I'll try your approach to get rid of my workaround routine. Using UnloadUnsedAssets as normal would be awesome. |
@wloczykij89 sigterm_handler is a common structure used in C applications. It is used to handle signals sent by Operating System. I'm not sure whether your solution is fixing the problem or postponing it. Because not handling a signal looks scary a little bit. Is it possible to test which statement in |
@tanersener I totally agree with you and treat this as a clue to finding the real cause of the error. But damn, in my test project, it works after that change :/ Maybe I'll do more tests on a complex project and different devices. The specific line of code that cause crash in sigterm_handler (int sig): I have created test handler only for SIGXCPU: "test_sigterm_handler" with logs and commented out "exit(123)" line:
During encoding, "test_sigterm_handler" may invoke several times or not at all.
|
@wloczykij89 Thanks for doing these tests. I think you've already found the real cause of this issue. If you ask google The solution is to ignore |
Added a new API method,
Android
iOS/tvOS
|
July 2020. |
Awesome, I'll try this as soon as I can. Hopefully I can remove my stupid garbage collection workarounds. Great work! |
Hi cyliax and tanersener, I'm seeing the same crash on my side too using Unity 2019, do you have a link to download an Android LTS binary so I could test it on my side too? Thanks. |
@shpitsmedia You can use this dev build for testing, mobile-ffmpeg-min-4.3.3.LTS.aar. |
@tanersener Amazing, it works! can you please also send me a link to the full LTS version? |
I don't have a full LTS dev build. You can build it yourself though. |
@tanersener This is a bit over my head :) do you know when you are going to release the next release? |
|
@tanersener Excellent, its just around the corner, thanks again! |
@tanersener Hi again, we've got a little problem, we're trying to merge 2 mp4 videos using -filter_complex concat but it seems that without libx264 the output video is very low quality, do you have a clue how can it be done without using GPL if even possible? |
@shpitsmedia You don't have too many options there. You can try to use |
@tanersener mpeg4 works, thank you so much for the help! |
Hi, I just tried the MobileFFmpeg 4.4 (not the LTS) in Unity 2019.4.5f1 and it works. Many thanks :). You do a great job. Here is the the code I used in Unity in case someone struggles with it:
I'm also attaching .unitypackage with dependency solver (Unity project just needs to be set up for it to work) and very rough iOS wrapper. Let's hope it helps. Thanks again and keep up the good work :). |
Fixed and released in |
Hello Everybody, public static void ExecuteAsync(string command) { //implement the interface ExecuteCallback as separate class in the same script or own script file |
Description
I get an app crash whenever I call Resources.UnloadUnusedAssets after executing something on the library. Im currently testing it with the "-i path -hide_banner" arguments.
Expected behavior
I expect the app not to crash.
Current behavior
The app crashes immediately.
Screenshots
If applicable, add screenshots to help explain your problem.
Logs
https://ghostbin.co/paste/vt9t4
Environment
Other
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: