【问题标题】:how to extract audio from video如何从视频中提取音频
【发布时间】:2015-06-25 04:13:12
【问题描述】:

我正在开发一个可以下载不同格式视频的安卓应用。它做得很好。

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

1.直接从视频文件链接中提取音频

2.有没有适合android从视频文件中提取音频的库

感谢您的宝贵时间!

【问题讨论】:

  • 任何反对的理由?

标签: android video


【解决方案1】:

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

  1. here下载JAVE。
  2. 参考下面的 sn-p 从 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); 

【讨论】:

  • 重要说明 JAVE 是 ffmpeg 上的 Java 包装器。
  • 我已经下载了这个jave,告诉我如何将它包含在Android studio中?
【解决方案2】:

JAVE 基本上是 FFMPEG 的封装,因为这个简单的 FFMPEG 是一个非常大的框架,使用起来也会增加应用程序的大小。我可以通过使用 Android 原生 API(MediaExtractor 和 MediaMuxer)来检查我的要点。从附加的网址: https://gist.github.com/ArsalRaza/132a6e99d59aa80b9861ae368bc786d0

【讨论】:

  • 这只会从视频中删除视频元数据,但文件仍然是视频,只有音频。
猜你喜欢
  • 2011-07-27
  • 2010-10-09
  • 2020-06-26
  • 1970-01-01
  • 2013-07-06
  • 2012-04-12
  • 1970-01-01
  • 2011-01-08
  • 2012-07-10
相关资源
最近更新 更多