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

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

有人能帮忙吗?


当前回答

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

其他回答

似乎你正在从视频文件中提取音频,并将其降至立体声频道。 只提取音频(不重新编码):

ffmpeg.exe -i in.mp4 -vn -c:a copy out.m4a

提取音频和混音到立体声(无需重新编码):

ffmpeg.exe -i in.mp4 -vn -c:a copy -ac 2 out.m4a

要生成一个mp3文件,你需要重新编码音频:

ffmpeg.exe -i in.mp4 -vn -ac 2 out.mp3

-c(选择codecs) & -map(选择流)选项:

-c:a ->选择最佳支持的音频(转码) ->最好支持的音频(复制) -map 0:a ->所有音频从第一个(音频)输入文件(转码) -map 0:0 ->第一个输入文件的第一个流(转码) -map 1:a:0 ->第一个音频流从第2(音频)输入文件(转码) -map 1:a:1 -c:a copy ->第2个音频流从第2(音频)输入文件(复制)

这是我刚才用的:

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

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

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

通常

ffmpeg -formats

or

ffmpeg -codecs

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

提取音频流,不需要重新编码。

ffmpeg -i input-video.avi -vn -acodec copy output-audio.aac

-vn是no video。 -acodec copy表示使用已经存在的相同音频流。

读取输出,看看它是什么编解码器,以设置正确的文件名扩展名。