一僚祷、實(shí)驗(yàn)環(huán)境:centOS
二酷师、步驟
1、使用yum安裝ffmpeg的依賴文件
此步驟一般不會有什么問題惜浅,就算以前安裝過下面的某些軟件瘫辩,也不會重復(fù)安裝
yum install autoconf automake cmake freetype-devel gcc gcc-c++ git libtool make mercurial nasm pkgconfig zlib-devel -y
2、安裝ffmpeg的功能模塊
下面這些功能模塊是可以選擇的赡矢,當(dāng)需要ffmpeg實(shí)現(xiàn)這些功能時杭朱,就可以選擇安裝或者不安裝,因?yàn)槲倚枰獙?shí)現(xiàn)的是mp4轉(zhuǎn)m3u8格式功能吹散,必須增加libx264模塊
Yasm :yasm是x264和ffmpeg必須要依賴的模塊
cd ~/ffmpeg_sources
git clone --depth 1 git://github.com/yasm/yasm.git
cd yasm
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
make
make install
make distclean
libx264:
cd ~/ffmpeg_sources
git clone --depth 1 git://git.videolan.org/x264
cd x264
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static
make
make install
make distclean
libfdk_aac
cd ~/ffmpeg_sources
git clone --depth 1 git://git.code.sf.net/p/opencore-amr/fdk-aac
cd fdk-aac
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean
libmp3lame
cd ~/ffmpeg_sources
curl -L -O http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar xzvf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --disable-shared --enable-nasm
make
make install
make distclean
libopus
cd ~/ffmpeg_sources
git clone git://git.opus-codec.org/opus.git
cd opus
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean
libogg
cd ~/ffmpeg_sources
curl -O http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz
tar xzvf libogg-1.3.2.tar.gz
cd libogg-1.3.2
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean
libvorbis
cd ~/ffmpeg_sources
curl -O http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz
tar xzvf libvorbis-1.3.4.tar.gz
cd libvorbis-1.3.4
LDFLAGS="-L$HOME/ffmeg_build/lib" CPPFLAGS="-I$HOME/ffmpeg_build/include" ./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean
FFmpeg
下面這個步驟是官網(wǎng)給出來的弧械,執(zhí)行下面這個步驟的時候出了個問題,用git命令去拿ffmpeg源碼的時候拿不到空民,可能是跟網(wǎng)絡(luò)問題刃唐,故而我是直接下載最新的版本來用的,我下載的是2.8.4界轩,其他步驟都是一樣
cd ~/ffmpeg_sources
git clone --depth 1 http://source.ffmpeg.org/git/ffmpeg.git
cd ffmpeg
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --bindir="$HOME/bin" --pkg-config-flags="--static" --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libx264
make
make install
make distclean
hash -r
到這里画饥,ffmpeg就編譯安裝完成了。
三浊猾、測試
我在/tmp/mp4/目錄下面放了一個 test.mp4文件抖甘,執(zhí)行下面命令
cd /tmp/mp4/
ffmpeg -i test.mp4 -c:v libx264 -c:a aac -strict -2 -f hls -hls_time 15 -hls_list_size 0 test.m3u8
成功執(zhí)行后的顯示
[root@dev1 mp4]# ffmpeg -i test.mp4 -c:v libx264 -c:a aac -strict -2 -f hls -hls_time 15 -hls_list_size 0 test.m3u8
ffmpeg version 2.8.4 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-16)
configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --pkg-config-flags=--static --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libx264
libavutil 54. 31.100 / 54. 31.100
libavcodec 56. 60.100 / 56. 60.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 40.101 / 5. 40.101
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101
libpostproc 53. 3.100 / 53. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mp4':
Metadata:
major_brand : mp42
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 2036-02-06 06:28:16
encoder : HandBrake 0.10.2 2015060900
Duration: 00:16:05.32, start: 0.000000, bitrate: 465 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/bt709), 640x360, 299 kb/s, 25 fps, 25 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2036-02-06 06:28:16
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 160 kb/s (default)
Metadata:
creation_time : 2036-02-06 06:28:16
handler_name : Stereo
[libx264 @ 0x31f5020] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
[libx264 @ 0x31f5020] profile High, level 3.0
Output #0, hls, to 'test.m3u8':
Metadata:
major_brand : mp42
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.40.101
Stream #0:0(und): Video: h264 (libx264), yuv420p, 640x360, q=-1--1, 25 fps, 90k tbn, 25 tbc (default)
Metadata:
creation_time : 2036-02-06 06:28:16
handler_name : VideoHandler
encoder : Lavc56.60.100 libx264
Stream #0:1(und): Audio: aac, 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
creation_time : 2036-02-06 06:28:16
handler_name : Stereo
encoder : Lavc56.60.100 aac
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
frame=24127 fps= 46 q=28.0 Lsize=N/A time=00:16:05.32 bitrate=N/A
video:25976kB audio:15628kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[libx264 @ 0x31f5020] frame I:137 Avg QP:16.54 size: 33746
[libx264 @ 0x31f5020] frame P:9202 Avg QP:19.82 size: 1882
[libx264 @ 0x31f5020] frame B:14788 Avg QP:24.10 size: 315
[libx264 @ 0x31f5020] consecutive B-frames: 17.4% 1.8% 2.1% 78.7%
[libx264 @ 0x31f5020] mb I I16..4: 15.5% 23.9% 60.6%
[libx264 @ 0x31f5020] mb P I16..4: 1.5% 3.4% 0.5% P16..4: 19.5% 5.3% 3.5% 0.0% 0.0% skip:66.4%
[libx264 @ 0x31f5020] mb B I16..4: 0.1% 0.2% 0.0% B16..8: 9.8% 1.3% 0.2% direct: 0.5% skip:87.8% L0:42.2% L1:50.1% BI: 7.7%
[libx264 @ 0x31f5020] 8x8 transform intra:54.7% inter:66.4%
[libx264 @ 0x31f5020] coded y,uvDC,uvAC intra: 38.6% 62.1% 31.4% inter: 3.6% 6.4% 1.0%
[libx264 @ 0x31f5020] i16 v,h,dc,p: 29% 36% 17% 18%
[libx264 @ 0x31f5020] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 20% 34% 2% 3% 4% 3% 3% 3%
[libx264 @ 0x31f5020] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 25% 14% 5% 6% 6% 6% 5% 6%
[libx264 @ 0x31f5020] i8c dc,h,v,p: 46% 27% 21% 7%
[libx264 @ 0x31f5020] Weighted P-Frames: Y:1.1% UV:0.8%
[libx264 @ 0x31f5020] ref P L0: 75.2% 10.1% 10.2% 4.5% 0.0%
[libx264 @ 0x31f5020] ref B L0: 89.2% 8.6% 2.2%
[libx264 @ 0x31f5020] ref B L1: 96.1% 3.9%
[libx264 @ 0x31f5020] kb/s:220.50