Does .pipe() return a full frame in each buffer? Trying to send video stream directly from fluent-ffmpeg to node-opencv for analysis.
No it doesn't. Buffer size mostly depends on OS configuration. You'll get chunks of a video file that have no direct link whatsoever with the video timeline.
Ah alright, kinda figured that. Any suggestions on how to implement something like this?
I think you may simply run ffmpeg with something like "frame%d.jpg" as the output filename. ffmpeg will automatically select the jpeg format and output frame0.jpg, frame1.jpg, etc.
Then you can use the 'progress' event from fluent-ffmpeg ; the 'frames' attribute in the argument to the event handler will tell you how many frames ffmpeg has processed yet, thus how many output files are available. Here's a quick example:
function enqueueFrame(number) {
// do something with frame<number>.jpg
}
var lastFrameEnqueued = 0;
ffmpeg(inputStream)
.on('progress', function(progress) {
var n = lastFrameEnqueued + 1;
lastFrameEnqueued = progress.frames - 1;
for (; n < progress.frames; n++) {
enqueueFrame(n);
}
})
.save('frame%d.jpg')
Oh, and you may want to check whether progress.frames is a valid number. I think the first occurences of the 'progress' may have an empty string there instead (while ffmpeg is getting set up).
Thanks yeah that works, a little laggy because frames have to be saved and then read from disk but not bad.
Save them in /tmp, most distros mount /tmp on a ramdisk nowadays, that way it will be just as fast as using plain in-memory streams.
(edit: typo)
Closing for housekeeping, feel free to reopen if necessary !
Most helpful comment
I think you may simply run ffmpeg with something like "frame%d.jpg" as the output filename. ffmpeg will automatically select the jpeg format and output frame0.jpg, frame1.jpg, etc.
Then you can use the 'progress' event from fluent-ffmpeg ; the 'frames' attribute in the argument to the event handler will tell you how many frames ffmpeg has processed yet, thus how many output files are available. Here's a quick example: