Gagravarr / VorbisJava

A library for working with Ogg Vorbis files
Apache License 2.0
126 stars 26 forks source link

Concatenating audio files #22

Closed RostMyr closed 6 years ago

RostMyr commented 7 years ago

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

mchukd commented 6 years ago

Bump! Very important point!

andrm commented 6 years ago

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.

RostMyr commented 6 years ago

Thanks for the clarification :)