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

Migrate from flutter_ffmpeg to ffmpeg-kit #446

Merged
merged 2 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions yuuna/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,3 @@ subprojects {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}

ext {
flutterFFmpegPackage = "full-gpl-lts"
}
12 changes: 5 additions & 7 deletions yuuna/lib/src/media/source_types/player_media_source.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'dart:async';
import 'dart:io';

import 'package:ffmpeg_kit_flutter/ffmpeg_session.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_ffmpeg/flutter_ffmpeg.dart';
import 'package:ffmpeg_kit_flutter/ffmpeg_kit.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_vlc_player/flutter_vlc_player.dart';
import 'package:fluttertoast/fluttertoast.dart';
Expand Down Expand Up @@ -170,10 +171,8 @@ abstract class PlayerMediaSource extends MediaSource {
String command =
'-ss $timestamp -y -i "$inputPath" -frames:v 1 -q:v 2 "$outputPath"';

final FlutterFFmpeg flutterFFmpeg = FlutterFFmpeg();
await flutterFFmpeg.execute(command);

String output = await FlutterFFmpegConfig().getLastCommandOutput();
FFmpegSession session = await FFmpegKit.execute(command);
String output = await session.getOutput() ?? '';

if (!output.contains('Output file is empty, nothing was encoded')) {
while (!imageFile.existsSync()) {
Expand Down Expand Up @@ -263,8 +262,7 @@ abstract class PlayerMediaSource extends MediaSource {
String command =
'-ss $timeStart -to $timeEnd -y -i "$inputPath" -map 0:a:$audioIndex "$outputPath"';

final FlutterFFmpeg flutterFFmpeg = FlutterFFmpeg();
await flutterFFmpeg.execute(command);
await FFmpegKit.execute(command);

return audioFile;
}
Expand Down
10 changes: 5 additions & 5 deletions yuuna/lib/src/media/sources/player_local_media_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import 'dart:async';
import 'dart:io';

import 'package:collection/collection.dart';
import 'package:ffmpeg_kit_flutter/ffmpeg_kit.dart';
import 'package:flutter/material.dart';
import 'package:flutter_ffmpeg/flutter_ffmpeg.dart';
import 'package:ffmpeg_kit_flutter/ffmpeg_session.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_vlc_player/flutter_vlc_player.dart';
import 'package:material_floating_search_bar/material_floating_search_bar.dart';
Expand Down Expand Up @@ -99,21 +100,20 @@ class PlayerLocalMediaSource extends PlayerMediaSource {
Future<void> generateThumbnail(String inputPath, String targetPath) async {
String timestamp =
JidoujishoTimeFormat.getFfmpegTimestamp(const Duration(seconds: 30));
final FlutterFFmpeg flutterFFmpeg = FlutterFFmpeg();

String command =
'-ss $timestamp -y -i "$inputPath" -frames:v 1 -q:v 2 "$targetPath"';

await flutterFFmpeg.execute(command);
String output = await FlutterFFmpegConfig().getLastCommandOutput();
FFmpegSession session = await FFmpegKit.execute(command);
String output = await session.getOutput() ?? '';

if (output.contains('Output file is empty, nothing was encoded')) {
String timestamp =
JidoujishoTimeFormat.getFfmpegTimestamp(const Duration(seconds: 1));

String command =
'-ss $timestamp -y -i "$inputPath" -frames:v 1 -q:v 2 "$targetPath"';
await flutterFFmpeg.execute(command);
await FFmpegKit.execute(command);
}
}

Expand Down
18 changes: 6 additions & 12 deletions yuuna/lib/src/utils/player/subtitle_utils.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';

import 'package:flutter_ffmpeg/flutter_ffmpeg.dart';
import 'package:ffmpeg_kit_flutter/ffmpeg_kit.dart';
import 'package:ffmpeg_kit_flutter/ffmpeg_session.dart';
import 'package:path_provider/path_provider.dart';
import 'package:subtitle/subtitle.dart';
import 'package:path/path.dart' as path;
Expand Down Expand Up @@ -139,9 +140,7 @@ class SubtitleUtils {
outputFile.deleteSync();
}

final FlutterFFmpeg flutterFFmpeg = FlutterFFmpeg();

await flutterFFmpeg.execute(command);
await FFmpegKit.execute(command);

await Future.delayed(const Duration(seconds: 1));

Expand Down Expand Up @@ -185,11 +184,8 @@ class SubtitleUtils {
outputFile.deleteSync();
}

final FlutterFFmpeg flutterFFmpeg = FlutterFFmpeg();
final FlutterFFmpegConfig flutterFFmpegConfig = FlutterFFmpegConfig();

await flutterFFmpeg.execute(command);
String output = await flutterFFmpegConfig.getLastCommandOutput();
FFmpegSession session = await FFmpegKit.execute(command);
String output = await session.getOutput() ?? '';
if (output.contains("Stream map '0:s:$i' matches no streams.")) {
break;
}
Expand Down Expand Up @@ -227,9 +223,7 @@ class SubtitleUtils {

String command = '-i "$inputPath" "$outputPath"';

final FlutterFFmpeg flutterFFmpeg = FlutterFFmpeg();

await flutterFFmpeg.execute(command);
await FFmpegKit.execute(command);

return targetFile.readAsStringSync();
}
Expand Down
24 changes: 16 additions & 8 deletions yuuna/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.2"
ffmpeg_kit_flutter:
dependency: "direct main"
description:
name: ffmpeg_kit_flutter
sha256: b7c874eeffd2c554d636a84a9fbdfe34a99a5862ad636d4779b4b7f56060d728
url: "https://pub.dev"
source: hosted
version: "6.0.3-LTS"
ffmpeg_kit_flutter_platform_interface:
dependency: transitive
description:
name: ffmpeg_kit_flutter_platform_interface
sha256: addf046ae44e190ad0101b2fde2ad909a3cd08a2a109f6106d2f7048b7abedee
url: "https://pub.dev"
source: hosted
version: "0.2.1"
file:
dependency: transitive
description:
Expand Down Expand Up @@ -616,14 +632,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.2"
flutter_ffmpeg:
dependency: "direct main"
description:
name: flutter_ffmpeg
sha256: "8d8bb4551cf76384748ba6948739c1e56a9164794e48f06cbfb0ff1bfb058b5f"
url: "https://pub.dev"
source: hosted
version: "0.4.2"
flutter_gpt_tokenizer:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion yuuna/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies:
external_app_launcher: ^3.1.0
external_path: ^1.0.1
favicon: ^1.1.1
ffmpeg_kit_flutter: 6.0.3-LTS
file_picker: ^5.3.0
filesystem_picker:
git:
Expand All @@ -47,7 +48,6 @@ dependencies:
flutter_charset_detector: ^1.0.2
flutter_colorpicker: ^1.0.3
flutter_exit_app: ^1.0.5
flutter_ffmpeg: ^0.4.2
flutter_gpt_tokenizer: ^0.1.0
flutter_html: ^3.0.0-beta.2
flutter_html_table: ^3.0.0-beta.2
Expand Down
Loading