jave2
jave2 copied to clipboard
Encode to stream feature
Instead of encoding to a file and waiting for the process to complete, a nice feature would be to do the encoding to a stream of bytes so that audio manipulation can be chained and more efficient without the need to write the file to disk.
For instance using a BufferedInputStream as destination instead of a File
would look like:
// Create the BufferedInputStream from an audio file to encode
BufferedInputStream buffer = new BufferInputStream(new File("/path/to/audio.flac");
Encoder encoder = new Encoder();
encoder.encode(new MultimetiaObject(sourceFile, buffer, attributes);
// so that the encoding can be processed in a 'reactive' way
BufferedInputStream bufferedInputStream = new BufferedInputStream(null).;
while (bufferedInputStream.available() > 0) {
val bytes = bufferedInputStream.read();
...
// cool stuff, maybe feed the bytes to a media player, or create a waveform on the fly
// all while the output goes to the file
}
Or even better, using PipedOutputStream
that can do the same but without the need to write into file and at the same time to the same code as the one above.
FFmpeg can write to UNIX pipes as described here
I need this also! @octaviospain did you find a workaround for this or ended up using File
?
@ovistoica no workaround, I have to use a File
. Maybe we should study jave2 code and implement this ourselves
Jav2 is starting the ffmpeg executabe, and it is writing the output to a file.
I see two potential solutions for the request you have:
- tell ffmpeg to write the content to a pipe, something like this https://stackoverflow.com/questions/32584220/how-to-make-ffmpeg-write-its-output-to-a-named-pipe Not sure how we can handle this platform independent and I have never used pipes from/in java, but I think this would be simplest way to implent it
- The other way would be to use the streaming capability of ffmpeg (if it's what you wish) https://stackoverflow.com/questions/24017930/how-to-stream-with-ffmpeg-via-http-protocol But then you will need to dinamically assign free tcp ports and add a listener which then reads the stream from there
What is the best option depends on your requirements ffmpeg also has the option to stream the outputdata