Reputation: 1214
I am not sure if this is a new question but search for 5 minutes doesn't yield any result. I want to use ffmpeg to capture 10 seconds mp4 blocks into files for my other program to post-analysis. Right now, in the code below. I will see 1-1.5 seconds gap between between the generated mp4. Only one process can poke with the /dev/video0 device. I know there's overhead in executing a process, open/close device and file i/o. How can I minimize the gap? Thanks.
const { execSync, exec } = require("child_process");
capture()
function capture() {
while(true) {
let fileName = getNewFileName();
let captureCmd = `ffmpeg -hide_banner -loglevel error -t 10 -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video0 ${fileName}.mp4 -r 1 ${fileName}-%03d.jpg`
execSync(captureCmd)
}
}
function getNewFileName() {
let date = new Date()
let month = ("0" + date.getMonth()).slice(-2);
let day = ("0" + date.getDay()).slice(-2);
let hour = ("0" + date.getHours()).slice(-2);
let min = ("0" + date.getMinutes()).slice(-2);
let sec = ("0" + date.getSeconds()).slice(-2);
return "output/" + date.getFullYear() + month + day + hour + min + sec;
}
~
Upvotes: 0
Views: 113
Reputation: 93008
This is what the segment muxer is meant for
ffmpeg -hide_banner -loglevel error -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video0 -f segment -segment_time 10 -g 250 ${fileName}-%03d.mp4 -r 1 ${fileName}-%03d.jpg
Upvotes: 1