Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library not usable inside a Flutter dart isolate #263

Closed
One-djey opened this issue Dec 2, 2021 · 10 comments
Closed

Library not usable inside a Flutter dart isolate #263

One-djey opened this issue Dec 2, 2021 · 10 comments
Labels
flutter Affect flutter platform no-issue-activity question Further information is requested v4.5 Affects v4.5 release

Comments

@One-djey
Copy link

One-djey commented Dec 2, 2021

Description
I can't use the flutter library inside an isolate.
Any operation using FFmpegKit, FFprobeKit or FFmpegKitConfig fails.

Expected behavior
ffmpeg_kit_flutter should be usable outside the main thread: inside any isolate.

Current behavior
While trying to FFmpegKit.executeWithArgumentsAsync([...]) an unhandled exception is thrown:
E/flutter (25355): Null check operator used on a null value

To Reproduce
Implement this great tutorial about Isolates in dart
Then try any FFmpeg execution with FFmpegKit.executeWithArgumentsAsync inside the myIsolate function of the tutorial.

Screenshots
NA

Logs

E/flutter (25355): [ERROR:flutter/runtime/dart_isolate.cc(1137)] Unhandled exception:
E/flutter (25355): Null check operator used on a null value
E/flutter (25355): #0      EventChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:512:86)
E/flutter (25355): #1      EventChannel.receiveBroadcastStream.<anonymous closure> (package:flutter/src/services/platform_channel.dart:532:7)
E/flutter (25355): #2      EventChannel.receiveBroadcastStream.<anonymous closure> (package:flutter/src/services/platform_channel.dart:531:64)
E/flutter (25355): #3      _runGuarded (dart:async/stream_controller.dart:773:24)
E/flutter (25355): #4      _BroadcastStreamController._subscribe (dart:async/broadcast_stream_controller.dart:207:7)
E/flutter (25355): #5      _ControllerStream._createSubscription (dart:async/stream_controller.dart:786:19)
E/flutter (25355): #6      _StreamImpl.listen (dart:async/stream_impl.dart:473:9)
E/flutter (25355): #7      FFmpegKitInitializer._initialize (package:ffmpeg_kit_flutter/src/ffmpeg_kit_flutter_initializer.dart:256:44)
E/flutter (25355): #8      FFmpegKitInitializer.initialize (package:ffmpeg_kit_flutter/src/ffmpeg_kit_flutter_initializer.dart:50:23)
E/flutter (25355): #9      FFmpegKitConfig.init (package:ffmpeg_kit_flutter/ffmpeg_kit_config.dart:48:32)
E/flutter (25355): #10     AbstractSession.createFFmpegSession (package:ffmpeg_kit_flutter/abstract_session.dart:70:29)
E/flutter (25355): #11     FFmpegSession.create (package:ffmpeg_kit_flutter/ffmpeg_session.dart:40:43)
E/flutter (25355): #12     FFmpegKit.executeWithArgumentsAsync (package:ffmpeg_kit_flutter/ffmpeg_kit.dart:51:41)
E/flutter (25355): #13     myIsolate.<anonymous closure> (package:my_app/main.dart:157:45)
E/flutter (25355): <asynchronous suspension>

Environment

  • Platform: Flutter on Android
  • Architecture: arm64-v8a (Pixel 4A 5G)
  • Version ffmpeg_kit_flutter 4.5.0
  • Android Studio version 4.1.3
  • Android NDK version 23.1.7779620

Other
A StackOverflow question has been asked for this same error on another domain. It might help for the resolution.

@tanersener
Copy link
Collaborator

As far as I remember, this is a limitation coming from flutter, not something we ignored. Other plugins that use platform channels also suffer from it. See flutter issue #13937.

@tanersener tanersener added flutter Affect flutter platform v4.5 Affects v4.5 release question Further information is requested labels Dec 3, 2021
@One-djey
Copy link
Author

One-djey commented Dec 3, 2021

As recommended by one of the comments in the Flutter's issue @tanersener mentioned, I will try to use isolate_handler and come back to you, if it's working.

@One-djey
Copy link
Author

One-djey commented Dec 4, 2021

