tanersener / flutter-ffmpeg

FFmpeg plugin for Flutter. Not maintained anymore. Superseded by FFmpegKit.
GNU Lesser General Public License v3.0
644 stars 132 forks source link

FFmpeg crashes fatally on Android #302

Closed Gicminos closed 3 years ago

Gicminos commented 3 years ago

Description After doing various conversions, FFmpeg makes the Android application crash. The issue seems similar to https://github.com/tanersener/mobile-ffmpeg/issues/320 but it happens on the new FFmpeg version 4.4-dev-416

Expected behavior I expect the app not to crash or at least crash with an error that can be caught instead of generating a SIGABRT

Current behavior After a not defined number of operation, the app crashes fatally.

Logs

I/mobile-ffmpeg(32658): 
F/libc    (32658): FORTIFY: pthread_mutex_destroy called on a destroyed mutex (0x746585bb98)
F/libc    (32658): Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 6386 (AsyncTask #3), pid 32658 (com.app.app)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'OnePlus/Nord_EEA/Nord:11/RP1A.201005.001/2103130237:user/release-keys'
Revision: '0'
ABI: 'arm64'
Timestamp: 2021-05-11 12:29:53+0100
pid: 32658, tid: 6386, name: AsyncTask #3  >>> com.app.app <<<
uid: 10399
signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
Abort message: 'FORTIFY: pthread_mutex_destroy called on a destroyed mutex (0x746585bb98)'
    x0  0000000000000000  x1  00000000000018f2  x2  0000000000000006  x3  00000073c7b1a500
    x4  0000000000000000  x5  0000000000000000  x6  0000000000000000  x7  0000000000000010
    x8  00000000000000f0  x9  e6b8fdff6eef8d16  x10 0000000000000000  x11 ffffffc0fffffbdf
    x12 0000000000000001  x13 00000073c7b1a062  x14 000000000000001b  x15 00000000000000c4
    x16 0000007728cc2c80  x17 0000007728ca4b70  x18 00000073b934a000  x19 0000000000007f92
    x20 00000000000018f2  x21 00000000ffffffff  x22 0000000000a1ce14  x23 000000000514020c
    x24 0000000000082205  x25 000000736f71dbcf  x26 00000000000c2011  x27 0000000000082005
    x28 000000736f71f07a  x29 00000073c7b1a580
    lr  0000007728c583e0  sp  00000073c7b1a4e0  pc  0000007728c5840c  pst 0000000000001000
backtrace:
      #00 pc 000000000004e40c  /apex/com.android.runtime/lib64/bionic/libc.so (abort+164) (BuildId: 177ced94c8a288368e00f7f6d454f607)
      #01 pc 00000000000b1724  /apex/com.android.runtime/lib64/bionic/libc.so (__fortify_fatal(char const*, ...)+124) (BuildId: 177ced94c8a288368e00f7f6d454f607)
      #02 pc 00000000000b0d20  /apex/com.android.runtime/lib64/bionic/libc.so (HandleUsingDestroyedMutex(pthread_mutex_t*, char const*)+52) (BuildId: 177ced94c8a288368e00f7f6d454f607)
      #03 pc 00000000000b16a0  /apex/com.android.runtime/lib64/bionic/libc.so (pthread_mutex_destroy+144) (BuildId: 177ced94c8a288368e00f7f6d454f607)
      #04 pc 00000000000161f4  /data/app/~~b1IcgZyNV2Qh04rrBKVlYw==/com.app.app-T9kJdSRjZ9WidZfqbsKwiw==/lib/arm64/libmobileffmpeg.so (exit_program+32) (BuildId: b57e749e21d9106923ad74eb8a4b767e70a578d9)
      #05 pc 000000000001f8d8  /data/app/~~b1IcgZyNV2Qh04rrBKVlYw==/com.app.app-T9kJdSRjZ9WidZfqbsKwiw==/lib/arm64/libmobileffmpeg.so (ffmpeg_execute+10848) (BuildId: b57e749e21d9106923ad74eb8a4b767e70a578d9)
      #06 pc 0000000000014848  /data/app/~~b1IcgZyNV2Qh04rrBKVlYw==/com.app.app-T9kJdSRjZ9WidZfqbsKwiw==/lib/arm64/libmobileffmpeg.so (Java_com_arthenica_mobileffmpeg_Config_nativeFFmpegExecute+412) (BuildId: b57e749e21d9106923ad74eb8a4b767e70a578d9)
      #07 pc 000000000013ced4  /apex/com.android.art/lib64/libart.so (art_quick_generic_jni_trampoline+148) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #08 pc 00000000001337e8  /apex/com.android.art/lib64/libart.so (art_quick_invoke_static_stub+568) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #09 pc 00000000001a8a94  /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+228) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #10 pc 00000000003185c8  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+376) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #11 pc 000000000030e8f4  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+996) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #12 pc 000000000067fbd8  /apex/com.android.art/lib64/libart.so (MterpInvokeStatic+548) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #13 pc 000000000012d994  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_static+20) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #14 pc 00000000002513f8  [anon:dalvik-classes.dex extracted in memory from /data/app/~~b1IcgZyNV2Qh04rrBKVlYw==/com.app.app-T9kJdSRjZ9WidZfqbsKwiw==/base.apk] (com.arthenica.mobileffmpeg.Config.ffmpegExecute+20)
      #15 pc 000000000067fe7c  /apex/com.android.art/lib64/libart.so (MterpInvokeStatic+1224) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #16 pc 000000000012d994  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_static+20) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #17 pc 000000000025204c  [anon:dalvik-classes.dex extracted in memory from /data/app/~~b1IcgZyNV2Qh04rrBKVlYw==/com.app.app-T9kJdSRjZ9WidZfqbsKwiw==/base.apk] (com.arthenica.mobileffmpeg.FFmpeg.execute+4)
      #18 pc 000000000067fe7c  /apex/com.android.art/lib64/libart.so (MterpInvokeStatic+1224) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #19 pc 000000000012d994  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_static+20) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #20 pc 000000000000134e  [anon:dalvik-classes7.dex extracted in memory from /data/app/~~b1IcgZyNV2Qh04rrBKVlYw==/com.app.app-T9kJdSRjZ9WidZfqbsKwiw==/base.apk!classes7.dex] (com.arthenica.flutter.ffmpeg.FlutterFFmpegExecuteFFmpegAsyncArgumentsTask.doInBackground+62)
      #21 pc 000000000067cf20  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+1520) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #22 pc 000000000012d814  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+20) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #23 pc 0000000000001398  [anon:dalvik-classes7.dex extracted in memory from /data/app/~~b1IcgZyNV2Qh04rrBKVlYw==/com.app.app-T9kJdSRjZ9WidZfqbsKwiw==/base.apk!classes7.dex] (com.arthenica.flutter.ffmpeg.FlutterFFmpegExecuteFFmpegAsyncArgumentsTask.doInBackground+4)
      #24 pc 000000000067cf20  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+1520) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #25 pc 000000000012d814  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+20) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #26 pc 000000000035aed0  /system/framework/framework.jar (offset 0x92f000) (android.os.AsyncTask$3.call+40)
      #27 pc 000000000067e958  /apex/com.android.art/lib64/libart.so (MterpInvokeInterface+1808) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #28 pc 000000000012da14  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_interface+20) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #29 pc 00000000001f0b06  /apex/com.android.art/javalib/core-oj.jar (java.util.concurrent.FutureTask.run+62)
      #30 pc 000000000067e958  /apex/com.android.art/lib64/libart.so (MterpInvokeInterface+1808) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #31 pc 000000000012da14  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_interface+20) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #32 pc 00000000001fb956  /apex/com.android.art/javalib/core-oj.jar (java.util.concurrent.ThreadPoolExecutor.runWorker+158)
      #33 pc 000000000067cf20  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+1520) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #34 pc 000000000012d814  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+20) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #35 pc 00000000001fa718  /apex/com.android.art/javalib/core-oj.jar (java.util.concurrent.ThreadPoolExecutor$Worker.run+4)
      #36 pc 000000000067e958  /apex/com.android.art/lib64/libart.so (MterpInvokeInterface+1808) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #37 pc 000000000012da14  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_interface+20) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #38 pc 00000000000ed090  /apex/com.android.art/javalib/core-oj.jar (java.lang.Thread.run+8)
      #39 pc 0000000000305ef0  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.7972480776628613073)+268) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #40 pc 000000000066b988  /apex/com.android.art/lib64/libart.so (artQuickToInterpreterBridge+780) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #41 pc 000000000013cff8  /apex/com.android.art/lib64/libart.so (art_quick_to_interpreter_bridge+88) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #42 pc 0000000000133564  /apex/com.android.art/lib64/libart.so (art_quick_invoke_stub+548) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #43 pc 00000000001a8a78  /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+200) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #44 pc 0000000000555364  /apex/com.android.art/lib64/libart.so (art::JValue art::InvokeVirtualOrInterfaceWithJValues<art::ArtMethod*>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, art::ArtMethod*, jvalue const*)+460) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #45 pc 00000000005a4714  /apex/com.android.art/lib64/libart.so (art::Thread::CreateCallback(void*)+1308) (BuildId: 3d7f69313944ac28951104ab465e9cda)
      #46 pc 00000000000b0048  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+64) (BuildId: 177ced94c8a288368e00f7f6d454f607)
      #47 pc 00000000000503c8  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: 177ced94c8a288368e00f7f6d454f607)

Environment

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.0.6, on Microsoft Windows [Version 10.0.19042.964], locale en-GB)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] VS Code (version 1.56.0)
[√] Connected device (2 available)

