如果您希望从Flash 视频(Flash Video)文件(FLV格式)中提取音频,有几个选项可用。不幸的是,他们中的许多人为您做出的选择是将音频流编码为不同的格式。在某些情况下,这不是问题,但如果您试图保持音频与视频中的内容相同,那么您需要将音频提取到一个片段中的东西。 FFmpeg是一个适用于(FFmpeg)Linux、Mac和Windows的多媒体工具包,可以轻松做到这一点。
下面的示例适用于Linux,但是一旦您将其安装在Windows或Mac上,您就可以运行如下所示的相同命令。
下载并安装 FFmpeg
首先,您需要下载并安装FFmpeg。大多数发行版的软件存储库中都有FFmpeg,尽管出于软件专利的原因,可能已经取消了一些支持。 无论如何(Regardless),为了我们的目的,一个相当简单的FFmpeg版本就可以了。在Ubuntu中,您只需要在终端中使用以下命令:
该命令还将安装相当多的额外库(连同FFmpeg),这些库是设备、格式和过滤器支持所需的。
从 FLV 文件中提取音频
安装后,使用FFmpeg非常简单,只要您知道要使用哪些命令即可。有数百种不同的选项,一种在不同情况下使用的特殊语法,其强大的功能和复杂性可能有点让人不知所措。值得庆幸的是,对于我们的工作,FFmpeg非常简单。
我们需要做的第一件事是准确找出我们的FLV文件中使用了哪些编解码器。为此,请打开终端(Terminal)(如果它仍未打开),然后切换到FLV文件所在的目录。在我们的示例中,该文件名为Bohemian_Rhapsody.flv,它位于桌面(Desktop)上。所以要输入的命令是:
这会将终端(Terminal)程序移动到同一目录(在本例中为桌面(Desktop)),因此我们所有的命令都将在那里激活。这很重要,因为如果您告诉程序(如FFmpeg)对文件执行操作,则只有文件不在终端(Terminal)“查找”的位置,那么您将收到错误消息。
现在我们已经使用 cd 将目录更改为Desktop,我们需要输入以下命令:
注意:如果您在本教程中尝试此操作,请在每次看到命令中使用的文件名时替换它。(Note: if you’re trying this along with the tutorial, substitute the name of your file each time you see it used in the commands.)
上面的命令有点小技巧,你会得到错误,但不要担心。我们实际上告诉 ffmpeg 的是Bohemian_Rhapsody.flv是输入文件。这就是“-i”告诉 ffmpeg 的内容。
当我们在命令后按 Enter 时,我们并没有告诉 ffmpeg 确切地对文件做什么,所以它会吐出一个错误。没什么大不了的。忽略它。因为除了错误之外,它还为我们提供了有关文件的信息。我们感兴趣的部分看起来像这样:
以上信息告诉我们以下几点。按顺序,它告诉我们流是使用AAC编码器编码的,它的频率为 44100 Hz(刻录到 CD 的正确采样率),它是立体声的,使用 16 位样本,并且具有比特率107 kb/s。出于提取目的,我们最感兴趣的是该文件具有AAC音频。知道了这一点,我们需要做的就是输入以下命令:
以下是上一个命令的不同部分的作用:
ffmpeg – 启动 FFmpeg
-i Bohemian_Rhapsody.flv – 为FFmpeg提供输入文件的名称
-vn – 告诉FFmpeg忽略视频轨道
-acodec copy – 复制音轨(而不是编码为另一种格式)
Bohemian_Rhapsody.m4a – 名称输出文件的
输入上一个命令后,大约只需要一秒钟左右,您应该会注意到桌面(Desktop)上有一个名为Bohemian_Rhapsody.m4a的新文件,该文件只包含原始(Bohemian_Rhapsody.m4a)FLV文件中 的原始音轨。只需(Just)在您最喜欢的媒体播放器中打开它并聆听以确保一切正常。
就是这么简单。当然,FFmpeg有很多很多其他可用的选项。您可以将音频转码为不同的格式,以上传到手机、MP3播放器或WAV文件。如果需要,您可以操纵原始FLV中的视频,随意调整比特率、采样率和通道数。
也许您稍后会想了解这一点,但现在您肯定知道一件事:使用FFmpeg从(FFmpeg)FLV格式 的文件中提取音频很简单。简单(Simple),快速。
Use FFmpeg To Easily Extract Audio From FLV FIles
If you’re looking to extract the audio frоm Flash Video files (FLV format), there arе a few options aνailable. Unfortunately, the choice many of them makе for you is to encode the audio strеam to a different format. In ѕome сases thіs isn’t a problem, but if you’re trying to keep the audio idеntical to what’s inside the video, then you want somethіng that extracts the audio in one рiece. FFmpeg, a multimedia toolkit for Linux, Mac and Windows, can do this with ease.
The example below will be for Linux, but once you have it installed on Windows or Mac, you can run the same command as shown below.
Download and Install FFmpeg
First you’ll need to download and install FFmpeg. Most distributions have FFmpeg in the software repositories, although some support may have been stripped out of it for software patent reasons. Regardless, for our purposes a fairly plain version of FFmpeg will do. In Ubuntu, you only need to use the following command in the Terminal:
This command will also install quite a few extra libraries (along with FFmpeg), needed for device, format and filter support.
Extracting Audio From FLV Files
Once installed, using FFmpeg is pretty simple, as long as you know which commands to use. There are hundreds of different options, a special syntax to use in different circumstance, and the sheer power and complexity can be a bit overwhelming. Thankfully, for our job, FFmpeg is pretty straightforward.
The first thing we need to do is find out exactly what codecs are used in our FLV file. To do that, open the Terminal (if it isn’t still open), and change to the directory where the FLV file is located. In our example, the file is called Bohemian_Rhapsody.flv and it is located on the Desktop. So the command to type would be:
This moves the Terminal program into the same directory (the Desktop in this case), so all of our commands will be active there. This is important because if you tell a program (like FFmpeg) to act on a file, only the file isn’t where the Terminal is “looking” then you will get errors.
Now that we’ve used cd to change directory to the Desktop, we need to type the following command:
Note: if you’re trying this along with the tutorial, substitute the name of your file each time you see it used in the commands.
The above command is a bit of a hack, and you’ll get errors, but don’t worry. What we’ve actually told ffmpeg is that Bohemian_Rhapsody.flv is the input file. That’s what the “-i” tells ffmpeg.
When we hit Enter after the command, we haven’t told ffmpeg exactly what to do with the file, so it spits out an error. No biggie. Just ignore it. Because along with the error, it also gives us information about the file. The part we’re interested in will look something like this:
The above information tells us the following things. In order, it tells us that the stream is encoded using the AAC encoder, that it has a frequency of 44100 Hz (the correct sampling rate for burning to CD), that it is stereo, uses 16-bit samples, and has a bitrate of 107 kb/s. For extracting purposes, we’re most interested that the file has AAC audio. Knowing this, all we need to do is type the following command:
Here’s what the different parts of the previous command do:
ffmpeg – launches FFmpeg
-i Bohemian_Rhapsody.flv – provides FFmpeg with the name of the input file
-vn – tells FFmpeg to ignore the video track
-acodec copy – copies the audio track (instead of encoding to another format)
Bohemian_Rhapsody.m4a – name of the output file
After typing the previous command, only a second or so should go by, and you should notice a new file on your Desktop, named Bohemian_Rhapsody.m4a, which will contain nothing but the original audio track from the original FLV file. Just open it up in your favorite media player and give a listen to make sure everything is as it should be.
It’s that simple. Of course, FFmpeg has many, many other options available. You can transcode the audio to a different format, for uploading to a cell phone, MP3 player, or WAV file. You can manipulate the video from the original FLV if you want, fool around with the bitrate, sample rate and number of channels.
And maybe you’ll want to learn that later, but for now you know one thing with certainty: it’s simple to use FFmpeg to extract audio from a file in FLV format. Simple, and fast.