如何在颤振中制作视频缩略图?

Yuv*_*sai 7 dart flutter

我有一个 flutter 应用程序,它显示内部存储中的视频文件列表......现在我想在视频列表中显示视频的缩略图,那么我该如何在我的 flutter 应用程序中执行此操作?如果有人有任何想法,请帮助我。

我正在使用 ListBuilder 小部件。

Hus*_*dar 16

为他人。使用视频播放器插件作为缩略图。这些库非常有效,也适用于 ios。只需像项目一样创建 statefullWidget(如果你想在列表中显示,使用该小部件作为项目)。见下面的例子。

class _VideoItemState extends State<VideoItem> {
VideoPlayerController _controller;

@override
void initState() {
super.initState();
_controller = VideoPlayerController.network(widget.video.file.path)
  ..initialize().then((_) {
    setState(() {});  //when your thumbnail will show.
  });
}

@override
void dispose() {
super.dispose();
_controller.dispose();
}

@override
Widget build(BuildContext context) {
return ListTile(
  leading: _controller.value.initialized
      ? Container(
          width: 100.0,
          height: 56.0,
          child: VideoPlayer(_controller),
        )
      : CircularProgressIndicator(),
  title: Text(widget.video.file.path.split('/').last),
  onTap: () {
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) =>
            VideoPlayerPage(videoUrl: widget.video.file.path),
      ),
    );
  },
);
 }
}
Run Code Online (Sandbox Code Playgroud)

  • 我认为它会显示单个视频的缩略图,那么视频网址列表呢 (2认同)

olu*_*ide 11

You can use the video_thumbnail plugin too, like so:

For a video file:

final uint8list = await VideoThumbnail.thumbnailData(
  video: videofile.path,
  imageFormat: ImageFormat.JPEG,
  maxWidth: 128, // specify the width of the thumbnail, let the height auto-scaled to keep the source aspect ratio
  quality: 25,
);
Run Code Online (Sandbox Code Playgroud)

OR from a video URL:

final uint8list = await VideoThumbnail.thumbnailFile(
  video: "https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4",
  thumbnailPath: (await getTemporaryDirectory()).path,
  imageFormat: ImageFormat.WEBP,
  maxHeight: 64, // specify the height of the thumbnail, let the width auto-scaled to keep the source aspect ratio
  quality: 75,
);
Run Code Online (Sandbox Code Playgroud)