Skip to content

Commit

Permalink
added example to save frame via ffmpeg directly
Browse files Browse the repository at this point in the history
  • Loading branch information
b-g committed Sep 6, 2017
1 parent b344682 commit 5f94bb1
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/darknetImageFfmpegTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const darknet = require('@moovel/yolo');
const spawn = require('child_process').spawn;
let ffmpeg = null;

// ffmpeg -f rawvideo -s 768x576 -pix_fmt bgr24 -i data.modified.raw data.png
function ffmpegPipe(dimensions, filename) {
if (!ffmpeg) {
ffmpeg = spawn('ffmpeg',
[
'-loglevel', 'warning',
'-f', 'rawvideo',
'-pix_fmt', 'bgr24', // or 'rgb24' if color channels are swapped
'-s', `${dimensions.width}x${dimensions.height}`,
'-y',
'-i', '-',
filename
], {
stdio: ['pipe', process.stdout, process.stderr],
});
return ffmpeg.stdin;
} else {
return ffmpeg.stdin;
}
}

darknet.detectImage({
cfg: './cfg/yolo.cfg',
weights: './yolo.weights',
data: './cfg/coco.data',
image: './data/dog.jpg',
}, function(modified, original, detections, dimensions) {
ffmpegPipe(dimensions, 'detected.png').write(modified, function() {
process.exit(0);
});
});

0 comments on commit 5f94bb1

Please sign in to comment.