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

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

有人能帮忙吗?


当前回答

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

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

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

其他回答

要编码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

对于寻找更简单的方法从视频文件中提取音频,同时保留原始视频文件的参数的人,您可以使用:

ffmpeg -i <video_file_name.extension> <audio_file_name.extension>

例如,运行:

ffmpeg -i screencap.mov screencap.mp3

从mov视频文件中提取mp3音频文件。