0

I have some ffmpeg processes running in order and all writing into one stream (fs.createWriteStream).

Is it possible to delete the data read through fs.createReadStream from the file?

I want to run the script 24/7 and want the stream to act like a buffer.

Thanks in advance!

Henry
  • 15
  • 1
  • 8
  • I don't understand what you want to achieve. Do you want to delete data into file? – TGrif Feb 17 '18 at 21:31
  • I am opening a stream with fs.createWriteStream (file.mp3). Then I pipe the output of some ffmpeg instances into that and the file gets really big after some time which I want to prevent by deleting the content I already read out of the mp3 file (it's an audio livestream) @TGrif – Henry Feb 17 '18 at 21:42
  • So why don't you stream data directly without writing to a file ? – TGrif Feb 17 '18 at 21:52
  • Because I see no possibility to "append" inputs to a running ffmpeg instance. This way I can append audio while the stream is running. – Henry Feb 17 '18 at 21:59

1 Answers1

0

You can actually "append data" to running ffmpeg instance - or any other writable stream. To make this possible, you need to use this option for pipe:

myFile.pipe(ffmpegRunner, {end: false});

This will tell pipe to not notify the ffmpeg that the file has ended. Then, you can switch the files once the first one ends:

myFile.on("end", () => {
    myFile.unpipe(ffmpegRunner);
    anotherFile.pipe(ffmpegRunner, {end: false});
});

You can do that even before the stream ends I guess.

Giulio Bambini
  • 4,695
  • 4
  • 21
  • 36
  • To the OP, if you use this method, the files you feed ffmpeg should be either raw streams (like .mp3) or containers without global headers, like MPEG-TS. – Gyan Feb 18 '18 at 05:07
  • Let me get this straight: myFile is a stream created with fs.createWriteStream() and ffmpegRunner is the ffmpeg instance? Because [here](https://github.com/fluent-ffmpeg/node-fluent-ffmpeg#pipestream-options-pipe-the-output-to-a-writable-stream) it says ffmpegRunner.pipe(stream, options)... – Henry Feb 18 '18 at 13:16
  • Also I use .input(stream) for the instance running 24/7, how will I be able to switch files doing this? – Henry Feb 18 '18 at 13:20
  • I managed to solve this using the second example at the link I posted, just needed to fiddle around with some stuff... Thanks anyways! :) – Henry Feb 18 '18 at 15:55