npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

video-capture

v1.0.2

Published

基于h5 canvas的视频快照插件

Downloads

187

Readme

效果图

1.安装

  • <script>标签引入"dist/video-capture.js"或"dist/video-capture.min.js"
  • 使用npm,运行命令:npm install -D video-capture

2.例子

  • npm使用
import VideoCapture from 'video-capture'

async test(){
    //dataURL 捕获画面的base64
    //width画面宽
    //height画面高
    let { dataURL, width, height } = await new VideoCapture("https://vjs.zencdn.net/v/oceans.mp4").capture("10%");

    document.getElementById("imgId").src = dataURL;
}

test();
  • 使用远程视频地址
<!DOCTYPE html>
<html>
    <head>
        ...
    </head>
    <body>
        <img id="preview1" />
        <img id="preview2" />
        <img id="preview3" />
        <script src="../dist/video-capture.min.js"></script>
        <script>
            //方法1、捕获20s处的画面,并使用preview1显示出来
            new VideoCapture("https://vjs.zencdn.net/v/oceans.mp4").capture(20, "preview1");
            //方法2、捕获20s处的画面,传入img dom
            new VideoCapture("https://vjs.zencdn.net/v/oceans.mp4").capture(20, document.getElementById("preview2"));
            //方法3、捕获50%处画面
            new VideoCapture("https://vjs.zencdn.net/v/oceans.mp4").capture("50%", "preview3"));

        </script>
    </body>
</html>
  • 使用本地视频资源
<!DOCTYPE html>
<html>
    <head>
        ...
    </head>
    <body>
        <input id="inputFile" type="file"/>
        <img id="preview"/>
        <script src="../dist/video-capture.min.js"></script>
        <script>
            document.getElementById("inputFile").onchange = function ({ target }) {
                let [file] = target.files;
                if (!/.*\.mp4$/.test(file.name)) alert("请选择mp4视频文件");
                new VideoCapture(file).capture("50%", "preview");
            }
        </script>
    </body>
</html>

3.方法&参数

3.1 构造方法 VideoCapture(uri)

  • uri:可以是一个远程视频链接,也可以是一个本地视频文件对象

3.2 capture(time,img)方法

  • time:指定时间,可以是秒数,如10,也可以是以%结尾的百分数,如'50%'
  • img:可以是img标签的id,或img对象,如果有指定,那么会将捕获的画面dataURL赋值给img.src

3.3 revoke() 方法

当构造方法传入的是一个本地视频资源时,在有必要的时候,可以调用revoke方法来释放资源。