compressVideo static method
Compress video
Implementation
static Future<XFile?> compressVideo(XFile file) async {
final VideoEditorController controller = VideoEditorController.file(file);
await controller.initialize();
final ValueNotifier<double> exportingProgress = ValueNotifier<double>(0.0);
XFile? video;
try {
video = await VideoUtils.exportVideo(
onStatistics: (FFmpegStatistics stats) {
exportingProgress.value = stats.getProgress(controller.trimmedDuration.inMilliseconds);
},
preset: VideoExportPreset.superfast,
customInstruction:
'-vf "scale=720:-2" -b:v 3000k -r 30 -hls_list_size 5 -hls_time 5 -threads 5 ',
controller: controller,
);
} catch (e) {
log(e.toString());
}
await video
?.saveTo('${await getCacheDirectory()}/${DateTime.now().millisecondsSinceEpoch}.mp4');
return video;
}