Jump to content

child_process and async/await


Recommended Posts

I want to feed some input files stored in an array to a ffmpeg childprocess , but it needs to be asynchronous because I want to capture std.err live. However I need to feed one input at a time waiting for the previous one to finish. I think I need to use promises or async await but I cannot work out how. my code (simplified) is:

var inputArray =['"'+"firstFile"+'"' ,'"'+"secondFile"+'"' ,'"'+"third"+'"' ];
 var spawn = require('child_process').spawn;
 child = spawn("ffmpeg",["-y", "-i",inputArray[i],+i+".ts"],{ shell: true});
 child.stderr.on('data', function (fdata) {
 var datastring = fdata.toString(), lines = datastring.split(/(\r?\n)/g);
    for (var b=0; b<lines.length; b++) {
        document.getElementById("show").innerHTML = lines[b];
    child.on('exit',  function (code) {
        console.log("code "+i+" "+ code);

Thanks in advance

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...