Reputation: 119
I'm trying to make thumbnails for videos, but the problem is I'm not able to write some right ffmpeg commands for getting the very first frame. This is for a Node.js AWS Lambda function.
I tried this, but it's not working for me.
-vf "select=eq(n\,0)"
Tried all from here How to extract the 1st frame and restore as an image with ffmpeg?.
Here's my command line, I copied it and honestly I have no idea about this commands.
function createImage(type) {
return new Promise((resolve, reject) => {
let tmpFile = fs.createWriteStream(`/tmp/screenshot.${type}`);
const ffmpeg = spawn(ffmpegPath, [
'-ss',
'00:00:00.01',
'-i',
target,
'-vf',
`thumbnail`,
'-qscale:v',
'2',
'-frames:v',
'1',
'-f',
'image2',
'-c:v',
'mjpeg',
'pipe:1',
]);
ffmpeg.stdout.pipe(tmpFile);
ffmpeg.on('close', function(code) {
tmpFile.end();
resolve();
});
ffmpeg.on('error', function(err) {
console.log(err);
reject();
});
});
}
(I use this https://johnvansickle.com/ffmpeg/ release 4.2.3 version on a Node child process.)
Upvotes: 2
Views: 503
Reputation: 575
This should get you the result you wanted.
You had some extra arguments in your command. You should read the ffmpeg documentation.
function createImage(type) {
return new Promise((resolve, reject) => {
let tmpFile = fs.createWriteStream(`./screenshot.${type}`);
const ffmpeg = spawn(ffmpegPath, [
'-i', target,
'-r', '1',
'-vframes', '1',
'-f', 'image2',
'-qscale:v', '2',
'-c:v', 'mjpeg',
'pipe:1'
]);
ffmpeg.stdout.pipe(tmpFile);
ffmpeg.on('close', code => {
tmpFile.end();
resolve();
});
ffmpeg.on('error', err => {
console.log(err);
reject();
});
});
}
createImage("jpg");
Upvotes: 1