Commit ca03dac8 authored by Jan Göttlich's avatar Jan Göttlich

Fixed problems and Created Entry Point

*fixed a severe problem where you were sprites were wrongly
*created a new modified entry point which is easier to access
*changed README to only have the options
parent 82702ce8
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# compiled output # compiled output
/dist /dist
/tmp /tmp
/playground/tmp/* /playground
# dependencies # dependencies
/node_modules /node_modules
......
npm # Video thumbnails + WebVTT using Node.js
Thumbnails generator module. Uses [WebVTT](http://dev.w3.org/html5/webvtt/) as thumbnails descriptor. Can pack thumbnails into spritesheet using [node-sprit]() module.
## Installation
npm install thumbnails-webvtt --save
## Requirements
* [ffmpeg](https://www.ffmpeg.org/) used by `fluent-ffmpeg`
* [ImageMagick](http://www.imagemagick.org/) as used by `node-sprite`
## Example
```javascript
'use strict'
var thumbgen = require('thumbnails-webvtt')
thumbgen('/media/Hammer.of.the.Gods.2013.BluRay.720p.mkv', {
output: '/vtt/Hammer.of.the.Gods.2013.BluRay.720p.vtt',
size: {
width: 480
},
numThumbnails: 6,
spritesheet: true
}, function(err, metadata) {
if (err) {
throw err
}
console.dir(metadata)
})
```
will print
```javascript
[ { path: '/Hammer.of.the.Gods.2013.BluRay.720p/thumbnails.png#xywh=0,808,480,200',
from: '00:00:00.000',
to: '00:14:49.474' },
{ path: '/Hammer.of.the.Gods.2013.BluRay.720p/thumbnails.png#xywh=0,0,480,200',
from: '00:14:49.474',
to: '00:29:38.947' },
{ path: '/Hammer.of.the.Gods.2013.BluRay.720p/thumbnails.png#xywh=0,202,480,200',
from: '00:29:38.947',
to: '00:44:28.421' },
{ path: '/Hammer.of.the.Gods.2013.BluRay.720p/thumbnails.png#xywh=0,404,480,200',
from: '00:44:28.421',
to: '00:59:17.894' },
{ path: '/Hammer.of.the.Gods.2013.BluRay.720p/thumbnails.png#xywh=0,606,480,200',
from: '00:59:17.894',
to: '01:14:07.368' },
{ path: '/Hammer.of.the.Gods.2013.BluRay.720p/thumbnails.png#xywh=0,1010,480,200',
from: '01:14:07.368',
to: '01:38:49.824' } ]
```
## API ## API
### thumbgen(source, options, callback) ### thumbgen(source, options, callback)
...@@ -93,7 +34,7 @@ Create thumbnails (and optionally pack them into spritesheet) and create WebVTT ...@@ -93,7 +34,7 @@ Create thumbnails (and optionally pack them into spritesheet) and create WebVTT
* Number of thumbnails to generate. Used in opposite to `timemarks`. Each thumbnail moment is calculated as `source_duration * 0.9 / numThumbnails`. * Number of thumbnails to generate. Used in opposite to `timemarks`. Each thumbnail moment is calculated as `source_duration * 0.9 / numThumbnails`.
* **secondsPerThumbnail** defaults to `0` * **secondsPerThumbnail** defaults to `5`
* If specified thumbnails will be generated each `secondsPerThumbnail` seconds. * If specified thumbnails will be generated each `secondsPerThumbnail` seconds.
...@@ -101,7 +42,7 @@ Create thumbnails (and optionally pack them into spritesheet) and create WebVTT ...@@ -101,7 +42,7 @@ Create thumbnails (and optionally pack them into spritesheet) and create WebVTT
* If specified thumbnails will be generated each `framesPerThumbnail` frames. * If specified thumbnails will be generated each `framesPerThumbnail` frames.
* **spritesheet** defaults to `false` * **spritesheet** defaults to `true`
* Generate spritesheet or not. * Generate spritesheet or not.
...@@ -109,12 +50,3 @@ Create thumbnails (and optionally pack them into spritesheet) and create WebVTT ...@@ -109,12 +50,3 @@ Create thumbnails (and optionally pack them into spritesheet) and create WebVTT
* Spritesheet file name * Spritesheet file name
* **spriteSheetOptions** default to `null`
* Spritesheet options passed to [node-sprite](https://github.com/naltatis/node-sprite#options) `.sprite()` function.
## TODO
* Use cool spritesheet generator
* Tests
* Use some kind of WebVTT generator?
"use strict";
const thumbgen = require('lib/index');
const Promise = require('bluebird');
function generateThumbnailTooltip(options) {
thumbgen(options.pathtovideo, {
output: options.output || './tmp/vtt/myVTT.vtt',
assetsDirectory: options.assetsDirectory,
size: {
width: options.width,
height: options.height
} || null,
timemarks: options.timemarks || null,
numThumbnails: options.numThumbnails || 0,
secondsPerThumbnail: options.secondsPerThumbnail || 5,
framesPerThumbnail: options.framesPerThumbnail || 0,
spritesheet: options.spritesheet || true,
spriteSheetName: options.spriteSheetName || 'thumbnails',
}, function (err, metadata) {
if (err) {
throw err
}
});
}
module.exports = generateThumbnailTooltip;
...@@ -29,6 +29,7 @@ exports.generateThumbnails = function(source, options, callback) { ...@@ -29,6 +29,7 @@ exports.generateThumbnails = function(source, options, callback) {
.on('end', success) .on('end', success)
.screenshots( .screenshots(
{ {
filename: 'tn_%000i.png',
size: mysize, size: mysize,
count: options.timemarks.length, count: options.timemarks.length,
timemarks: options.timemarks timemarks: options.timemarks
......
...@@ -104,11 +104,30 @@ function SpriteSheetWriter(metadata, options, filenames) { ...@@ -104,11 +104,30 @@ function SpriteSheetWriter(metadata, options, filenames) {
} }
} }
function filenameToNumber(a) {
let number = a.match(/(\d+)/)[1];
return parseInt(number);
}
//
// function changeFilename(aFilenames){
// for(let i = 0; i < aFilenames.length; i++ ){
// aFilenames[i].filename = "tn_" + (i+1) +".png";
// aFilenames[i].name = "tn_" + (i+1) + ".png";
// }
// }
function createSpriteSheet() { function createSpriteSheet() {
generate.sprite(sheetName, spriteOptions, function(err, globalSprite) { generate.sprite(sheetName, spriteOptions, function(err, globalSprite) {
if (err) { if (err) {
return self.emit('internalError', err) return self.emit('internalError', err)
} }
// changeFilename(globalSprite.images);
// globalSprite.images.sort((a,b)=>{
// let aNumber = filenameToNumber(a.filename);
// let bNumber = filenameToNumber(b.filename);
// return aNumber - bNumber;
// });
var sprites = globalSprite.images var sprites = globalSprite.images
, sheetFilename = globalSprite.filename() , sheetFilename = globalSprite.filename()
...@@ -118,6 +137,12 @@ function SpriteSheetWriter(metadata, options, filenames) { ...@@ -118,6 +137,12 @@ function SpriteSheetWriter(metadata, options, filenames) {
, sprite , sprite
, spritePath , spritePath
sprites.sort((a,b)=>{
let aNumber = filenameToNumber(a.filename);
let bNumber = filenameToNumber(b.filename);
return aNumber - bNumber;
});
while (filename = filenames[i++]) { while (filename = filenames[i++]) {
sprite = lodash.find(sprites, {filename: filename}) sprite = lodash.find(sprites, {filename: filename})
spritePath = util.format( spritePath = util.format(
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"description": "Module for creating video thumbnails with WebVTT file as descriptor", "description": "Module for creating video thumbnails with WebVTT file as descriptor",
"version": "0.0.4", "version": "0.0.4",
"license": "MIT", "license": "MIT",
"main": "lib/index.js", "main": "index.js",
"keywords": [ "keywords": [
"video", "video",
"thumbnail", "thumbnail",
......
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
let thumbgen = require('../lib/index'); let thumbgen = require('../lib/index');
thumbgen('./tmp/oceans.mp4', { let name = "tagesschau";
output: './tmp/vtt/myVTT.vtt',
thumbgen('./tmp/' + name + '.mp4', {
output: './tmp/vtt/' + name + '.vtt',
size: { size: {
width: 100 width: 100
}, },
numThumbnails: 50, numThumbnails: 180,
spritesheet: true spritesheet: true
}, function(err, metadata) { }, function(err, metadata) {
if (err) { if (err) {
...@@ -16,6 +18,4 @@ thumbgen('./tmp/oceans.mp4', { ...@@ -16,6 +18,4 @@ thumbgen('./tmp/oceans.mp4', {
} }
console.log(metadata) console.log(metadata)
}); });
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment