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

baidu-mct-video-compare

v1.2.0

Published

A video's quality compare player, support side-by-side/top-and-bottom/single-step mode. Author:[email protected]/[email protected]

Downloads

23

Readme

baidu-mct-video-compare

A Web Player for video quality compare

  • baidu

  • HomePage: https://cloud.baidu.com/product/mct.html

Features

  • Support side-by-side mode

  • Support single-step mode (split two videos)

  • Support frame capture

Use

Install by npm

# https://www.npmjs.com/package/baidu-mct-video-compare
npm i baidu-mct-video-compare

Import and use it

API

    1. Create Player
    • single-step mode

      /**
       * single-step-hori
       */
      let player = VideoCompareModule.initPlayer({
          type : "single-step-hori",
          containerId : "compare-player",
          width : "1000px", // or 1000px
          height : "auto"
      });
    • side-by-side mode

      /**
       * single-step-hori
       */
       let player = VideoCompareModule.initPlayer({
           type : "side-by-side",
           containerId : "compare-player",
           width : "1000px", // or 1000px
           height : "auto",
           mode : "waterfall"
           // mode : "line"
       });
    1. Bind listener
    • bind player's event listener
      • onReady: get duration
        player.onReady = (e) => {
            console.log(e);
            // todo
        };
      • onTimeUpdate: get play timestamp
        player.onTimeUpdate = (e) => {
            console.log("onTimeUpdate:" + e);
            // todo
        };
    1. play control
    • operations API
      // play
      global.play = () => {
          player.play();
      };
      
      // pause
      global.pause = () => {
          player.pause();
      };
      
      // seek to 5sec
      global.seek5 = () => {
          player.seek(5);
      };
      
      // capture frame, get canvas objects
      global.capture = () => {
          console.log(captureArea);
          captureArea.innerHTML = "";
          let captureData = player.capture();
          console.log("captureData:", captureData);
          captureData.forEach((item, i) => {
              captureArea.appendChild(item);
          });
      };
      
    1. run Player
    player.do([
        "http://test-bucket.bj-bos-sandbox.baidu-int.com/1080p10s.mp4",
        "http://test-bucket.bj-bos-sandbox.baidu-int.com/1080p10s_9k.mp4"
    ]);

Example Demo:

  • Js
import VideoCompareModule from '@baidu/baidu-mct-video-compare';

// let width = 0;
// let height = 0;
let duration = 0;
let playProgress = document.querySelector("progress#play-progress");
let playPtsLabel = document.querySelector("span#play-pts");
let captureArea = document.querySelector("div#capture-area");
console.log("captureArea:", captureArea);

/**
 * single-step-hori
 */
let player = newMCTWebComparePlayer({
    type : "single-step-hori",
    containerId : "compare-player",
    width : "1000px", // or 1000px
    height : "auto"
});

/**
 * side by side
 */
// let player = newMCTWebComparePlayer({
//     type : "side-by-side",
//     containerId : "compare-player",
//     width : "1000px", // or 1000px
//     height : "auto",
//     mode : "waterfall"
//     // mode : "line"
// });


player.do([
    "http://test-bucket.bj-bos-sandbox.baidu-int.com/1080p10s.mp4",
    "http://test-bucket.bj-bos-sandbox.baidu-int.com/1080p10s_9k.mp4"
]);

player.onReady = (e) => {
    console.log(e);
    duration = e.duration;
    playPtsLabel.textContent = "0 / " + e.duration;
    playProgress.max = e.duration;
    playProgress.addEventListener('click', (e) => {
        let x = e.pageX - playProgress.offsetLeft; // or e.offsetX (less support, though)
        let y = e.pageY - playProgress.offsetTop;  // or e.offsetY
        let clickedValue = x * playProgress.max / playProgress.offsetWidth;
        player.seek(clickedValue);
    });
};

player.onTimeUpdate = (e) => {
    console.log("onTimeUpdate:" + e);
    playPtsLabel.textContent = e + " / " + duration;
    playProgress.value = e;
};

global.play = () => {
    player.play();
};

global.pause = () => {
    player.pause();
};

global.seek5 = () => {
    player.seek(5);
};

global.capture = () => {
    console.log(captureArea);
    captureArea.innerHTML = "";
    let captureData = player.capture();
    console.log("captureData:", captureData);
    captureData.forEach((item, i) => {
        captureArea.appendChild(item);
    });
};

global.release = () => {
    player.release();
};
  • index.html
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>VideoCompare</title>
        <style>
            #context {
                padding : 50px;
            }
            #play-progress {
                width: 100px;
            }
        </style>
    </head>
    <body>
        <div id="context">
            <div id="compare-player"></div>
            <hr>

            <progress id="play-progress" value="0" max="0"></progress>
            <span id="play-pts">0 / 0</span>
            <br>
            <button onclick="play()">Play</button>
            <button onclick="pause()">Pause</button>
            <button onclick="seek5()">Seek5</button>
            <button onclick="capture()">Capture</button>
            <button onclick="release()">Release</button>
        </div>
        <div id="capture-area"></div>

        <!-- script runnning -->
        <script src="dist/demo.js"></script>
    </body>
</html>