targetSubtitleFromVideo static method
Gets a list of subtitles from a video file.
Implementation
static Future<SubtitleItem?> targetSubtitleFromVideo({
required File file,
required Language language,
required Function(SubtitleItem) onItemComplete,
}) async {
Directory appDocDir = await getApplicationDocumentsDirectory();
Directory subsDir = Directory('${appDocDir.path}/targetSubtitles');
if (!subsDir.existsSync()) {
subsDir.createSync(recursive: true);
}
String inputPath = file.path;
String threeLanguageCode = language.threeLetterCode;
String outputPath = '${subsDir.path}/extractSrt.srt';
String command =
'-loglevel quiet -i "$inputPath" -map 0:m:language:$threeLanguageCode -map -0:a -map -0:v "$outputPath"';
File outputFile = File(outputPath);
if (outputFile.existsSync()) {
outputFile.deleteSync();
}
final FlutterFFmpeg _flutterFFmpeg = FlutterFFmpeg();
await _flutterFFmpeg.execute(command);
await Future.delayed(const Duration(seconds: 1));
if (outputFile.existsSync()) {
SubtitleItem item = await subtitlesFromFile(
file: outputFile,
type: SubtitleItemType.embeddedSubtitle,
);
onItemComplete(item);
return item;
} else {
return null;
}
}