2015-06-25 187 views
0

我正在研究一款可以下载不同格式的视频的android应用程序。如何从视频中提取音频

现在我想从下载的视频文件或可用的视频链接中提取音频。 有什么办法通过以下任一方法

1.extract音频直接从视频文件链接

,以从视频中提取音频2.is有任何库,适用于Android版从视频文件中提取音频

感谢您的时间!

+1

任何downvote原因是什么? – xtr

回答

1

您可以使用称为JAVE(Java音频视频编码器)的库将视频编码为音频文件。

  1. here下载JAVE。
  2. 参考下面的代码片段编码从MP4到MP3

代码:

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

重要提示是,JAVE是'ffmpeg'上的Java包装。 –

+1

我已经下载了这个jave,告诉我如何将它包含在Android studio中? –