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;
 for(i=0;i<inputArray.length;i++){
 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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...