After having tuned many things in my code and migrated to isolate_handler, I have another issue, but which seems closely related to the previous one:

I/flutter (20344): Loading ffmpeg-kit-flutter.
I/flutter (20344): [Isolate] ERROR: MissingPluginException(No implementation found for method getLogLevel on channel flutter.arthenica.com/ffmpeg_kit)
I/flutter (20344): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:7)
I/flutter (20344): #1      FFmpegKitInitializer._initialize (package:ffmpeg_kit_flutter_audio/src/ffmpeg_kit_flutter_initializer.dart:258:22)
I/flutter (20344): #2      FFmpegKitInitializer.initialize (package:ffmpeg_kit_flutter_audio/src/ffmpeg_kit_flutter_initializer.dart:50:7)
I/flutter (20344): #3      FFmpegKitConfig.init (package:ffmpeg_kit_flutter_audio/ffmpeg_kit_config.dart:48:5)
I/flutter (20344): #4      AbstractSession.createFFmpegSession (package:ffmpeg_kit_flutter_audio/abstract_session.dart:70:7)
I/flutter (20344): #5      FFmpegSession.create (package:ffmpeg_kit_flutter_audio/ffmpeg_session.dart:40:21)
I/flutter (20344): #6      FFmpegKit.executeWithArgumentsAsync (package:ffmpeg_kit_flutter_audio/ffmpeg_kit.dart:51:21)
I/flutter (20344): <asynchronous suspension>


======== Exception caught by services library ======================================================
The following MissingPluginException was thrown while activating platform stream on channel flutter.arthenica.com/ffmpeg_kit_event:
MissingPluginException(No implementation found for method listen on channel flutter.arthenica.com/ffmpeg_kit_event)

When the exception was thrown, this was the stack: 
#0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:7)
#1      EventChannel.receiveBroadcastStream.<anonymous closure> (package:flutter/src/services/platform_channel.dart:545:9)
====================================================================================================

I'm not sure @tanersener can fix it.
I am disappointed by this beautiful speech:

[isolate_handler] use a mechanism called platform channel to communicate between the Dart and the native sides, a message passing mechanism using the MethodChannel type. This mechanism depends on elements of the underlying UI engine to function. Standard isolates don't have that underlying engine because it's not something they normally need but this means that any call to a plugin (eg. to something as simple as path_provider) will fail.

Even with that, the ffmpeg_kit_flutter doesn't work inside an isolate.

@One-djey
Copy link
Author

One-djey commented Dec 9, 2021

@tanersener do you have any workaround?

@tanersener
Copy link
Collaborator

No, I don't know how to overcome this.

@github-actions
Copy link

github-actions bot commented Feb 9, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@mpcreza
Copy link

mpcreza commented Feb 26, 2022

Hi @tanersener , i get same error when use with flutter_background_service. this plugin work with other plugins if no requires UI, i don't understand why ffmpeg needs UI.

Error:

ERROR: MissingPluginException(No implementation found for method getLogLevel on channel flutter.arthenica.com/ffmpeg_kit)

ERROR:flutter/lib/ui/ui_dart_state.cc

I also tested with old flutter_ffmpeg plugin and it worked.

@tanersener
Copy link
Collaborator

@mpcreza ffmpeg-kit is not the renamed version of flutter_ffmpeg. There are big changes under the hood. The main difference is ffmpeg-kit is a federated plugin, flutter_ffmpeg is not. In ffmpeg-kit we also followed the best practices from official flutter plugins. So, they are quite different.

I don't know what is the issue with flutter_background_service, those two lines doesn't tell me much. I suggest creating a separate issue and filling out issue template fields if you need assistance about that.

@mpcreza
Copy link

mpcreza commented Mar 2, 2022

@tanersener you're right.
If I create a new issue, it will be very similar to this issue, because the problem I have with the flutter_background_service is related to isolate. now should I create a new issues or explain more here?

@tanersener
Copy link
Collaborator

@mpcreza If your stack trace is identical to the one given in the first post then you have the same problem. You can add the details here. But we don't have a solution or workaround for isolates yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flutter Affect flutter platform no-issue-activity question Further information is requested v4.5 Affects v4.5 release
Projects
None yet
Development

No branches or pull requests

3 participants