Split a concatenated stream of PNG images into individual PNG frames
This module is installed via npm:
$ npm install png-split-stream
var pngSplitStream = require('png-split-stream');
// all.png is a concatenation of multiple PNGs
// eg. `cat a.png b.png > all.png`
fs.createReadStream(__dirname + '/fixtures/all.png')
.pipe(pngSplitStream())
.on('data', function(data) {
// each 'data' event contains one of the whole images as a single chunk
console.log(data.slice(1, 4));
// 'PNG'
});
var ffmpegBin = require('ffmpeg-static');
var spawn = require('child_process').spawn;
var ffmpeg = spawn(ffmpegBin.path, [
'-i', 'myfile.mp4',
'-f', 'image2pipe',
'-vcodec', 'png',
'-'
]);
ffmpeg.stdout
.pipe(pngSplitStream())
.on('data', function (data) {
// each 'data' event contains one of the frames from the video as a single chunk
console.log(data.slice(1, 4));
// 'PNG'
});
This code was heavily adapted and stripped down for just splitting purposes from @devongott/png-stream.