-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[mob][photos] run ffmpeg in isolate #5743
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
Conversation
| import "package:ffmpeg_kit_flutter/ffmpeg_kit.dart"; | ||
| import "package:ffmpeg_kit_flutter/ffmpeg_session.dart"; | ||
|
|
||
| class IsolatedFfmpegService { | ||
| static Future<FFmpegSession> ffmpegRun(Map args) async { | ||
| final command = args['command'] as String; | ||
|
|
||
| final session = await FFmpegKit.execute(command); | ||
|
|
||
| return session; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using shared computer/isolate, let's use a dedicated computer instance for ffmpeg so that it doesn't block one of the shared computer for long time.
Also, we can simplify the call by adding a helper method.
class IsolatedFfmpegService {
final Computer _computer = Computer.create();
void init() {
_computer.turnOn(workersCount: 1);
}
Future<FFmpegSession> runFfmpeg(String command) async {
return _computer.compute<Map, FFmpegSession>(
_ffmpegRun,
param: {'command': command},
);
}
static Future<FFmpegSession> _ffmpegRun(Map args) async {
final command = args['command'] as String;
final session = await FFmpegKit.execute(command);
return session;
}
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to init ffmpeg inside that isolate/worker, that can either work with this computer with single worker that will ensure that the ffmpeg is initialized in that isolate or start another isolate and manage it ourself similar to MLComputer
mobile/lib/main.dart
Outdated
| Computer.shared().turnOn(workersCount: 4).ignore(); | ||
| CryptoUtil.init(); | ||
|
|
||
| IsolatedFfmpegService.init(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's init it right before processing any video to avoid creating redundant isolate.
|
|
||
| // Fetch resolution of generated stream by decrypting a single frame | ||
| final FFmpegSession session2 = await FFmpegKit.execute( | ||
| final map2 = await IsolatedFfmpegService.runFfmpeg( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should. we rename this?
Description
Tests