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-rtp

v0.3.1

Published

Real time video transmission in Web

Downloads

4

Readme

video-rtp

npm

A cross-browser implementation to record video on real time

1. Use webRTC/mediaRecord first 2. Degrade to use "input[type = file]" when not support webRTC

video-rtp can open the camera and record video to a series of blobs. You can upload the recorded blobs in realtime to the server! Or you can get the blobs and combine to a smaller video after specific time-intervals.

Browser Support

According to webRTC/MediaRecord/Canvas's compatibility

| Browser | Support | Features | | ------------- |-------------|-------------| | Firefox | mobile / PC | webRTC to webm | | Google Chrome | mobile / PC | webRTC to webm | | Opera | mobile / PC | mobile: canvas to webp, PC: webRTC to webm | | Android | ALL | Chrome: webRTC to webm, Other: canvas to webp | | Microsoft Edge | Suggest: rtmp-streamer | canvas to webp | | Safari 11 | mobile / PC | canvas to webp now |

There is a similar project: RecordRTC! Demo

How to use it

You can install scripts using NPM:

npm install video-rtp

Record video

import {webrtcSurport, openVideo} from 'video-rtp'

function getSocket(isRTC) {
    let url = `ws://localhost:3000/${isRTC ? 'webm' : 'webp'}`
    const ws = new WebSocket(url);
    return new Promise(resolve => {
    ws.onopen = () => resolve(ws)
    })
},

const wsP = getSocket(webrtcSurport())

const record = await openVideo({
    video: document.getElementById('webrtc'),
    duration: 100,
    MINSIZE: 1024,
    chunks(chunk) {
    // sender chunks
    console.log('sender chunks', chunk)
    wsP.then(ws => ws.send(chunk))
    },
    ended() {
    // record chunks ended, You can save video in this function.
    console.log('record chunks ended')
    wsP.then(ws => ws.send(0))
    },
    degrade:true // 不支持webRTC则降级处理打开本地视频
})

How to save recordings?

import {webrtcSurport, openVideo} from 'video-rtp'
import Whammy from 'whammy'

let video = null
const encoder = new Whammy.Video(15);
openVideo({
    /* .....*/
    chunks(blobs, canvas) {
        // save webm/webp to blobs
        encoder.add(canvas)
    },
    ended() {
        // create video by blobs
        if (webrtcSurport()) {
            video = new Blob(blobs, {type: 'video/webm;codecs=vp9'});
        }else {
            video = encoder.compile()
        }
    },
    degrade:document.getElementById('p') // 不支持webRTC则降级处理打开本地视频
})

DEMO

Local video compression and upload

WEB push and pull stream, mock live broadcast

https://github.com/zhutao315/videoRTP-example

npm install && npm start

open localhost:3000

API Documentation

| Name | Type | Default | Description | | ---------------| ------------- | ------------- | ---------------------------------------------------------------| | video | String/DOM | - | Display video recorded by the camera | | duration | Number | 100(ms) | The time interval when Canvas draws frames | | collectTime | Number | 1000(ms) | The time length of chunks by mediaRecord record | | MINSIZE | Number | 1M | If the video size is lower than this value, the video will be returned without processing | | MAXTIME | Number | 15(m) | The Maximum duration of the upload video | | chunks | Function | () => { } | The callback Function executed each time when the screen is recorded. The param is a blob and the blob's type is webm/webp | | ended | Function | () => { } | The callback Function executed when the record is end | | degrade | String/DOM/Boolen | - | The degrage is usefull when the webRTC is not supported |

When the "degrade" is a string, the component will find the DOM by id/class. The dom will bind a click event to open the local video. When the value of "degrade" is true, the openVideo function will open the local video directly.

How to manually stop recordings?

record.stop();

How to pause recordings?

record.pause();

How to resume recordings?

record.resume();

License

If you have any Suggestions, let me know. Thanks! MIT licence