Gagravarr/VorbisJava

Concatenating audio files

Closed this issue · 3 comments

Is there a proper way to concatenate two (or more) independent ogg audio files? Using writeAudioData you will end up with correct file size (sum of all audio files sizes) but you will loose duration. I'm looking through sources and can't find a way to set the overall duration for the output file.

Hoping for advice

Bump!
Very important point!

andrm commented

This library can't do this by itself. It focuses on Ogg which is a container format, the data stream inside of it is encoded with an audio and/or video encoder (opus, vorbis, theora etc). Ogg can "hold" all of these.

If you want to concatenate you have to know at the very least the metadata of the encoded (inner) datastream and remove it from the individual files and add one to the very beginning of the stream.
This library does not have the functionality to do this automatically.

I happen to know opus quite a bit and even concatenating several opus files doesn't seem to be easy to me. Reason: The opus format has a "preskip" which says something like "decode at least n frames before playing audio" to get the decoder in a good state. You also need to make sure it has the same sample rate etc.

From my experience people use usually ffmpeg for that use case which does a full (opus) decode to wav and then re-encodes to opus.

Thanks for the clarification :)