saveTrimmedVideo method
Future<void>
saveTrimmedVideo({
- required double startValue,
- required double endValue,
- required dynamic onSave(
- String? path
- OutputType outputType = OutputType.video,
- int fpsGIF = 10,
- int scaleGIF = 480,
- int qualityGIF = 50,
- String videoFolderName = 'Trimmer',
- String? videoFileName,
- StorageDirection? storageDir,
Implementation
Future<void> saveTrimmedVideo({
required double startValue,
required double endValue,
required Function(String? path) onSave,
OutputType outputType = OutputType.video,
int fpsGIF = 10,
int scaleGIF = 480,
int qualityGIF = 50,
String videoFolderName = 'Trimmer',
String? videoFileName,
StorageDirection? storageDir,
}) async {
if (_currentVideoFile == null) {
throw Exception('No video loaded');
}
final path = _currentVideoFile!.path;
final baseName = basenameWithoutExtension(path);
final ext = outputType == OutputType.gif ? '.gif' : extension(path);
final timestamp = DateFormat('yyyyMMdd_HHmmss').format(DateTime.now());
final safeFileName = videoFileName ??
'${baseName}_trimmed_$timestamp'.replaceAll(RegExp(r'\s+'), '_');
final outputDir = await _getStorageDirectory(videoFolderName, storageDir);
final outputPath = '$outputDir$safeFileName$ext';
if (outputType == OutputType.gif) {
final gifPath = await _generateGif(
videoPath: path,
fps: fpsGIF,
width: scaleGIF,
quality: qualityGIF,
start: startValue,
end: endValue,
outputPath: outputPath,
);
onSave(gifPath);
} else {
await _videoTrimmer.loadVideo(path);
final trimmedPath = await _videoTrimmer.trimVideo(
startTimeMs: startValue.toInt(),
endTimeMs: endValue.toInt(),
);
if (trimmedPath == null) {
throw Exception('Video trimming failed.');
}
final savedPath = await File(trimmedPath).copy(outputPath);
onSave(savedPath.path);
}
}