I was trying to conver audio formats to ogg ( vorbis ) file using Xuggler.
First, i've attemted the very basic way to do it,
IMediaReader readermp3 = ToolFactory.makeReader(sourcefile);
IMediaWriter writer = ToolFactory.makeWriter(targetfilemp3, readermp3);
readermp3.addListener(writer);
while (readermp3.readPacket() == null)
targetfile ended with .ogg. This actually works, however it encodes to ogg FLAC instead of ogg vorbis.
Then i've tried to do some of its parts manually,
First - Get the original sample rate and channel number, Second - addaudiostream using these sample rate,channel number AND Codec id for vorbis.
IMediaReader readermp3 = ToolFactory.makeReader(sourcefile);
IContainer readercontainer = readermp3.getContainer();
readercontainer.open(sourcefile, IContainer.Type.READ,null);
int numStreams = readercontainer.getNumStreams();
IStream stream = null;
for(int i = 0; i < numStreams; i++) {
stream = readercontainer.getStream(i); }
IStreamCoder mycoder = stream.getStreamCoder();
int sourcechannels,sourcesamplerate;
sourcechannels = mycoder.getChannels();
sourcesamplerate = mycoder.getSampleRate();
/* these were for getting samplerate and channels i don't think they are relevant but im */copying it here just incase
IMediaWriter writer = ToolFactory.makeWriter(targetfilemp3, readermp3);
writer.addAudioStream(0, 0,ICodec.ID.CODEC_ID_VORBIS,sourcechannels, sourcesamplerate);
readermp3.addListener(writer);
while (readermp3.readPacket() == null)
;
When i try to run this, it gives me an error "ERROR org.ffmpeg - [libvorbis @ 0436F300] Specified sample_fmt is not supported." "WARN com.xuggle.xuggler - Error: could not open codec (../../../../../../../csrc/com/xuggle/xuggler/StreamCoder.cpp:831)"
Sidenote = it works with mp3,wav and flac ogg file. Also, i have tried changing my extension to .vorbis instead of .ogg. Still the same error.
Then ofcourse, i googled it. There is only 1 relevant q/a about this issue https://groups.google.com/forum/?fromgroups=#!topic/xuggler-users/18hsI_LGxI4
however, i didn't understand the answer =).
Thanks a lot for the answers.