以60 fps从画布捕获帧

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

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

html5-canvas frame-rate todataurl
1个回答
0
投票

如果您将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); 
        }
      }
© www.soinside.com 2019 - 2024. All rights reserved.