Giter Site home page Giter Site logo

couturecraigj / html5-media-converter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nknapp/html5-media-converter

0.0 1.0 0.0 678 KB

NodeJS module to convert media files into format suitable for web usage (discontinued, please write if you want to take over)

License: MIT License

JavaScript 100.00%

html5-media-converter's Introduction

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.

html5-media-converter's People

Contributors

couturecraigj avatar greenkeeper[bot] avatar nknapp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.