[ffmpeg] global ffmpeg
This commit is contained in:
parent
90cb99fb18
commit
b9c539acb1
Binary file not shown.
|
|
@ -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(
|
} catch (e) {
|
||||||
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes));
|
print('FFmpeg is not installed.');
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
ffmpegPath = tempFile.path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<File?> getTmpFile(String filename) async {
|
Future<File?> getTmpFile(String filename) async {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue