我尝试了以下命令从视频中提取音频:

ffmpeg -i Sample.avi -vn -ar 44100 -ac 2 -ab 192k -f mp3 Sample.mp3

但我得到了如下的输出

libavutil     50.15. 1 / 50.15. 1
libavcodec    52.72. 2 / 52.72. 2
libavformat   52.64. 2 / 52.64. 2
libavdevice   52. 2. 0 / 52. 2. 0
libavfilter    1.19. 0 /  1.19. 0
libswscale     0.11. 0 /  0.11. 0
libpostproc   51. 2. 0 / 51. 2. 0
SamplE.avi: Invalid data found when processing input

有人能帮忙吗?


当前回答

使用-b:a代替-ab,因为-ab现在已经过时了,还要确保输入的文件路径是正确的。

从视频中提取音频,我已经使用下面的命令和它的工作良好。

String[] complexCommand = {"-y", "-i", inputFileAbsolutePath, "-vn", "-ar", "44100", "-ac", "2", "-b:a", "256k", "-f", "mp3", outputFileAbsolutePath};

在这里,

-y -覆盖输出文件而不询问。 -i - FFmpeg从-i选项指定的任意数量的输入“文件”中读取 -vn -关闭录像功能 -ar -设置音频流编码时的采样率 -ac -设置音频通道数。 -b:a—设置音频比特率 -f - format

在GitHub上查看我完整的FFmpeg android项目示例。

其他回答

Ffmpeg -i sample。Avi将为您的文件提供音频/视频格式信息。确保配置了正确的库来解析输入流。另外,要确保文件没有损坏。

要编码mp3音频,ffmpeg.org显示了以下示例:

ffmpeg -i input.wav -codec:a libmp3lame -qscale:a 2 output.mp3

我只是通过将input.wav替换为视频文件名来从视频中提取音频。2表示190 kb/秒。您可以在上面的链接中看到其他质量级别。

命令行是正确的,工作在一个有效的视频文件。我会确保你已经安装了正确的库工作与mp3,安装蹩脚o探头与另一个音频编解码器。

通常

ffmpeg -formats

or

ffmpeg -codecs

会提供足够的信息让你知道更多。

如果封装到avi中的音频一开始就不是mp3格式,您可能需要指定-acodec mp3作为附加参数。或者不管你的mp3编解码器是什么(在Linux系统上可能是-acodec libmp3lame)。您还可以通过指定-f mp3来“强制”将格式转换为mp3,从而获得与平台无关的相同效果,尽管不是所有版本的ffmpeg仍然支持这种切换。你的里程可能会有所不同。

这是我刚才用的:

ffmpeg -i my.mkv -map 0:3 -vn -b:a 320k my.mp3

选项的解释:

my.mkv is a source video file, you can use other formats as well -map 0:3 means I want 3rd stream from video file. Put your N there - video files often has multiple audio streams; you can omit it or use -map 0:a to take the default audio stream. Run ffprobe my.mkv to see what streams does the video file have. my.mp3 is a target audio filename, and ffmpeg figures out I want an MP3 from its extension. In my case the source audio stream is ac3 DTS and just copying wasn't what I wanted 320k is a desired target bitrate -vn means I don't want video in target file