wideor - A module that uses avconv and convert to create a slideshow video from images with the help of stroem-kid

Install:

git clone http://github.com/lahabana/wideor wideor
cd wideor
npm install
# This creates the file which will be used to check that files are well generated
# to avoid these tests use mocha test/*
npm test

Use case and example:

it is basically a wrapper around a convert and a stroem-kid to create a video from all kinds of images (please report those causing problems).

var wideor =require('../index.js');

var fs =require('fs');

var files =['1.jpg','2.png','3.jpg'];

var wid =wideor.create({

duration:5,

size:'640x480'

});

var ws =fs.createWriteStream('foo.mpeg');

wid.stdout.pipe(ws);

// add all the photos to the video

for(var j =0; j <files.length; j++){

var ext = files[j].split('.');

wid.add({path:'photos/'+ files[j],

format: ext[ext.length-1]});

}

wid.end();

ws.on('close',function(){

// Your video is created

});

By the way I am quite new to node so if it is crap or wrong please let me know :) but like really!

API

wideor.create(options, factory) Creates a stroem-kid. options is an object and is decribed later. factory should return a thread factory as needed by stroem-kid (see wideor.factory()).

options:

duration how long in seconds each image should be displayed (default:1).

formatIn the format of the stream given to avconv, also the format of the output of convert if it is used (only jpeg has been tested and other parameters may fail) (default:jpeg).

formatOut the format of the video output (internally passed as -f options.formatOut) (default:mpegts).

size the size of the video (default: 640x480).

fps the number of frames per second of the video (default:20).

wideor.plugConvert(stream, options, callback) add a convert call to normalize images which reads from stream it then call callback(err, convert_child.stdout). This is meant to be called inside you custom wideor.factory

options:

formatIn the format of the image that will be streamed into convert.

formatOut the format that convert should convert to (jpeg is the default and the only one tested) this option should be similar to the main options

formatIn as it will be piped into the avconv stdin.

size a dimension of format [width]x[height] to indicate the output size of the video (this should be options.size of the main options).

bg an heximal color code to define the background color when the image doesn't fit fully in size.

wideor.factory(options) returns a stroem-kid factory parametized with 'options' which are the options passed to wideor.create(). To plug in a convert call inside your factory wideor.plugConvert(stream, options, callback. for example:

varcustomFactory=function(options){

returnfunction(data,cb){

var str =fs.createReadStream(data.path);

var opts ={formatIn:data.format, size:options.size,

formatOut:options.formatIn, bg:data.bg};

wideor.plugConvert(str, opts, cb);

};

};

var wid =wideor.create({}, customFactory);

//...

TESTS

To check that we create video well we use Unix diff between a video previously generated with the same parameters. These videos are located in the directory checkFiles and you should generate them with the script generate_base.sh

The images used to create the videos are located in testFiles each subdirectory in testFiles contains the list of images which will constitute the video.

The test cases have a strict format: [width]x[height]_[duration]_[other]. Other can be whatever you want.

TODO

use directly libav rather than launching it from the command line

checking intermediary formats other than jpeg

MIT License

Copyright (c) 2013 Charly Molter

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.