centos6中yum安装ffmpeg

参考地址:http://note.youdao.com/noteshare?id=a15b392a329fcf83bedf50d2a85fffec&sub=E2472051547B4383BE193A3CFA0FDE76

本章中为虚拟环境所以防火墙是关闭的,线上的防火墙可添加或酌情修改

-A INPUT -m state --state NEW -m tcp -p tcp --dport 1935 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

1.升级系统

yum install epel-release -y
yum update -y
reboot

2.环境

[root@localhost ~]# cat /etc/redhat-release  
CentOS release 6.8 (Final) 
[root@localhost ~]# uname -a 
Linux localhost.localdomain 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux 
[root@localhost ~]# hostname -I 
192.168.1.96
[root@localhost ~]# hostname  
localhost.localdomain

3.下载yum依赖包

yum -y install gcc gcc-c++ autoconf automake make  openssl openssl-devel pcre-devel git 

4.nginx-rtmp-module安装

cd /opt
git clone https://github.com/arut/nginx-rtmp-module.git 

5.nginx 安装略,编译时需加上此模块:--add-module=/root/nginx-rtmp-module

6.ffmpeg安装

rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
rpm -Uvh http://li.nux.ro/download/nux/dextop/el6/x86_64/nux-dextop-release-0-2.el6.nux.noarch.rpm

7.安装ffmpeg和ffmpeg开发包

yum install ffmpeg ffmpeg-devel -y  

8.测试
ffmpeg

ffmpeg version 2.6.8 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-16)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-gnutls --enable-ladspa --enable-libass --enable-libdc1394 --enable-libfaac --enable-nonfree --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libx264 --enable-libx265 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
libavutil 54. 20.100 / 54. 20.100
libavcodec 56. 26.100 / 56. 26.100
libavformat 56. 25.101 / 56. 25.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 11.102 / 5. 11.102
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
Use -h to get full help or, even better, run 'man ffmpeg'

9.nginx配置

worker_processes  1; 
 events { 
    worker_connections  1024; 
} 
rtmp {                      #RTMP 服务         此处共添加9行
    server {      
        listen 1935;        #服务端口  
        chunk_size 4096;    #数据传输块的大小 
    application vod { 
        play /opt/video/vod; #视频文件存放位置。需要创建此目录(可放入视频进行播放) 
        } 
    } 
} 
http { 
    include       mime.types; 
    default_type  application/octet-stream; 
    sendfile        on; 
    keepalive_timeout  65; 
    server { 
        listen       80; 
        server_name  localhost; 
        location / { 
            root   html; 
            index  index.html index.htm; 
        } 
        error_page   500 502 503 504  /50x.html; 
        location = /50x.html { 
            root   html; 
        } 
    } 
} 

10.新建存放视频的位置并放视频

mkdir -p /opt/video/vod
/etc/init.d/nginx restart重启nginx服务

11.添加nginx配置两个server并重启服务

events { 
    worker_connections  1024; 
} 
 
rtmp { 
    server {  
        listen 1935; 
    chunk_size 4096; 
 
    application vod { 
        play /opt/video/vod; 
    } 
 
    application live {     #第一处添加的直播字段   此处共添加3行
        live on; 
    } 
    } 
 
} 
 
http { 
    include       mime.types; 
    default_type  application/octet-stream; 
    sendfile        on; 
    keepalive_timeout  65; 
    server { 
        listen       80; 
        server_name  localhost; 
 
    location /stat {       #第二处添加的 location 字段。 此处共添加7行
        rtmp_stat all; 
        rtmp_stat_stylesheet stat.xsl; 
    } 
    location /stat.xsl {   #第二处添加的 location 字段。    
    root /usr/local/nginx/nginx-rtmp-module/;     ##注意需要把这个模块放到 nginx 目录中 
    } 
 
        location / { 
            root   html; 
            index  index.html index.htm; 
        } 
 
        error_page   500 502 503 504  /50x.html; 
        location = /50x.html { 
            root   html; 
        } 
    } 
} 

12.使用ffmpeg推送流

ffmpeg -re -i next.mp4 -vcodec libx264 -acodec aac -strict -2 -f flv rtmp://192.168.1.96:1935/live

显示如下:

