Centos搭建FFMPEG环境实现MP4格式转m3u8格式

一、实验环境:centOS

二、步骤

1、使用yum安装ffmpeg的依赖文件

此步骤一般不会有什么问题,就算以前安装过下面的某些软件,也不会重复安装

yum install autoconf automake cmake freetype-devel gcc gcc-c++ git libtool make mercurial nasm pkgconfig zlib-devel -y

2、安装ffmpeg的功能模块

下面这些功能模块是可以选择的,当需要ffmpeg实现这些功能时,就可以选择安装或者不安装,因为我需要实现的是mp4转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

下面这个步骤是官网给出来的,执行下面这个步骤的时候出了个问题,用git命令去拿ffmpeg源码的时候拿不到,可能是跟网络问题,故而我是直接下载最新的版本来用的,我下载的是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文件,执行下面命令

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

成功执行后的显示

[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

参考文章

FFMPEG官网文档
CSDN参考文档

你可能感兴趣的:(Centos搭建FFMPEG环境实现MP4格式转m3u8格式)