centos6中yum安裝ffmpeg

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

本章中為虛擬環(huán)境所以防火墻是關(guān)閉的分井,線上的防火墻可添加或酌情修改

-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.升級(jí)系統(tǒng)

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

2.環(huán)境

[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 安裝略,編譯時(shí)需加上此模塊:--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開發(fā)包

yum install ffmpeg ffmpeg-devel -y  

8.測(cè)試
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 服務(wù)         此處共添加9行
    server {      
        listen 1935;        #服務(wù)端口  
        chunk_size 4096;    #數(shù)據(jù)傳輸塊的大小 
    application vod { 
        play /opt/video/vod; #視頻文件存放位置描馅。需要?jiǎng)?chuàng)建此目錄(可放入視頻進(jìn)行播放) 
        } 
    } 
} 
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服務(wù)

11.添加nginx配置兩個(gè)server并重啟服務(wù)

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/;     ##注意需要把這個(gè)模塊放到 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)

轉(zhuǎn)碼mpg4轉(zhuǎn)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 #轉(zhuǎn)后的視頻名

用以下鏈接中的方式查看轉(zhuǎn)碼前后對(duì)比,視覺上就能看出來,^^
http://note.youdao.com/noteshare?id=5658883c3a21467b6aaf3a9a171922fb&sub=8A7FC7CBE8E547908C1948143B859DFA

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末丹莲,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子尸诽,更是在濱河造成了極大的恐慌甥材,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,542評(píng)論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件性含,死亡現(xiàn)場(chǎng)離奇詭異洲赵,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)胶滋,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,822評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門板鬓,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人究恤,你說我怎么就攤上這事俭令。” “怎么了部宿?”我有些...
    開封第一講書人閱讀 163,912評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵抄腔,是天一觀的道長瓢湃。 經(jīng)常有香客問我,道長赫蛇,這世上最難降的妖魔是什么绵患? 我笑而不...
    開封第一講書人閱讀 58,449評(píng)論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮悟耘,結(jié)果婚禮上落蝙,老公的妹妹穿的比我還像新娘。我一直安慰自己暂幼,他們只是感情好筏勒,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,500評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著旺嬉,像睡著了一般管行。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上邪媳,一...
    開封第一講書人閱讀 51,370評(píng)論 1 302
  • 那天捐顷,我揣著相機(jī)與錄音,去河邊找鬼雨效。 笑死迅涮,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的设易。 我是一名探鬼主播逗柴,決...
    沈念sama閱讀 40,193評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼顿肺!你這毒婦竟也來了戏溺?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,074評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤屠尊,失蹤者是張志新(化名)和其女友劉穎旷祸,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體讼昆,經(jīng)...
    沈念sama閱讀 45,505評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡托享,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,722評(píng)論 3 335
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了浸赫。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片闰围。...
    茶點(diǎn)故事閱讀 39,841評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖既峡,靈堂內(nèi)的尸體忽然破棺而出羡榴,到底是詐尸還是另有隱情,我是刑警寧澤运敢,帶...
    沈念sama閱讀 35,569評(píng)論 5 345
  • 正文 年R本政府宣布校仑,位于F島的核電站忠售,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏迄沫。R本人自食惡果不足惜稻扬,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,168評(píng)論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望羊瘩。 院中可真熱鬧泰佳,春花似錦、人聲如沸尘吗。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,783評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽摇予。三九已至,卻和暖如春吗跋,著一層夾襖步出監(jiān)牢的瞬間侧戴,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,918評(píng)論 1 269
  • 我被黑心中介騙來泰國打工跌宛, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留酗宋,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,962評(píng)論 2 370
  • 正文 我出身青樓疆拘,卻偏偏與公主長得像蜕猫,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子哎迄,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,781評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • 1.分離視頻音頻流 ffmpeg -i input_file -vcodec copy -an output_fi...
    XLAccount閱讀 3,076評(píng)論 0 8
  • 我們?cè)缫堰^了耳聽愛情的年紀(jì)回右,沒有了一見鐘情的懵動(dòng),也沒有了海誓山盟的篤定漱挚,更沒有了奮不顧身的勇氣翔烁。 到最后就連那些...
    冬白love閱讀 445評(píng)論 7 9
  • 每天在上下班的地鐵里,都是拿著手機(jī)匆忙的身影旨涝。我今天忽然不想再打游戲蹬屹,我想開始碼字,我想起我曾經(jīng)那么愛寫字白华,就覺得...
    鳶茵茵閱讀 279評(píng)論 0 0
  • 那么晚了慨默,本來不想寫,但不寫又不舒服弧腥∠萌。看到空間里一位學(xué)攝影的朋友分享著用新買的單反拍的照片,那份喜悅我能夠體會(huì)鸟赫。我...
    寒塘鶴影ciki閱讀 276評(píng)論 0 2
  • 不知從何時(shí)起蒜胖,自己喜歡夜空消别,喜歡那顆星那輪月那抹悲。 小的時(shí)候哭著哭著就笑了台谢,長大后笑著笑著就哭了寻狂。 看...
    夜空那抹悲閱讀 303評(píng)論 4 2