2

I am using ffmpeg without using fluent-ffmpeg. I am using 'child_process' from node.

First of all I verified how can I pass more than one arguments to the child process command. and I verified it given below code.

I used copy command like this

cp vid1.mp4 vid2.mp4

which successfully copied vid1 into vid2.

const execFile = require('child_process').execFile;
const child = execFile('cp', ['vid1.mp4', 'vid3.mp4'], (error, stdout, stderr) => {
    if (error) {
        console.error('stderr: =============================', stderr);
        throw error;
    }
    console.log('stdout: ==========================', stdout);
});

console.log('here');

Above code is content of the 'index.js'(default entry point in node). And running this with node . , which copies vid1 into vid3 successfully.

Now, I want to do watermarking to the given video. For that I am using this tutorial. Currently link to the actual tutorial is broken, you can see it here.

This is the command that I am using

ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=10:10" output.mp4

Now the same command I am using like this ,

const execFile = require('child_process').execFile;

const child = execFile('ffmpeg', ['-i', 'input.mp4' , '-i' , 'logo.png' , '-filter_complex' , '"overlay=10:10"' , 'output.mp4' ], (error, stdout, stderr) => {
    if (error) {
        console.error('stderr: =============================', stderr);
        throw error;
    }
    console.log('stdout: ==========================', stdout);
});

console.log('here');

and I am getting an error , that ,

No such filter: '"overlay' Error initializing complex filters. Invalid argument

/Users/neerpatel/Desktop/testProjects/childProcess/index.js:7 throw error; ^

Error: Command failed: ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=10:10" output.mp4

You can clearly see that the same command that runs in terminal directly, doesn't work when I pass it in child process. Why does it happen ?

Moreover, I wanted to add tag 'watermarking' , but I can't create tag since my reputation is below 1500. please, someone do it.

UPDATE : I used EXEC , instead of execFile . and it worked like charm, but parent file kept waiting for child process. Child process never returns END signal. and this is my code.

const exec = require('child_process').exec;

const child = exec('ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=10:10" output.mp4', (error, stdout, stderr) => {
    if (error) {
        console.error('stderr: =============================', stderr);
        throw error;
    }
    console.log('stdout: ==========================', stdout);
});

console.log('here');
5
  • can someone mention user stackoverflow.com/users/5726027/gyan he usually helps everyone with queries related to ffmpeg. Commented May 15, 2018 at 13:33
  • 2
    Did you notice that the error message refers to the filter as "overlay? The value option to filter_complex doesn't require quotes unless it has a space. Try w/o quotes, e.g. [..., '-filter_complex', 'overlay=10:10', ...] or simply [..., '-filter_complex overlay=10:10', ...] Commented May 15, 2018 at 14:03
  • @marekful , if I type in the command shown like >>> ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=10:10" output.mp4 <<< , it gives me correct output. and you can see that my system says ::: Command failed for : ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=10:10" output.mp4 ... why so ? Commented May 16, 2018 at 4:44
  • It is weird but not unprecedented or something you should spend too much time thinking on. May be a bug in Node but obviously there's a difference in how the terminal and Node's child_process.exec interpret/handle quotes in strings. Commented May 16, 2018 at 10:34
  • thanks for ur help @marekful Commented May 16, 2018 at 11:15

1 Answer 1

3

finally found out solution , As marekful suggested, the problem was in "overlay=10:10" string ,

so I took another variable str = "overlay=10:10" , and passed that as argument, and it worked like charm.

thanks Marekful.

const execFile = require('child_process').execFile;
const str = "overlay=10:10";
const child = execFile('ffmpeg', ['-i', 'input.mp4' , '-i' , 'logo.png' , '-filter_complex' , str , 'output.mp4' ], (error, stdout, stderr) => {
    if (error) {
        console.error('stderr: =============================', stderr);
        throw error;
    }
    console.log('stdout: ==========================', stdout);
});

console.log('here');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.