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