【问题标题】:Capture frames from a canvas at 60 fps以 60 fps 从画布捕获帧
【发布时间】:2020-07-12 06:21:22
【问题描述】:

大家好,所以我有一个画布,我可以在上面写一个相当复杂的动画。假设我想以每秒 60 帧的速度截取画布的屏幕截图。画布不必实时播放,我只需要每秒捕获 60 帧,这样我就可以将屏幕截图发送到 FFmpeg 并制作视频。我知道我可以使用canvas.toDataURL,但是如何顺利捕获帧?

【问题讨论】:

    标签: html5-canvas frame-rate todataurl


    【解决方案1】:

    如果您将 lottie-web 用于浏览器中的后期效果内容,请使用此代码暂停视频和 lottie 动画。比截屏并使用 Whammy 编译一个 webm 文件,然后您可以通过 ffmpeg 运行该文件以获得所需的输出。

      generateVideo(){
                const vid = new Whammy.fromImageArray(this.captures, 30);
                vid.name = "project_id_238.webm";
                vid.lastModifiedDate = new Date();
    
                this.file = URL.createObjectURL(vid);
        },
        async pauseAll(){
           this.pauseVideo();
          if(this.animations.length){
           this.pauseLotties()
          }
                this.captures.push(this.canvas.toDataURL('image/webp'));
                if(!this.ended){
                  setTimeout(()=>{
                    this.pauseAll();
                  }, 500);
                } 
        },
        async pauseVideo(){
          console.log("curretTime",this.video.currentTime);
          console.log("duration", this.video.duration);
            this.video.pause();
           const oneFrame = 1/30;
          this.video.currentTime += oneFrame;
        },
        async pauseLotties(){
          lottie.freeze();
            for(let i =0; i<this.animations.length; i++){
              let step =0;
              let animation = this.animations[i].lottie;
              if(animation.currentFrame<=animation.totalFrames){
                step = animation.currentFrame + animation.totalFrames/30;
              }
              lottie.goToAndStop(step, true, animation.name); 
            }
          }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-04
      • 1970-01-01
      • 1970-01-01
      • 2013-02-12
      • 1970-01-01
      • 2020-11-22
      • 2022-12-18
      相关资源
      最近更新 更多