D
D
Deodatuss2016-04-22 13:19:32
fmpeg
Deodatuss, 2016-04-22 13:19:32

How to keep child_process.stdin permanently open?

Hello. There is a node, there is ffmpeg. You need to convert pieces of video into one as they arrive. That is, at intervals, check whether new ones have appeared and insert them into the queue for conversion.
Actually I start ffmpeg:

var args = ['-i', 'pipe:0', '-f', 'mp4', '-movflags', 'frag_keyframe', 'pipe:1'];
var ffmpeg = spawn('C:/ffmpeg/bin/ffmpeg.exe', args);

I say where to write to the exit.
var output_file = fs.createWriteStream('./compiled/output.mp4');
ffmpeg.stdout.pipe(output_file);

Well, in turn I put the files there:
funtion pipeNewFile(){
    var file = files.shift();
    if(!file){return;}
    var newReadStream = fs.createReadStream(file);
    newReadStream.pipe(ffmpeg.stdin);
    newReadStream.on('end',function(){
        pipeNewFile();
    });
}

The first file is processed normally, but the next one either skips or throws an "Error: write after end" error, depending on where I write pipeNewFile () (I tried a lot of things). In general, the code is not particularly important, I want to know what approaches are there for such a task? So that the streams of reading different files are transferred to the constantly open child_process.stdin (maybe pause, resume will somehow help?) and perceived by them as a continuous stream of reading one file (in fact, these are pieces of one video). Thanks in advance for any help and sorry for the confusion of the question.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2016-04-22
@Deodatuss

https://nodejs.org/api/stream.html#stream_readable...
newReadStream.pipe(ffmpeg.stdin, { end: false });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question