I want to create video from image files. So I have installed videoshow module. And configured the same as per the documentaion.
var videoOptions = {
fps: 25,
loop: 5, // seconds
transition: true,
transitionDuration: 1, // seconds
videoBitrate: 1024,
videoCodec: 'libx264',
size: '640x?',
audioBitrate: '128k',
audioChannels: 2,
format: 'mp4',
pixelFormat: 'yuv420p'
}
var images = [
"D:/PROJECTS/Video/storage/1.jpg",
"D:/PROJECTS/Video/storage/2.jpg"
];
app.get("/video", function () {
videoshow(images, videoOptions)
// .audio('song.mp3')
.save('video.mp4')
.on('start', function (command) {
console.log('ffmpeg process started:', command)
})
.on('error', function (err, stdout, stderr) {
console.error('Error:', err)
console.error('ffmpeg stderr:', stderr)
})
.on('end', function (output) {
console.error('Video created in:', output)
})
});
But When I run it shows the error on server
Error: Error: Cannot find ffmpeg
at D:\PROJECTS\Video\node_modules\videoshow\node_modules\fluent-ffmpeg\lib\processor.js:136:22
at D:\PROJECTS\Video\node_modules\videoshow\node_modules\fluent-ffmpeg\lib\capabilities.js:123:9
at D:\PROJECTS\Video\node_modules\videoshow\node_modules\async\dist\async.js:473:16
at next (D:\PROJECTS\Video\node_modules\videoshow\node_modules\async\dist\async.js:5315:29)
at D:\PROJECTS\Video\node_modules\videoshow\node_modules\async\dist\async.js:958:16
at D:\PROJECTS\Video\node_modules\videoshow\node_modules\fluent-ffmpeg\lib\capabilities.js:116:11
at D:\PROJECTS\Video\node_modules\videoshow\node_modules\fluent-ffmpeg\lib\utils.js:223:16
at F (D:\PROJECTS\Video\node_modules\videoshow\node_modules\which\which.js:68:16)
at E (D:\PROJECTS\Video\node_modules\videoshow\node_modules\which\which.js:80:29)
at D:\PROJECTS\Video\node_modules\videoshow\node_modules\which\which.js:89:16
Then I installed ffmpeg using
npm install ffmpeg --save
but not worked. So I tried installing at the global level using
npm install ffmpeg -g
Even installing on my window machine and setting the path of its bin folder in environment variables did not work?
What could be the issue?
Actually, I need to instal the ffmpeg in my system and set it to the environment path variable.
And you don't need to install in nodejs.
npm i videoshow
Just use this command
Related
I'm trying to setup a Lambda layer to add a watermark to images with Graphicsmagick. I'm however a bit stuck at getting the binary to work with the libraries, so how do I setup a link to the libraries within the child process?
So far I've built the Graphicsmagick binary with the following options:
./configure --prefix=/opt/graphicsmagick --enable-shared=no --enable-static=yes --disable-shared --disable-installed
Pretty much followed the instructions on this answer and ideas from this Gist. Either one however does not concern running binaries as a layer. So wondering maybe there are some specifics to that which I'm missing here?
Heres the code from my handler:
module.exports.run = async (event, context, callback) => {
process.env['IM_PATH'] = '/opt/graphicsmagick/bin/'
process.env['LD_LIBRARY_PATH'] = '/opt/graphicsmagick/lib'
process.env['DYLD_LIBRARY_PATH'] = '/opt/graphicsmagick/lib'
process.env['MAGICK_HOME'] = '/opt/graphicsmagick/'
...
const graphicsmagick = '/opt/graphicsmagick/bin/gm'
const graphicsmagickArgs = [
'-dissolve', '15',
'-tile',
watermark,
inputImage,
output,
]
spawn(graphicsmagick, graphicsmagickArgs, { stdio: 'inherit' })
.on('close', () => console.log('success'))
.on('error', error => console.log('error', error))
...
}
I've also tried running an exec with the environment variables like so:
exec('/opt/graphicsmagick/bin/gm', { env:
{
'IM_PATH': `/opt/graphicsmagick/bin/`,
'LD_LIBRARY_PATH': '/opt/graphicsmagick/lib',
'DYLD_LIBRARY_PATH': '/opt/graphicsmagick/lib',
'MAGICK_HOME': `/opt/graphicsmagick/`,
}}, (err, stdout, stderr) => {
console.log('error', err)
console.log('stdout', stdout)
console.log('stderr', stderr)
})
The layer runs Graphicsmagick but does not find the libraries folder. I get the following error in the console:
/opt/graphicsmagick/bin/gm: error while loading shared libraries:libpng15.so.15: cannot open shared object file: No such file or directory
My ffmpeg function thats running as a shell command isnt working. I think its because 'ffmpeg' isnt really referring to anything. I have the ffmpeg node module in my bundle, but i dont know the execFile command is referring to it here.
Im following aws-lambda-ffmpeg as an example of how to call this particular function. They are referring to 'ffmpeg' as a 64-bit linux build they created from John Vansickle's static FFMPEG builds in their gulp function.
I want to know how to replace 'ffmpeg' with something that will just recognize it like a node_module without having to do the whole gulp static build process. To my understanding the only reason they are doing that is to get the latest build which i really dont need.
If I am wrong and a static build using gulp is needed for another reason please let me know.
function ffmpegProcess(description, cb) {
console.log('Starting FFmpeg');
child_process.execFile(
'ffmpeg',
[
'-y',
'-loglevel', 'warning',
'-i', 'download',
'-c:a', 'copy',
'-vf', scaleFilter,
'-movflags', '+faststart',
'-metadata', 'description=' + description,
'out.' + config.format.video.extension,
'-vf', 'thumbnail',
'-vf', scaleFilter,
'-vframes', '1',
'out.' + config.format.image.extension
],
{
cwd: tempDir
},
function(err, stdout, stderr) {
console.log('FFmpeg done.');
return cb(err, 'FFmpeg finished:' + JSON.stringify({ stdout: stdout, stderr: stderr}));
}
);
}
I need blender command-line access though spawn but keep running into an ENOENT error and it is hard to pinpoint what is missing. The command-line being passed in the sample application works in terminal.
Below are some details about the environment and the sample script I am using.
Environment (OSX El Capitan)
Installed Blender 2.76b with:
brew install Caskroom/cask/blender
Then add alias to bash_profile for terminal access:
alias blender="/Applications/blender/Blender.app/Contents/MacOS/blender"
Test Code
#!/usr/bin/env node
var child_process = require('child_process');
var arguments = [
'-b',
'recipe.blend',
'-o', 'test-#',
'-f', 0
];
console.log("values: ", arguments);
var child = child_process.spawn('blender', arguments);
child.stdout.on('data', function(data) {
console.log('data out: ', data.toString());
});
child.stderr.on('data', function(data) {
console.error('error out: ',data);
});
child.on('close', function(code) {
console.log('closing code: ' + code);
});
// Raw command-line for terminal. (PASS)
// blender -b recipe.blend -o test-# -f 0
Try changing the child_process.spawn('blender', arguments); line to child_process.spawn('/Applications/blender/Blender.app/Contents/MacOS/blender', arguments);. NodeJS won't be using your bash aliases, so unless the blender executable is in its PATH it won't be able to find the executable and will throw an ENOENT.
The other option is adjusting Node's PATH to include the path to the blender executable. You could also pass the fullpath to the blender executable in as an environment variable.
Cheers!
I have a very strange error. I'm using MAC OS X 10.9.5.
When i use some functions from GM (npm install gm) like resize or something else i got this error.
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:988:11)
at Process.ChildProcess._handle.onexit (child_process.js:779:34)
I have found many threads about it and according to them i have installed graphicksmagic and imagemagick with brew to system.
brew install imagemagick
brew install graphicsmagick
It was working for a while but for no reason it starts to showing the above error again.
I checked that i have installed imagemagick and graphicksmagick in system and its working from terminal.
I checked if i have it in $PATH and its there.
If i run this in nodejs it shows correct version of imagemagick in console, so i assume path is ok in nodejs.
var sys = require('sys')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) {
if(error)
sys.puts(error);
if(stderr)
sys.puts(stderr);
sys.puts(stdout);
}
exec("identify --version", puts);
This is code which is crashing:
gm(request(url), thumbName)
.resize('300', '300', '^')
.gravity('Center')
.crop('300', '300')
.toBuffer('JPG',function (err, buffer) {
var data = {
Bucket: bucket,
Key: thumbName,
Body: buffer,
ACL:'public-read',
ContentType: 'image/jpeg'
};
s3.putObject(data, function(err, res) {
....
});
Everything is working when i deploy it on heroku
IF someone will have this issue i solved it.
I add variable PATH to enviroment variables in node with this value
bin:node_modules/.bin:/usr/local/bin:/usr/bin:/bin
I am building an app with node.js, I successfully uploaded the video, but I need to generate a video thumbnail for it. Currently I use node exec to execute a system command of ffmpeg to make the thumbnail.
exec("C:/ffmpeg/bin/ffmpeg -i Video/" + Name + " -ss 00:01:00.00 -r 1 -an -vframes 1 -f mjpeg Video/" + Name + ".jpg")
This code is coming from a tutorial from http://net.tutsplus.com/tutorials/javascript-ajax/how-to-create-a-resumable-video-uploade-in-node-js/
the code above did generate a jpg file but it's not a thumbnail but a video screen shot, I wonder is there any other method to generate video thumbnail, or how to exec the ffmpeg command to make a real thumbnail (resized), and I prefer png file.
Reference to GitHub fluent-ffmpeg project.
Repeating example from original StackOverflow answer:
var proc = new ffmpeg('/path/to/your_movie.avi')
.takeScreenshots({
count: 1,
timemarks: [ '600' ] // number of seconds
}, '/path/to/thumbnail/folder', function(err) {
console.log('screenshots were saved')
});
Resize by adding a -s widthxheight option to your command.
There is a node module for this:
video-thumb
It basically just wraps a call to exec ffmpeg
I recommend using https://www.npmjs.com/package/fluent-ffmpeg to call ffmpeg from Node.js
Using media-thumbnail, you can easily generate thumbnails from your videos. The module basically wraps the ffmpeg thumbnail functionality.
const mt = require('media-thumbnail')
mt.forVideo(
'./path/to/video.mp4',
'./path/to/thumbnail.png', {
width: 200
})
.then(() => console.log('Success'), err => console.error(err))
You can also create thumbnails from your images using this package.
Instead I would recommend using thumbsupply. In addition to provide you with thumbnails, it caches them to improve performance significantly.
npm install --save thumbsupply
After installing the module, you can use it in a following way.
const thumbsupply = require('thumbsupply')("com.example.application");
thumbsupply.generateThumbnail('some-video.mp4')
.then(thumb => {
// serve thumbnail
})
app.post('/convert', upload.any(), (req, res) => {
console.log("calling", req.files)
let thumbNailName = req.files[0].filename.split('.')
var gm = require('gm');
gm('./src/Upload/'+req.files[0].filename)// get pdf file from storage folder
.thumb(
50, // Width
50, // Height
'./src/thumbnail/'+thumbNailName[0]+'.png', // Output file name
80, // Quality from 0 to 100
function (error, stdout, stderr, command) {
if (!error) {
console.log("processing");
} else {
console.log("error")
}
}
);
})