Search code examples
javaaudioxuggle

Audio playing too fast


If any of my fellow Xuggler users can tell me what I'm doing wrong, that would be awesome! I am doing the following:

  1. Reading from ogv (ogg video)
  2. Queueing the audio and video
  3. Writing back to ogv

sounds simple right? The problem I am experiencing in my QueueMixer class is that the output file plays the audio 2x too fast, and no matter what I check or change with regards to pts it doesnt improve.

The eclipse project and all files being used are at this link: http://dl.dropbox.com/u/7316897/paul-xuggled.zip

To run a test, compile and execute the StreamManager class; a test ogv file is included. Before anyone asks, yes I have to queue the data as it will be mixed with other data in a future version.


Solution

  • The fix is to multiply the sample count by two when extracting them from the ShortBuffer.

    samples = new short[(int) audioSamples.getNumSamples() * 2];
    audioSamples.getByteBuffer().asShortBuffer().get(samples);
    
    Having half the samples causes the audio to play twice as fast.