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

html5-media-converter-fixed-size

v0.0.1

Published

Converts videos and images into web-usable formats

Downloads

2

Readme

html5-media-converter

NodeJS module to convert media files into format suitable for web usage. There is a good article about this topic at the Mediacru.sh blog and this module tries to apply these best practices.

In order to use it, you'll need a current version of ffmpeg. To cite Mediacru.sh:

"Please note that you cannot use your distribution-provided ffmpeg package. Read up on compiling
ffmpeg yourself and make sure you include libx264, fdk-aac, libmp3lame, libvpx, and libopus. Our
servers and dev machines run Arch Linux and we just install the ffmpeg-full package from the AUR"

Example

The following snippets converts the file video.avi to targetDir/video.mp4, targetDir/video.ogv and targetDir/video.webm. The video is resized to fit into a box of "200x200" pixels.

var MediaConverter = require("html5-media-converter");
var mc = new MediaConverter();
mc.convert("source.avi", "200x200", "targetDir")

The following snippet uses the media-converter with streams and a .map(...) function. This snippet is untested and strongly simplified. It downloads a file from a webserver, converts it to mp4, webm and ogv, and uploads the result to the server.

var MediaConverter = require("html5-media-converter");
var request = require("request");
var mc = new MediaConverter();
var converter = mc.asStream("200x200");
request.get('http://server/original.avi').pipe(converter).map(function(stream) {
    stream.pipe(request.put("http://server/thumbnail"+stream.videoConverter.extName()));
});

Note that this works on-the-fly for ogv and webm, but the mp4-encoder cannot directly write to a stream, so the mp4-file is temporary saved into a file before uploading. This, however, happens automatically (as part of the process-streams package) and should not be your concern. There is another issue with decoding certain mp4-videos, which is described [in this SuperUser-post](http://superuser .com/questions/479063/ffmpeg-pipe-input-error). The piping-example won't work with these videos.

The MediaConverter can be configured to use other codecs and only a subset of codecs. The following will only convert to mp4, if that is enough for you.

var MediaConverter = require("html5-media-converter");
var request = require("request");
var mc = new MediaConverter({ videoFormats: ['mp4'] });

There are other options as well. Default default is

{
    programs: {
        // Path to the ffmpeg program
        ffmpeg: 'ffmpeg',
        // Path the the imagemagick convert program
        convert: 'convert'
    },
    videoFormats: ['mp4', 'ogv', 'webm']
}

TODO

  • Add image scaling as well.
  • Use input temp-file for unstreamable videos.
  • Test cases are not complete yet. They are running the module, but are not really testing the result. I'm not sure, if this is possible at all, but it would be good.

Please note that this api is still experimental. Feedback is welcome, although I cannot guarantee any response times at the moment.