trimVideoAndCompress static method

Future<XFile?> trimVideoAndCompress(
  1. VideoEditorController controller
)

Trim video and compress video

Implementation

static Future<XFile?> trimVideoAndCompress(
    VideoEditorController controller) async {
  final ValueNotifier<double> exportingProgress = ValueNotifier<double>(0.0);
  XFile? video;
  try {
    video = await VideoUtils.exportVideo(
      onStatistics: (FFmpegStatistics stats) {
        print(
            '#FFmpegStatistics# : ${stats.getProgress(controller.trimmedDuration.inMilliseconds)}');
        exportingProgress.value =
            stats.getProgress(controller.trimmedDuration.inMilliseconds);
      },
      // 'vf': f'scale={scale}',
      // 'c:v': 'libx264',
      // 'preset': 'veryfast',
      // 'loglevel': 'error',
      // "crf": 32,
      // "r": 30,
      // 'c:a': 'aac',
      // "threads": 1,
      // "hls_list_size": 5, "hls_time": 5,
      /// -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2"
      /// -vf scale=1280:-2
      preset: VideoExportPreset.ultrafast,
      controller: controller,
      customInstruction:
          '-c:v h264_videotoolbox -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -crf 32 -r 30 -hls_list_size 5 -hls_time 5 -threads 10 ',
    );
  } catch (e) {
    log(e.toString());
  }
  final String date = DateTime.now().millisecondsSinceEpoch.toString();

  await video?.saveTo('${await getCacheDirectory()}/$date.mp4');
  print('#savedTo# : ${await getCacheDirectory()}/$date.mp4');
  final XFile file = XFile('${await getCacheDirectory()}/$date.mp4');
  print('#Print# : ${await file.length()}');
  return video;
}