OK, I at least got the IMediaWriter to work with a little tweaking by doing the following upon creating it:
IAudioResampler oggResampler = IAudioResampler.make(2, audioCoder.getChannels(), audioCoder.getSampleRate(), IAudioSamples.Format.FMT_FLT, audioCoder.getSampleFormat());
IMediaWriter oggWriter = ToolFactory.makeWriter("out.ogg");
oggWriter.addAudioStream(0, 0, ICodec.ID.CODEC_ID_VORBIS, oggResampler.getOutputChannels(), oggResampler.getOutputRate());
oggWriter.getContainer().getStream(0).getStreamCoder().setSampleFormat(IAudioSamples.Format.FMT_FLT);
Strange that I have to manually set the sample format in the IContainer but at least that works. Then I read in a video with an IMediaReader and do the following in the listener:
public void onAudioSamples(IAudioSamplesEvent e) {
if (pVidParam.hasAudio) {
IAudioSamples inSamples = e.getAudioSamples();
long numSamples = inSamples.getNumSamples();
IAudioSamples outSamples = IAudioSamples.make(numSamples, resampler.getOutputChannels());
IAudioSamples outSamplesOGG = IAudioSamples.make(numSamples, resamplerOGG.getOutputChannels(), IAudioSamples.Format.FMT_FLT);
resampler.resample(outSamples, inSamples, numSamples);
resamplerOGG.resample(outSamplesOGG, inSamples, numSamples);
mp3Writer.encodeAudio(0, outSamples);
oggWriter.encodeAudio(0, outSamplesOGG);
}
}
The ogg file that is output though is still not correct. It seems like all of the audio data is there because it plays fine start to finish. However, any of the oggs I generate will cause vlc to choke somewhat, The time slider doesn't seem to be synced properly and the total time is incorrect. This seems to indicate that the header isn't being properly written.
I have a feeling that tweaking some more things using the StreamCoder like I did above will solve the issue but the things I've changed so far have had no effect. Any advice here?
Thanks