3
votes

I am working on an android app that can download videos in different formats.It done perfectly.

Now i want to extract audio from downloaded video file or available video link. Is there any way to extract audio from video by any of the following methods

1.extract audio directly from a video file link

or

2.is there any library that suitable for android to extract audio from a video files

Thanks for your time!

2
any downvote reason? - xtr

2 Answers

3
votes

You can use a library called JAVE (Java Audio Video Encoder) to encode a video into an audio file.

  1. Download JAVE from here.
  2. Refer to the below snippet to encode from MP4 to MP3

Code:

File source = new File("source.mp4");
File target = new File("target.mp3");

AudioAttributes audioAttributes = new AudioAttributes();
audioAttributes.setCodec("libmp3lame")
    .setBitRate(new Integer(128000))
    .setChannels(new Integer(2))
    .setSamplingRate(new Integer(44100));
EncodingAttributes encodingAttributes = new EncodingAttributes();
encodingAttributes.setFormat("mp3")
    .setAudioAttributes(audioAttributes);

Encoder encoder = new Encoder();
encoder.encode(source, target, encodingAttributes); 
2
votes

JAVE is basically a wrapper over FFMPEG, for this simple FFMPEG is a very big framework to use which also increase the app size. I can check a gist of mine performing the thing by using Android native API's (MediaExtractor & MediaMuxer). From the attached URL: https://gist.github.com/ArsalRaza/132a6e99d59aa80b9861ae368bc786d0