flutter - 将视频捕获到 Canvas 抖动

标签 flutter dart video-capture

我想像在js中的示例一样实现视频到 Canvas 应用程序:http://jsfiddle.net/Ls9kfwot/2/
但是我的问题是如何在特定区域拍摄视频播放器的屏幕截图?
就像drawImage中的js:

ctx.drawImage(sx,sy,swidth,sheight,x,y,width,height); // js drawimage
但是在Flutter中,我可以使用什么将视频复制到 Canvas 上?
我用视频播放器创建了一个简单的flutter项目:
  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: YoYoPlayer(
        aspectRatio: 16 / 9,
        url:
            "http://upload.wikimedia.org/wikipedia/commons/7/79/Big_Buck_Bunny_small.ogv",
        videoStyle: VideoStyle(),
        videoLoadingStyle: VideoLoadingStyle(
          loading: Center(
            child: Text("Loading video"),
            //capture image of video and display it
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
RenderRepaintBoundary和drawImage是解决方案?

最佳答案

是的,RenderRepaintBoundary和drawImage是您想要的。

  GlobalKey _repaintKey = GlobalKey();

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: RenderRepaintBoundary(
        key: _repaintKey,
        child: YoYoPlayer(
          aspectRatio: 16 / 9,
          url:
              "http://upload.wikimedia.org/wikipedia/commons/7/79/Big_Buck_Bunny_small.ogv",
          videoStyle: VideoStyle(),
          videoLoadingStyle: VideoLoadingStyle(
            loading: Center(
              child: Text("Loading video"),
              //capture image of video and display it
            ),
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
final boundary = _repaintKey.context.findRenderObject() as RenderRepaintBoundary;
final image = await boundary.toImage();
canvas.drawImage(image, Offset(10, 20), paint);

关于flutter - 将视频捕获到 Canvas 抖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63955406/

相关文章:

listview - 如果只有少量项目,如何使ListView占用空间来填充屏幕

datetime - 为什么Dart的DateTime对象不使用小于和大于运算符的覆盖方法?

ios - 在 iOS 上制作透明视频

android - Android NDK 的 OpenMAX 可以用于将实时视频/音频流式传输到服务器吗?例子?

dart - 简化迭代逻辑

python - 如何从图像采集卡中抓取帧?

flutter - 如何在屏幕之间传递数据?

dart - 如何在 Flutter 中删除字符串上的点(.)?

android - Flutter 的 'path_provider' 依赖项中的未定义类

performance - Flutter widget 应该在类中创建还是在 build() 函数中创建?