import 'dart:io'; import 'package:flutter/services.dart'; import 'package:path_provider/path_provider.dart'; import 'package:flutter/foundation.dart'; import 'package:process_run/process_run.dart'; class ConverterService { late Directory tempDir; late String assetName; late String ffmpegPath; ConverterService._(); static Future init() async { debugPrint('Initializing DLServices'); var dlService = ConverterService._(); await dlService._init(); return dlService; } Future _init() async { tempDir = await getTemporaryDirectory(); assetName = 'ffmpeg.exe'; await copyExecutable(); } Future 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)); } }); ffmpegPath = tempFile.path; } Future convertFile(String inputPath, String outputPath) async { debugPrint('Converting $inputPath to $outputPath'); var command = ' -q --flat-playlist -J'; var shellLinesController = ShellLinesController(); var shell = Shell(stdout: shellLinesController.sink); await shell.run(''' $ffmpegPath $command ''').then((result) { debugPrint('Analyse result: ${result}'); }); return shellLinesController.stream; } }