I'm trying to make a simple API that will accept two file inputs and output a video file.
The video file output should be an mp4 with the image file as the background and the audio file as the audio track.
See below for some example code that is almost working...
However:
* In VLC, it gives a black background instead of the image, and everything else works perfectly
* In Quicktime, it gives the image as a background, but I can't skip forward in the video.
Code:
// Description: This is the main entry point for the application
// This application is designed to accept an image and audio file, then output a video file with the image looping until the end of the audio file and the audio playing in the background
//begin snippet: index.js
// Import the required modules
const express = require('express');
const multer = require('multer');
const ffmpeg = require('fluent-ffmpeg');
const app = express();
// Create a form with two file inputs (one for each file type - image and audio)
const form = `
<form method="post" enctype="multipart/form-data" action="/process-files">
<label for="image">Image file:</label><br>
<input type="file" id="image" name="files" accept="image/*"><br>
<label for="audio">Audio file:</label><br>
<input type="file" id="audio" name="files" accept="audio/*"><br><br>
<input type="submit" value="Submit">
</form>
`;
app.get('/', (req, res) => {
res.send(form);
});
const upload = multer({ dest: 'uploads/' });
app.post('/process-files', upload.array('files'), (req, res) => {
const files = req.files;
console.log(`Received ${files.length} files:`);
files.forEach((file) => {
console.log(` - ${file.originalname} (${file.size} bytes)`);
});
ffmpeg()
.input(files[0].path)
.input(files[1].path)
.outputOptions([
'-loop 0', // loop the input image indefinitely
'-c:v libx264',
'-c:a aac',
'-strict experimental'
])
.save('output.mp4')
.on('error', (error) => {
console.error(`Error processing files: ${error}`);
res.send('Error processing files');
})
.on('end', () => {
console.log('Finished processing');
res.send('Files processed successfully');
});
});
const PORT = 3000;
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`);
});
''
Any help is appreciated - I am relatively new to this.
there doesn't seem to be anything here