a-schild / jave2

The JAVE (Java Audio Video Encoder) library is Java wrapper on the ffmpeg project
GNU General Public License v3.0
1.27k stars 249 forks source link

Encode to stream feature #221

Open octaviospain opened 1 year ago

octaviospain commented 1 year ago

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

ovistoica commented 1 year ago

I need this also! @octaviospain did you find a workaround for this or ended up using File?

octaviospain commented 1 year ago

@ovistoica no workaround, I have to use a File. Maybe we should study jave2 code and implement this ourselves

a-schild commented 1 year ago

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:

What is the best option depends on your requirements ffmpeg also has the option to stream the outputdata