Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@prateekmedia
Copy link
Member

@prateekmedia prateekmedia commented Apr 28, 2025

Description

  • Create a new service to use for FFmpeg in an isolate'ed environment
  • Apply this service wherever we use FFmpeg Kit
  • Make FFMpeg accessible in an isolate (background)

Tests

  • Test FFmpeg intergrations

Comment on lines 1 to 12
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;
}
}
Copy link
Member

@ua741 ua741 Apr 28, 2025

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;
  }
}

Copy link
Member

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

Computer.shared().turnOn(workersCount: 4).ignore();
CryptoUtil.init();

IsolatedFfmpegService.init();
Copy link
Member

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.

@prateekmedia prateekmedia marked this pull request as draft April 30, 2025 13:49
@prateekmedia prateekmedia self-assigned this May 7, 2025
@prateekmedia prateekmedia changed the base branch from main to flutter-upgrade June 16, 2025 11:51
@prateekmedia prateekmedia marked this pull request as ready for review June 16, 2025 11:51
@prateekmedia prateekmedia marked this pull request as draft June 16, 2025 13:47
@prateekmedia prateekmedia marked this pull request as ready for review July 11, 2025 10:41

// Fetch resolution of generated stream by decrypting a single frame
final FFmpegSession session2 = await FFmpegKit.execute(
final map2 = await IsolatedFfmpegService.runFfmpeg(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should. we rename this?

@prateekmedia prateekmedia changed the title [mob] isolated ffmpeg run [mob][photos] run ffmpeg in isolate Aug 12, 2025
@prateekmedia prateekmedia merged commit 9eeb7ef into flutter-upgrade Aug 12, 2025
2 checks passed
@prateekmedia prateekmedia deleted the isolated-ffmpeg branch August 12, 2025 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants