Flutter:获取视频的第一帧

问题描述 投票:0回答:3

如何在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.
  }
 });
},
dart flutter flutter-layout
3个回答
-3
投票
String thumb = await Thumbnails.getThumbnail(
    thumbnailFolder:'[FOLDER PATH TO STORE THUMBNAILS]', // creates the specified path if it doesnt exist
    videoFile: '[VIDEO PATH HERE]',
    imageType: ThumbFormat.PNG,
    quality: 30);

/*
* thumbnailFolder property can be omitted if you dont wish to keep the generated thumbails past each usage
*/

0
投票

下面的代码使用video_thumbnail插件,该插件在其文档中显示了对Android和ios的支持

在此处输入代码

Future genThumbnailFile() async{
    final thumbnail = await VideoThumbnail.thumbnailFile(
        video:
        _video.path,
        // thumbnailPath: _tempDir,
        imageFormat: ImageFormat.JPEG,
        //maxHeightOrWidth: 0,
        maxHeight:3,
        maxWidth: 2,
        quality: 10);
    setState(() {
      final file = File(thumbnail);
      filePath = file.path;
    });
  }

然后按如下所示在Image小部件中使用此filePath变量

filePath != null
                      ? Container(
                      width:400,
                      height: 200,
                      child: Image(image: AssetImage(filePath)))
                      : Text('No Floatting Button Click')

-4
投票

我使用发布的thumbnails来实现。

String thumb = await Thumbnails.getThumbnail(
    thumbnailFolder:'[FOLDER PATH TO STORE THUMBNAILS]', // creates the specified path if it doesnt exist
    videoFile: '[VIDEO PATH HERE]',
    imageType: ThumbFormat.PNG,
    quality: 30);

/*
* thumbnailFolder property can be omitted if you dont wish to keep the generated thumbails past each usage
*/
© www.soinside.com 2019 - 2024. All rights reserved.