ffmpeg version 2.6.8 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-16)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-gnutls --enable-ladspa --enable-libass --enable-libdc1394 --enable-libfaac --enable-nonfree --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libx264 --enable-libx265 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
libavutil 54. 20.100 / 54. 20.100
libavcodec 56. 26.100 / 56. 26.100
libavformat 56. 25.101 / 56. 25.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 11.102 / 5. 11.102
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'next.mp4':
Metadata:
major_brand : mp42
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 2016-08-09 09:35:02
encoder : HandBrake 0.10.5 2016021100
Duration: 00:00:05.00, start: 0.000000, bitrate: 739 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 960x540 [SAR 1:1 DAR 16:9], 735 kb/s, 25 fps, 25 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2016-08-09 09:35:02
handler_name : VideoHandler
[libx264 @ 0x214c520] using SAR=1/1
[libx264 @ 0x214c520] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x214c520] profile High, level 3.1
[libx264 @ 0x214c520] 264 - core 142 r2438 af8e768 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, flv, to 'rtmp://192.168.1.96:1935/live':
Metadata:
major_brand : mp42
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.25.101
Stream #0:0(und): Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p, 960x540 [SAR 1:1 DAR 16:9], q=-1--1, 25 fps, 1k tbn, 25 tbc (default)
Metadata:
creation_time : 2016-08-09 09:35:02
handler_name : VideoHandler
encoder : Lavc56.26.100 libx264
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[flv @ 0x214ba60] Failed to update header with correct duration.ate= 719.0kbits/s
[flv @ 0x214ba60] Failed to update header with correct filesize.
frame= 125 fps= 25 q=-1.0 Lsize= 221kB time=00:00:04.92 bitrate= 368.7kbits/s
video:219kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.284308%
[libx264 @ 0x214c520] frame I:1 Avg QP:21.33 size: 17488
[libx264 @ 0x214c520] frame P:45 Avg QP:17.88 size: 3758
[libx264 @ 0x214c520] frame B:79 Avg QP:17.46 size: 463
[libx264 @ 0x214c520] consecutive B-frames: 11.2% 9.6% 12.0% 67.2%
[libx264 @ 0x214c520] mb I I16..4: 22.8% 67.5% 9.8%
[libx264 @ 0x214c520] mb P I16..4: 6.9% 11.8% 0.3% P16..4: 25.2% 4.4% 1.3% 0.0% 0.0% skip:50.0%
[libx264 @ 0x214c520] mb B I16..4: 0.1% 0.2% 0.0% B16..8: 9.3% 0.4% 0.0% direct: 0.5% skip:89.6% L0:30.0% L1:67.6% BI: 2.4%
[libx264 @ 0x214c520] 8x8 transform intra:62.4% inter:89.6%
[libx264 @ 0x214c520] coded y,uvDC,uvAC intra: 19.3% 46.4% 6.9% inter: 3.7% 10.0% 0.2%
[libx264 @ 0x214c520] i16 v,h,dc,p: 32% 34% 11% 23%
[libx264 @ 0x214c520] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 23% 31% 2% 4% 3% 4% 2% 2%
[libx264 @ 0x214c520] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 25% 16% 5% 8% 5% 7% 4% 4%
[libx264 @ 0x214c520] i8c dc,h,v,p: 61% 21% 15% 3%
[libx264 @ 0x214c520] Weighted P-Frames: Y:33.3% UV:33.3%
[libx264 @ 0x214c520] ref P L0: 75.2% 16.2% 6.7% 1.9% 0.0%
[libx264 @ 0x214c520] ref B L0: 91.7% 7.7% 0.7%
[libx264 @ 0x214c520] ref B L1: 94.2% 5.8%
[libx264 @ 0x214c520] kb/s:357.07

登录:http://192.168.1.96/stat


RTMP    #clients    Video   Audio   In bytes    Out bytes   In bits/s   Out bits/s  State   Time
Accepted: 0 codec   bits/s  size    fps codec   bits/s  freq    chan    0 KB    0 KB    0 Kb/s  0 Kb/s      41m 25s
vod
vod streams 0
live
live streams    0
Generated by nginx-rtmp-module 1.1.4, nginx 1.8.0, pid 1767, built Nov 16 2017 12:39:43 gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)

转码mpg4转h264

ffmpeg -i next.mp4 -r 25 -s 1920*1080 -aspect 16:9 -b:v 2000K -bufsize 2000k -maxrate 2500k -vcodec h264 -strict -2 -acodec aac -ab 48k -ar 48000 -ac 2 n2.mp4

next.mp4 #源视频
n2.mp4 #转后的视频名

用以下链接中的方式查看转码前后对比,视觉上就能看出来,^^
http://note.youdao.com/noteshare?id=5658883c3a21467b6aaf3a9a171922fb&sub=8A7FC7CBE8E547908C1948143B859DFA

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,088评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,715评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,361评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,099评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 60,987评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,063评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,486评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,175评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,440评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,518评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,305评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,190评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,550评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,880评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,152评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,451评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,637评论 2 335

推荐阅读更多精彩内容

  • 1.分离视频音频流 ffmpeg -i input_file -vcodec copy -an output_fi...
    XLAccount阅读 3,054评论 0 8
  • 我们早已过了耳听爱情的年纪,没有了一见钟情的懵动,也没有了海誓山盟的笃定,更没有了奋不顾身的勇气。 到最后就连那些...
    冬白love阅读 442评论 7 9
  • 每天在上下班的地铁里,都是拿着手机匆忙的身影。我今天忽然不想再打游戏,我想开始码字,我想起我曾经那么爱写字,就觉得...
    鸢茵茵阅读 277评论 0 0
  • 那么晚了,本来不想写,但不写又不舒服。看到空间里一位学摄影的朋友分享着用新买的单反拍的照片,那份喜悦我能够体会。我...
    寒塘鹤影ciki阅读 265评论 0 2
  • 不知从何时起,自己喜欢夜空,喜欢那颗星那轮月那抹悲。 小的时候哭着哭着就笑了,长大后笑着笑着就哭了。 看...
    夜空那抹悲阅读 297评论 4 2