Extract audio from the flv file and store it in mp3 format

Source: Internet
Author: User
Tags flv file

Some teaching videos have been downloaded from Youku. To put them in mp3, You need to extract audio data from these flv files and store them in mp3 format.

The operating system is centos 5.3.

After searching online, find the following method:
Method 1: Use mencoder, for example, mencoder-of avi-nosound-ovc copy in. flv-o out_just_vid.avi
Method 2: Use mplayer, for example, mplayer-dumpaudio nodame_theme.flv-dumpfile nodame_theme.mp3
Method 3: Use ffmpeg.
For the above three methods, see:

Http://linux.byexamples.com/archives/229/extract-audio-from-video-or-online-stream/

Http://www.linuxquestions.org/questions/linux-desktop-74/copy-mode-extract-of-audio-from-youtube-flv-video-508026/

Here we use ffmpeg, which is very powerful to complete this task.

Ffmpeg Introduction

Ffmpeg home: http://www.ffmpeg.org/index.html
FFmpeg
Is a complete, cross-platform solution to record, convert and
Stream audio and video. It has desLibavcodec
-The leading audio/video
Codec library.

Install ffmpeg

From http:
// Www.ffmpeg.org/releases/ffmpeg-checkout-snapshot.tar.bz2download the ffmpeg's source code. Solution
Press the button and go to the source code directory. install it in three steps (configuer, make, make install). Use./configure.
-- Help: Check the installation configuration options.

Use ffmpeg to extract and convert the audio from the flv File

First, view the FLV file information:
[WHB @ jcwkyl introduction_to_algorithm] $ FFMPEG-I lecture_1.flv
FFmpeg version SVN-r21915, copyright (c) 2000-2010 the FFMPEG developers
Built on Feb 20 2010 18:28:18 with GCC 4.1.2 20071124 (Red Hat 4.1.2-42)
Configuration: -- enable-Encoder = MP3
Libavutil 50. 9. 0/50. 9. 0
Libavcodec 52.54. 0/52.54. 0
Libavformat 52.52. 0/52.52. 0
Libavdevice 52. 2. 0/52. 2. 0
Libswscale 0.10. 0/0.10. 0
[FLV @ 0x8a533a0] estimating duration from bitrate, this may be inaccurate

Seems stream 0 codec frame rate differs from container frame rate: 2000.00 (2000/1)-> 15.00 (15/1)
Input #0, FLV, from 'cture _ 1. flv ':
Metadata:
Duration: 4835
Starttime: 0
Totalduration: 4835
Width: 320
Height: 240
Videodatarate: 196
Audiodatarate: 63
Totaldataarate: 264
Framerate: 15
Bytelength: 159348112
Canseekontime: True
Sourcedata: CiaMM
Purl:
Pmsg:
Duration: 01:20:35. 06, start: 0.000000, bitrate: 200 kb/s
Stream #0.0: Video: h264, yuv420p, 320x240 [par dar], 200 kb/s, 15 tbr, 1 k tbn, 2 k tbc

Stream #0.1: Audio: aac, 22050Hz, stereo, s16

At least one output file must be specified

The above two lines marked in red show the various attributes of the video and audio data of the file. The audio data uses aac encoding. Here, you need to convert the audio into mp3 format, therefore, aac decoder and mp3 encoder are required.
Check whether ffmpeg has these tools.
[Whb @ jcwkyl introduction_to_algorithm] $ ffmpeg-codecs | grep aac
FFmpeg version SVN-r21915, Copyright (c) 2000-2010 the FFmpeg developers
Built on Feb 20 2010 18:28:18 with gcc 4.1.2 20071124 (Red Hat 4.1.2-42)
Configuration: -- enable-encoder = mp3
Libavutil 50. 9. 0/50. 9. 0
Libavcodec 52.54. 0/52.54. 0
Libavformat 52.52. 0/52.52. 0
Libavdevice 52. 2. 0/52. 2. 0
Libswscale 0.10. 0/0.10. 0
DEA aac Advanced Audio Coding

D Indicates decoder, E Indicates encoder, and A indicates Audio Codec. Both aac encoding and decoder exist.
Check whether the mp3 encoder is provided. Similarly, use the command ffmpeg-codecs. In the output result, only the mp2 encoder is found, but the mp3 encoder is not:
[Whb @ jcwkyl introduction_to_algorithm] $ ffmpeg-codecs
......
D a mp1 MP1 (MPEG audio layer 1)
DEA mp2 MP2 (MPEG audio layer 2)
D a mp3 MP3 (MPEG audio layer 3)
......
So first try to use the mp2 encoder for conversion:
[Whb @ jcwkyl introduction_to_algorithm] $ ffmpeg-I Lecture_1.flv-f mp2-vn Lecture_1.mp3
In this command,-I indicates the input file,-f indicates the output format,-vn indicates "vedio not", that is, the video output is disabled, and the last file to be converted is lecture_1.mp3.
After the conversion is complete, use the filecommand lecture_1.mp3 file format:
[Whb @ jcwkyl introduction_to_algorithm] $ file Lecture_1.mp3
Lecture_1.mp3: mpeg adts, layer II, v2, 64 kBits, 22.05 kHz, Stereo
File size comparison before and after conversion:
[Whb @ jcwkyl introduction_to_algorithm] $ du-hs Lecture_1 .*
153 M Lecture_1.flv
37 M Lecture_1.mp3

Use lelecture_1.mp3, which is completely normal.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.