[ffmpeg] global ffmpeg

This commit is contained in:
jscampucci 2024-07-10 15:12:18 +02:00
parent 90cb99fb18
commit b9c539acb1
2 changed files with 17 additions and 15 deletions

Binary file not shown.

View File

@ -10,7 +10,6 @@ import 'package:path/path.dart' as p;
class ConverterService { class ConverterService {
late Directory tempDir; late Directory tempDir;
late String assetName;
late String ffmpegPath; late String ffmpegPath;
ConverterService._(); ConverterService._();
@ -24,23 +23,26 @@ class ConverterService {
Future<void> _init() async { Future<void> _init() async {
tempDir = await getTemporaryDirectory(); tempDir = await getTemporaryDirectory();
assetName = 'ffmpeg.exe'; if (Platform.isWindows) {
await copyExecutable(); ffmpegPath = 'ffmpeg.exe';
} else if (Platform.isLinux) {
ffmpegPath = 'ffmpeg';
} else if (Platform.isMacOS) {
ffmpegPath = 'ffmpeg';
}
await checkFFmpeg();
} }
Future<void> copyExecutable() async { Future<void> checkFFmpeg() async {
File tempFile = File('${tempDir.path}/$assetName'); try {
var result = await Process.run(ffmpegPath, ['-version']);
ByteData data = await rootBundle.load('assets/executable/$assetName'); if (result.exitCode == 0) {
await tempFile.exists().then((value) { print('FFmpeg is installed.');
if (!value) { return;
debugPrint('Copying $assetName to ${tempFile.path}');
tempFile.writeAsBytes(
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes));
} }
}); } catch (e) {
print('FFmpeg is not installed.');
ffmpegPath = tempFile.path; }
} }
Future<File?> getTmpFile(String filename) async { Future<File?> getTmpFile(String filename) async {