I am creating a node application to record a live MJPEG stream 24 hours in chunks of 2 minutes.
Please see the code below.
const ffmpeg = require('fluent-ffmpeg');
const path = require('path');
const fs = require('fs');
// MJPEG stream URL (replace with your stream's URL)
const mjpegStreamUrl = 'http://192.168.195.62:8080/';
// Directory to store recorded files
const outputDir = path.join(__dirname, 'recordings');
// Ensure the output directory exists
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
// Function to start recording
function recordStream() {
const timestamp = new Date().toISOString().replace(/:/g, '-'); // Timestamp for file name
const outputFilePath = path.join(outputDir, `recording-${timestamp}.mp4`);
console.log(`Recording started: ${outputFilePath}`);
// Start recording using ffmpeg
ffmpeg(mjpegStreamUrl)
.inputFormat('mjpeg')
.outputOptions([
'-c:v copy',
'-f mp4'
])
.duration(120)
.on('end', () => {
console.log(`Recording finished: ${outputFilePath}`);
recordStream();
})
.on('error', (err) => {
console.error(`Error recording stream: ${err.message}`);
setTimeout(recordStream, 5000);
})
.save(outputFilePath);
}
recordStream();
I am always hit with the below error
Recording started: D:Recording Noderecordingsrecording-2024-09-10T05-09-34.554Z.mp4
Error recording stream: ffmpeg exited with code 4294967274: Conversion failed!
Kindly tell me what I am doing wrong. Thanks.
1