Flutter项目中如何获取本地视频文件的第一帧?
这是我的代码:
ImagePicker.pickVideo(source: ImageSource.camera).then((File file) {
if (file != null && mounted) {
//I got the video file here, but I want to get the first frame of the video.
}
});
},
首先,从文件对象获取文件路径并将其传递给以下使用的方法视频缩略图 https://pub.dev/packages/video_thumbnail用于生成缩略图的lib
Future<File> genThumbnailFile(String path) async {
final fileName = await VideoThumbnail.thumbnailFile(
video: path,
thumbnailPath: (await getTemporaryDirectory()).path,
imageFormat: ImageFormat.PNG,
maxHeight: 100, // specify the height of the thumbnail, let the width auto-scaled to keep the source aspect ratio
quality: 75,
);
File file = File(fileName);
return file;
}
其次,要使用它,您需要使用另一个方法接收 File 对象await
打电话,然后做setState()
更新文件。
File file = await genThumbnailFile(filePath);
setState(() {});
最后,使用类似的文件
Image.file(file, fit: BoxFit.cover,)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)