I'm trying to get a little ffmpeg converter-service up and running, made pretty good progress so far. But when it comes to spawning the actual ffmpeg process for conversion, i'm hitting a brick wall.
// options.ffmpegopts is an array containing format-specific parameters
var args = [ '-y', '"' + options.targetfile + '"' ];
args = options.ffmpegopts.concat(args);
var ffmpegProc = spawn('ffmpeg ', args);
ffmpegProc.stderr.on('data', function(data) {
console.log('stderr: ' + data);
});
When executing this code, i get the following console output:
stderr: execvp(): No such file or directory
I already checked different node versions (0.4.0, 0.4.2 and 0.5.0-pre) without any effect.
Another really strange behavior is the fact that i have to call spawn including a space ('ffmpeg '
instead of just 'ffmpeg'
). If i omit this space, i get a different error (stderr: "/path/to/my/movie.mpeg": no such file or directory
). When calling ffmpeg directly from the shell, the command sent to child_process.spawn() executes without any problems.
Any hints on that one? I already checked other projects who achieve the same (like node-imagemagick or ffmpeg-node, but the enlightment didn't hit me...
When running my application using strace -fF -o strace.log node server.js
, i can grep the following process spawning calls:
execve("/usr/local/sbin/ffmpeg", ["ffmpeg", "-i", "\"/data/media_dev/test/ORG_mymovi"..., "-sameq", "-ab", "128k", "-ar", "44100", "-b", "512k", "-r", "25", "-s", "320x240", "-f", "flv", ...], [/* 20 vars */]) = -1 ENOENT (No such file or directory)
execve("/usr/local/bin/ffmpeg", ["ffmpeg", "-i", "\"/data/media_dev/test/ORG_mymovi"..., "-sameq", "-ab", "128k", "-ar", "44100", "-b", "512k", "-r", "25", "-s", "320x240", "-f", "flv", ...], [/* 20 vars */]) = -1 ENOENT (No such file or directory)
execve("/usr/sbin/ffmpeg", ["ffmpeg", "-i", "\"/data/media_dev/test/ORG_mymovi"..., "-sameq", "-ab", "128k", "-ar", "44100", "-b", "512k", "-r", "25", "-s", "320x240", "-f", "flv", ...], [/* 20 vars */]) = -1 ENOENT (No such file or directory)
execve("/usr/bin/ffmpeg", ["ffmpeg", "-i", "\"/data/media_dev/test/ORG_mymovi"..., "-sameq", "-ab", "128k", "-ar", "44100", "-b", "512k", "-r", "25", "-s", "320x240", "-f", "flv", ...], [/* 20 vars */]) = 0
After seeing that strangely escaped double quotes on the path, i tried to call ffmpeg without the quotes...worked like a charm. But the problem remains, i need to be able to work with spaces in my paths.
Any suggestions?
Got it working with spaces, a simple inputfile.replace(' ', '\ ')
was enough.
I'd wager money that the space at the end of "ffmpeg "
is the cause of the current problem. A quick little C program will show that:
#include <unistd.h>
int main(int argc, char *argv[]) {
execvp(argv[1], &argv[1]);
perror(argv[0]);
}
gives the following output:
$ ./execvp "ffmpeg"
FFmpeg version 0.6-4:0.6-2ubuntu6, Copyright (c) 2000-2010 the FFmpeg developers
...
$ ./execvp "ffmpeg "
./execvp: No such file or directory
$
I suggest removing the space again, and re-run under strace(1) -fF
. Look for the command that is actually executed, and look to see if the error message about /path/to/my/movie.mpeg
is coming from ffmpeg
or from node.js
.