FFMPEG command works in shell ! but not in my node.js - node.js

When my ffmpeg command is built by my node.js application it does not run.
error
Unrecognized option 'ss 3.2 -t 1.9 -i videoplayback.mp4 -vf fps=15,scale=240:-1:flags=lanczos,palettegen palette.png'.
command
ffmpeg -ss 3.2 -t 1.9 -i videoplayback.mp4 -vf \ fps=15,scale=240:-1:flags=lanczos,palettegen palette.png
this is my code
var child_process = require('child_process')
function recordVideo() {
var spawn = child_process.spawn;
var args = [
'-y',
'-ss', '3.2',
'-t', '1.9',
'-i', '../getback/bin/videos/videoplayback.mp4',
'-vf', ' \\ ',
'fps=', '15',
'scale=', '320:-1',
'flags=','lanczos,palettegen palette.png',
];
var ffmpeg = spawn('ffmpeg', args);
ffmpeg.stdout.on('data', function (data) {
console.log(data);
});
ffmpeg.stderr.on('data', function (data) {
console.log('grep stderr: ' + data);
});
ffmpeg.on('close', (code) => {
console.log('child process exited with code ' + code);
});
};
recordVideo();
what is this error?
I think.. 'fps=', '15', In the following code
'=' options a problem.
I am still learning English.
I'm sorry if it was hard to understand.

Node will put a space between every argument in the array you give to child_process.spawn function, as the second argument, when it's building your command. Try replacing the argument pairs like "fps=" and "15" with a single argument: "fps=15".

For future reference one can view the spawned arguments by reading the spawnargs property from the created child process.

Related

Get full command-line string from child_process.spawn

I'm spawning a process with child_process.spawn(). How can I view the exact command line that is executed (including all command-line parameters passed into the spawn function)?
Here's my example that isn't working:
var s = require('child_process');
var p = s.spawn('ffmpeg', ['-probesize 1024', '-i "rtsp://192.168.1.10:554/11"', 'test.h264']);
When I capture the stderr, I get a message "Unrecognized option 'probesize 1024'. However, if I run ffmpeg from the command line, it works fine. So I need to see exactly how the command-line options are being mangled before being sent to FFMPEG in order to debug this.
Thanks
Try
var p = s.spawn('ffmpeg', [
'-probesize',
'1024',
'-i',
'rtsp://192.168.1.10:554/11',
'test.h264'
]);
Command line arguments that have a space between them but are coherent, still need to be separated. So there's needs to be a space between -probesize and 1024
Update
If you would like to keep the coherent arguments together, add shell: true to the options object:
var p = s.spawn('ffmpeg',
[
'-probesize 1024',
'-i "rtsp://192.168.1.10:554/11"',
'test.h264'
],
{
shell: true
}
);
Old question I know...but one idea I had, which might answer the OP's question
const cp = require('child_process');
var sp = cp.spawn( 'cmd', [ '/C' , 'echo', 'ffmpeg',
'-probesize',
'1024',
'-i',
'rtsp://192.168.1.10:554/11',
'test.h264'
]);
sp.stdout.on( "data" , (d) => {
console.log( `${d}`);
});
which will echo the cmd to the console...
ffmpeg -probesize 1024 -i rtsp://192.168.1.10:554/11 test.h264

ffmpeg throwing "errorMessage": "spawn ffmpeg ENOENT"

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}));
}
);
}

Open apps using node.js spawn

I'm trying to do a little application with node.js that would run on mac and execute some commands.
I've successfully used spawn to run command lines such as xcodebuild, but xcrun doesn't seems to work when I try to open the iOS Simulator.
I can open on terminal by typing:
xcrun instruments -w 'iPhone 5s (9.2)' -t <template>
But if I use node and try to use spawn like this:
var args = ['instruments', '-w', `iPhone 5s (9.2)`, '-t', 'noTemp'];
var xcrun = spawn('xcrun', args);
So it got me thinking that maybe it had some limitation opening apps? I tried to run:
var args = ['/Applications/Spotify.app'];
var xcrun = spawn('open', args);
And nothing happens. I couldn't find anything related to that. My question is: is there anyway to open apps using node.js spawn? If there is, does someone know what's the problem with my code?
Here's the full code if needed:
var args = ['instruments', '-w', `${fullDevice}`, '-t', 'noTemp'];
var xcrun = spawn('xcrun', args);
xcrun.stdout.on('data', (data)=>{
console.log(data.toString('utf8'));
})
xcrun.on('close', (code) => {
socket.emit({
time: commands.getCurrentTime(),
type: 'success',
log: 'Device booted...'
});
callback();
if (code !== 0) {
console.log(`open process exited with code ${code}`);
}
});
OBS: if I run this piece of code the application doesn't terminate, the program doesn't continue and nothing happens.
EDIT: Changed:
xcrun.on('data', (data)=>{
To:
xcrun.stdout.on('data', (data)=>{
Spawned processes have two separate streams for stdout and stderr, so you will need to listen for data on those objects and not the spawned process object itself:
xcrun.stdout.on('data', function(data) {
console.log('stdout: ' + data.toString());
});
xcrun.stderr.on('data', function(data) {
console.log('stderr: ' + data.toString());
});
The problem was one line above. Not sure why, but there's a socket.emit call that is wrong and actually hold the program's execution.

Node.js spawn of Blender command-line?

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!

FFmpeg Stream RTSP input and save to file at the same time using nodejs

I am using node-rtsp-stream module to stream RTSP to web with nodejs.
I am streaming RTSP source with ffmpeg, for example RTSP SOURCE - EXAMPLE
I know that I can save one or many inputs to many outputs but I dont know if there is option to stream the input and save it to file at the same time without executing two process of ffmpeg.
With the following example I am able to stream the RTSP source
ffmpeg -i rtsp-url -rtsp_transport tcp -f mpeg1video -b:v 800k -r 30
On the module is look like that:
this.stream = child_process.spawn("ffmpeg", [ "-i", this.url, "-rtsp_transport", "tcp",'-f', 'mpeg1video', '-b:v', '800k', '-r', '30', '-'], {
detached: false
});
ff =child_process.spawn("ffmpeg", [ "-i", this.url, '-b:v', '800k', '-r', '30', '1.mp4'], {
detached: false
});
this.inputStreamStarted = true;
this.stream.stdout.on('data', function(data) {
return self.emit('mpeg1data', data);
});
this.stream.stderr.on('data', function(data) {
return self.emit('ffmpegError', data);
});
As you can see I am using two process of ffmpeg to do what I want but
If anyone faced with this issue and solve it with one command ( process ), I would like to get some suggestions.
How to stream RTSP source and save it to file at the same time.
for more information about the module I use:
node-rtsp-stream
try the code: (it will read RTSP and save to a jpg file (overwrite it every 3 seconds))
var fs = require('fs');
var spawn = require('child_process').spawn;
var rtspURI = 'rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov';
var fps = 1/3;
//avconv -i rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov \
// -r 1/3 -an -y -update 1 test.jpg
var ffmpeg = spawn('avconv', ['-i',rtspURI,'-r',fps,'-an','-y','-update','1','test.jpg']);
// var ffmpeg = spawn('avconv',
// ['-i','rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov',
// '-r','1/3','-an','-y','-update','1','test.jpg']);
ffmpeg.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
ffmpeg.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
ffmpeg.on('close', function (code) {
console.log('child process exited with code ' + code);
});

Resources