xuggler

how to extract audio from video using xuggler?


i am trying to make an audio file (*.mp3 , .wav etc) from a video file (.avi,*.mp4 etc) using xuggler here is my code

Code:
IMediaReader reader = ToolFactory.makeReader("D:/Frames/my.mp4");
IMediaWriter writer = ToolFactory.makeWriter("D:/a.mp3",reader);
int sampleRate = 44100;
int channels = 1;
writer.addAudioStream(0, 0, ICodec.ID.CODEC_ID_MP3, channels, sampleRate);
while (reader.readPacket() == null);

but its not create an audio file for me. please guide me where i am doing wrong. if you will correct it or provide some other code for this purpose which is different from mine then i'll be thankful.


Solution

  • after searching a lot on internet about this problem i have found that i can do this same work with JAVE (Java Audio Video Encoder) so i try that and it works for me ..so i thought i post the solution there that if some one else face the same problem then he/she can see my work.

    its actually use ffmpeg behind the scene and it will extract audio from video file and much more for encoding stuff. here is the link for JAVE http://www.sauronsoftware.it/projects/jave/index.php

    also see one example there and i am posting it here also for your convenience

    File source = new File("source.mp4");
    File target = new File("target.mp3");
    AudioAttributes audio = new AudioAttributes();
    audio.setCodec("libmp3lame");
    audio.setBitRate(new Integer(128000));
    audio.setChannels(new Integer(2));
    audio.setSamplingRate(new Integer(44100));
    EncodingAttributes attrs = new EncodingAttributes();
    attrs.setFormat("mp3");
    attrs.setAudioAttributes(audio);
    Encoder encoder = new Encoder();
    encoder.encode(source, target, attrs); 
    

    hopefully it will help u..!