• No issues found!

Any help is highly appreciated. Thanks.

tanersener commented 3 years ago

I see that native calls trigger a cleanup routine and that routine fails with SIGABRT. I don't see why that routine is called in the stack trace. Can you explain which flutter_ffmpeg calls are made by your app? Is this case reproducible, can you list the steps to reproduce it?

Gicminos commented 3 years ago

I see that native calls trigger a cleanup routine and that routine fails with SIGABRT. I don't see why that routine is called in the stack trace. Can you explain which flutter_ffmpeg calls are made by your app? Is this case reproducible, can you list the steps to reproduce it?

Thank you for your quick reply. It was not easy to determine the command causing the crash but I am quite sure that it is getMediaInformation from FlutterFFprobe.

This is the code where I use it:

final FlutterFFprobe flutterFFprobe = FlutterFFprobe();
MediaInformation mediaInformation = await flutterFFprobe.getMediaInformation(this.path);
Map<dynamic, dynamic> mp = mediaInformation.getAllProperties();

It is worth to mention that sometimes this method returns null and in that case I run it again. Usually a second run retrieves the correct data but it seems that sometimes it causes this crash.

I am not sure how to trustly reproduce it because as said sometimes it happens and sometimes it doesn't. I could not figure yet exact steps to make it happen at the first shot.

