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

pixels-to-video

v0.0.123

Published

convert raw pixel data into GIFs or MP4s by piping to ffmpeg

Downloads

7

Readme

pixels-to-video

convert raw pixel data into GIFs or MP4s

pipes image data directly into ffmpeg - no need for temporary image files

much of the code is based on this thread

Installation

First install ffmpeg

Then

npm i pixels-to-video

Usage

Here we create a GIF and MP4 with random colors

var p2v = require('pixels-to-video');

var fps = 2; //frames per second
var width = 128; 
var height = 128;
var numFrames = 10;

//create flat pixel buffer with random colors [r,g,b,a,r,g,b,a ... ]
function randomColorsBuffer(w,h){ 
    var arr = [];
    for(var i=0;i<w*h;i++){
        arr.push(
            Math.floor(Math.random()*255), //r
            Math.floor(Math.random()*255), //g
            Math.floor(Math.random()*255), //b
            255 //a [ignored]
        );
    }
    return arr;
}

//////////////////////////////////////////////
//you can load an array of pre-rendered frames
//////////////////////////////////////////////

var frames = [];
for(var i=0;i<numFrames;i++){
    var frame = randomColorsBuffer(width,height);
    frames.push(frame);
}

//p2v.makeQuiet(true); //disable ffmpeg logging

p2v.makeMp4Sync('./output.mp4',frames,width,height,fps)
p2v.makeGifSync('./output.gif',frames,width,height,fps)

//async versions of these functions
//p2v.makeMp4('./output.mp4',frames,width,height,fps,cb)
//p2v.makeGif('./output.gif',frames,width,height,fps,cb)

///////////////////////////////////////////////
//or you can "stream" the frames in 1 at a time
///////////////////////////////////////////////

var framesSoFar = 0;
function getNextFrame(){
    framesSoFar++;
    if(framesSoFar>10){return null;} //return null to end the stream
    return randomColorsBuffer(width,height);//return 
}

p2v.makeMp4StreamedSync('./output2.mp4',getNextFrame,width,height,fps)

framesSoFar = 0;
p2v.makeGifStreamedSync('./output2.gif',getNextFrame,width,height,fps)

// async versions of these functions
// p2v.makeMp4Streamed('./output2.mp4',getNextFrame,width,height,fps,cb)
// p2v.makeGifStreamed('./output2.gif',getNextFrame,width,height,fps,cb)

The resulting GIF:

result

See Also

  • video-to-pixels - the opposite of this tool, converts videos into raw pixels

stonks