下载了一堆flv的MTV,无法导入iTunes,iTunes只识别mp4格式的视频,于是准备用ffmpeg把flv转换成mp4。
网上一搜,其实ffmpeg官网给出了非常详细的在Mac上编译ffmpeg的步骤:
http://ffmpeg.org/trac/ffmpeg/wiki/MacOSXCompilationGuide
1) 安装XCode
首先,必须安装XCode,XCode提供了Mac平台开发环境必须的gcc编译器,要注意的是XCode 4.5安装后并没有命令行的gcc可用,还需要打开XCode,在某个设置里添加Command Line Tools,XCode就会自动下载并安装好gcc,同时还有git也被安装了。
2) 安装homebrew
然后安装homebrew,这是一个Mac平台的包管理工具,类似Debian/Ubuntu的apt,提供了许多Mac没有的Unix/Linux工具,例如wget。安装homebrew很简单:
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
3) 安装相关包
ffmpeg需要的依赖包几乎都可以通过brew install安装:
brew install automake celt faac fdk-aac lame libass libtool libvorbis libvpx libvo-aacenc opencore-amr openjpeg opus sdl schroedinger shtool speex texi2html theora wget x264 xvid yasm
官网的命令行多了一个git,这个XCode自带,没必要再装了。
4) 安装libaacplus
这个包没法通过homebrew安装,所以只能自己下载安装,官网有一个详细的命令行步骤:
wget http://217.20.164.161/~tipok/aacplus/libaacplus-2.0.2.tar.gz
tar xzf libaacplus-2.0.2.tar.gz
cd libaacplus-2.0.2
# libtool on osx is quite different from the gnu libtool, which is called glibtool on osx
sed -i '.bck' -e 's/libtool/glibtool/' autogen.sh
./autogen.sh
make && make install
cd ..
5) 编译ffmpeg
直接按照官网的命令行编译,报ERROR: libopenjpeg not found,其实openjpeg是安装了的,只是没找到相应的头文件,网上google,一个国外网友给出了简单解决方案:
首先,确定openjpeg的安装目录在/usr/local/Cellar/openjpeg/1.5.1,然后,把相应的路径加入到gcc的搜索路径中:
export CFLAGS="-I/usr/local/Cellar/openjpeg/1.5.1/include/openjpeg-1.5"
然后开始编译:
git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg
./configure --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libaacplus --enable-libass --enable-libcelt --enable-libfaac --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-openssl --enable-libopus --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvo-aacenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --prefix=/usr/local
make && make install
运行ffmpeg,输出如下:
ffmpeg version N-48064-gcfa5300 Copyright (c) 2000-2012 the FFmpeg developers
built on Dec 21 2012 10:24:39 with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postpr
oc --enable-libaacplus --enable-libass --enable-libcelt --enable-libfaac --enabl
e-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-libopenjpeg --enable-openssl --enable-libop
us --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvo
-aacenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --
prefix=/usr/local
libavutil 52. 12.100 / 52. 12.100
libavcodec 54. 81.100 / 54. 81.100
libavformat 54. 49.102 / 54. 49.102
libavdevice 54. 3.102 / 54. 3.102
libavfilter 3. 29.100 / 3. 29.100
libswscale 2. 1.103 / 2. 1.103
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfi
le}...
Use -h to get full help or, even better, run 'man ffmpeg'
现在,可以找一个flv文件测试,把它转换成mp4:
ffmpeg -i psy-style.flv -vcodec copy -acodec copy psy-style.mp4
由于用了copy模式,ffmpeg不会重新转码,原有画质不变,只是把文件封装从flv变为mp4,瞬间就可完成。