tanersener commented 3 years ago

getMediaInformation method of FlutterFFprobe is a utility method which parses ffprobe output. If the output is not complete or not in the right format it returns null. In these situations logcat in Android includes a stack trace that explains why parsing failed. I suggest looking at it.

The stack trace in your first post shows that the crash happens during an ffmpeg call, not ffprobe. getMediaInformation is not to blame there.

com.app.app-T9kJdSRjZ9WidZfqbsKwiw==/lib/arm64/libmobileffmpeg.so (exit_program+32) (BuildId: b57e749e21d9106923ad74eb8a4b767e70a578d9)
com.app.app-T9kJdSRjZ9WidZfqbsKwiw==/lib/arm64/libmobileffmpeg.so (ffmpeg_execute+10848) (BuildId: b57e749e21d9106923ad74eb8a4b767e70a578d9)
com.app.app-T9kJdSRjZ9WidZfqbsKwiw==/lib/arm64/libmobileffmpeg.so (Java_com_arthenica_mobileffmpeg_Config_nativeFFmpegExecute+412) (BuildId: b57e749e21d9106923ad74eb8a4b767e70a578d9)
Gicminos commented 3 years ago

Ah, sorry about that!

This is the ffmpeg execute called before that:

await _flutterFFmpeg.execute('-i input.mp4 -codec:v libx264 -vf transpose=2 -s 480x720 -r 30 output.mp4');

Here is the full log of the execution.

I thought that the problem was not here because looking at the logs it seemed that the video gets processed successfully. As you mentioned that it happens during a cleanup, maybe it is when it tries to free memory? Thanks.

tanersener commented 3 years ago

Logs show that this issue happens when you run multiple commands at the same time. One ffmpeg execute and one getMediaInformation. Do you have the same crash when you are not doing that? When each command runs after the previous one is completed.

Gicminos commented 3 years ago

Yes, the situation seems better now!

I have then received a different memory error but I think that is not related with this package but with image_picker.

If you could allow me a couple of more days before closing the issue, I will test it more throughly to make sure that it is completely solved, and then close this myself.

Happy to provide any more details in case it could help somebody else. Thanks!

Gicminos commented 3 years ago

Hi, so far so good. Currently experiencing a different memory error but I believe it to not be related and currently being discussed in the issue #83090 on the main flutter repo.

Thanks for your help, I will close for now and re-open in case the error pops up again!