Chinaunix首页 | 论坛 | 博客
  • 博客访问: 116072
  • 博文数量: 67
  • 博客积分: 1584
  • 博客等级: 中校
  • 技术积分: 595
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-17 09:58
文章分类

全部博文(67)

文章存档

2012年(1)

2011年(62)

2010年(4)

分类: LINUX

2011-04-10 22:40:01

在优酷上下载了一些教学视频,为了把它们放到mp3里面,需要从这些flv文件中提取出音频数据并存储为mp3格式。

操作系统是centos 5.3。

在网上搜索了一下,找到以下方法:
方法一:使用mencoder,例如:mencoder -of avi -nosound -ovc copy in.flv -o out_just_vid.avi
方法二:使用mplayer,例如:mplayer -dumpaudio nodame_theme.flv -dumpfile nodame_theme.mp3
方法三:使用ffmpeg。
以上三种方法,可参看:



这里使用功能非常强大的ffmpeg来完成这项任务。
ffmpeg简介

ffmpeg的首页:
FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video. It includes libavcodec - the leading audio/video codec library.
ffmpeg安装

从http: //下载ffmpeg的源代码。解 压后进入源代码目录,三步走(configuer, make, make install)来安装它,使用./configure --help看具体的安装配置选项。
使用ffmpeg从flv文件中提取音频并转换

首先查看flv文件的信息:
[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 'Lecture_1.flv':
Metadata:
duration : 4835
starttime : 0
totalduration : 4835
width : 320
height : 240
videodatarate : 196
audiodatarate : 63
totaldatarate : 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 1:1 DAR 4:3], 200 kb/s, 15 tbr, 1k tbn, 2k tbc
Stream #0.1: Audio: aac, 22050 Hz, stereo, s16
At least one output file must be specified

上面输出中用红色标记的两行显示出这个文件的视频和音频数据的各种属性,其中音频数据使用的是aac编码,这里需要把音频转换成mp3格式,所以需要aac的解码器和mp3的编码器。
查看ffmpeg是否有这些工具。
[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表示decoder,E表示encoder,A表示Audio Codec。aac的编码解码器都存在。
再来查看是否提供了mp3的编码器,同样使用命令:ffmpeg -codecs,在输出结果中发现只有mp2的编码器,而没有mp3编码器:
[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)
......
所以先试着使用mp2编码器进行转换:
[whb@jcwkyl introduction_to_algorithm]$ ffmpeg -i Lecture_1.flv -f mp2 -vn Lecture_1.mp3
这条命令中,-i表示input file,-f表示输出格式,-vn表示“vedio not",即禁止视频输出,最后转换后的文件是Lecture_1.mp3。
转换完成后,使用file命令查看Lecture_1.mp3的文件格式:
[whb@jcwkyl introduction_to_algorithm]$ file Lecture_1.mp3
Lecture_1.mp3: MPEG ADTS, layer II, v2, 64 kBits, 22.05 kHz, Stereo
转换前后文件大小对比:
[whb@jcwkyl introduction_to_algorithm]$ du -hs Lecture_1.*
153M Lecture_1.flv
37M Lecture_1.mp3

使用播放器播放Lecture_1.mp3,完全正常。
阅读(1063) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~