今天介紹下FFmpeg在Linux下安裝編譯過程,總體過程比較順利,就是在ffmpeg等的時間稍長點,僅當記錄。
關于FFmpeg
FFmpeg是一個開源免費跨平台的視訊和音頻流方案,屬于自由軟體,采用LGPL或GPL許可證(依據你選擇的元件)。它提供了錄制、轉換以及流化音視訊的完整解決方案。它包含了非常先進的音頻/視訊編解碼庫libavcodec,為了保證高可移植性和編解碼品質,libavcodec裡很多codec都是從頭開發的。
FFmpeg配置
在安裝ffmpeg之前,首先要安裝yasm
1.安裝yasm
yasm是一個完全重寫的NASM彙編。目前,它支援x86和AMD64指令集,接受NASM和氣體彙編文法,産出二進制, ELF32 , ELF64 , COFF , Mach - O的( 32和64 ) , RDOFF2 ,的Win32和Win64對象的格式,并生成STABS 調試資訊的來源,DWARF 2 ,CodeView 8格式。之是以在FFmpeg中用這個,主要是支援編譯ffmpeg-x264.
1.下載下傳yasm-1.3.0.tar.gz這個版本:
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
如下:
複制代碼
jiangzhaowei@ubuntu$ wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz--2018-01-11 19:00:40-- http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
正在解析主機 www.tortall.net (www.tortall.net)... 69.55.226.36正在連接配接 www.tortall.net (www.tortall.net)|69.55.226.36|:80... 已連接配接。
已發出 HTTP 請求,正在等待回應... 302 Found
位置:http://211.162.127.5/files/30290000043CE033/www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz [跟随至新的 URL]--2018-01-11 19:00:41-- http://211.162.127.5/files/30290000043CE033/www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
正在連接配接 211.162.127.5:80... 已連接配接。
已發出 HTTP 請求,正在等待回應... 200 OK
長度: 1492156 (1.4M) [application/octet-stream]正在儲存至: “yasm-1.3.0.tar.gz”100%[=============================================================================================================>] 1,492,156 7.26MB/s 用時 0.2s
2018-01-11 19:00:41 (7.26 MB/s) - 已儲存 “yasm-1.3.0.tar.gz” [1492156/1492156])複制代碼
2.下載下傳完成後,用開始解壓
tar xzvf yasm-1.3.0.tar.gz
jiangzhaowei@ubuntu$ tar xzvf yasm-1.3.0.tar.gz
yasm-1.3.0/modules/objfmts/elf/tests/elfabssect.asmyasm-1.3.0/modules/objfmts/elf/tests/curpos-err.asmyasm-1.3.0/modules/objfmts/elf/tests/elfglobext2.asmyasm-1.3.0/modules/objfmts/elf/tests/elfvisibility.errwarn
yasm-1.3.0/modules/objfmts/elf/tests/curpos.hex
yasm-1.3.0/modules/objfmts/elf/tests/elf-x86id.hex
yasm-1.3.0/modules/objfmts/elf/tests/gas32/yasm-1.3.0/modules/objfmts/elf/tests/gas32/Makefile.inc
yasm-1.3.0/modules/objfmts/elf/tests/gas32/elf_gas32_got.hex
yasm-1.3.0/modules/objfmts/elf/tests/gas32/elf_gas32_ssym.hex
yasm-1.3.0/modules/objfmts/elf/tests/gas32/elf_gas32_test.sh
yasm-1.3.0/modules/objfmts/elf/tests/gas32/elf_gas32_got.asmyasm-1.3.0/modules/objfmts/elf/tests/gas32/elf_gas32_ssym.asmyasm-1.3.0/modules/objfmts/elf/tests/elfcond.hex
yasm-1.3.0/modules/objfmts/elf/tests/elfglobext2.hex
yasm-1.3.0/modules/objfmts/elf/tests/elf_test.sh
yasm-1.3.0/modules/objfmts/elf/Makefile.inc
yasm-1.3.0/modules/objfmts/elf/CMakeLists.txt
yasm-1.3.0/modules/objfmts/elf/elf-machine.h
yasm-1.3.0/modules/objfmts/elf/elf-objfmt.c
yasm-1.3.0/modules/objfmts/elf/elf-x86-x32.c
3.進入目錄,開始編譯
cd yasm-1.3.0
./configuremake
depbase=`echo frontends/yasm/yasm.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
gcc -std=gnu99 -DHAVE_CONFIG_H -I. -g -O2 -MT frontends/yasm/yasm.o -MD -MP -MF $depbase.Tpo -c -o frontends/yasm/yasm.o frontends/yasm/yasm.c &&\
mv -f $depbase.Tpo $depbase.Po
depbase=`echo frontends/yasm/yasm-options.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
gcc -std=gnu99 -DHAVE_CONFIG_H -I. -g -O2 -MT frontends/yasm/yasm-options.o -MD -MP -MF $depbase.Tpo -c -o frontends/yasm/yasm-options.o frontends/yasm/yasm-options.c &&\
mv -f $depbase.Tpo $depbase.Po
gcc -std=gnu99 -g -O2 -o yasm frontends/yasm/yasm.o frontends/yasm/yasm-options.o libyasm.a
depbase=`echo frontends/tasm/tasm.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
gcc -std=gnu99 -DHAVE_CONFIG_H -I. -g -O2 -MT frontends/tasm/tasm.o -MD -MP -MF $depbase.Tpo -c -o frontends/tasm/tasm.o frontends/tasm/tasm.c &&\
mv -f $depbase.Tpo $depbase.Po
depbase=`echo frontends/tasm/tasm-options.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
gcc -std=gnu99 -DHAVE_CONFIG_H -I. -g -O2 -MT frontends/tasm/tasm-options.o -MD -MP -MF $depbase.Tpo -c -o frontends/tasm/tasm-options.o frontends/tasm/tasm-options.c &&\
mv -f $depbase.Tpo $depbase.Po
gcc -std=gnu99 -g -O2 -o ytasm frontends/tasm/tasm.o frontends/tasm/tasm-options.o libyasm.a
depbase=`echo frontends/vsyasm/vsyasm.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
gcc -std=gnu99 -DHAVE_CONFIG_H -I. -g -O2 -MT frontends/vsyasm/vsyasm.o -MD -MP -MF $depbase.Tpo -c -o frontends/vsyasm/vsyasm.o frontends/vsyasm/vsyasm.c &&\
mv -f $depbase.Tpo $depbase.Po
gcc -std=gnu99 -g -O2 -o vsyasm frontends/vsyasm/vsyasm.o frontends/yasm/yasm-options.o libyasm.a
make[2]:正在離開目錄 `/kk/jiangzhaowei/share/ffmpeg/yasm-1.3.0'
make[1]:正在離開目錄 `/kk/jiangzhaowei/share/ffmpeg/yasm-1.3.0'
4.安裝
sudo make install
完成後如圖:
Making install in .make[2]: 正在進入目錄 `/kk/jiangzhaowei/share/ffmpeg/yasm-1.3.0'
make[3]: 正在進入目錄 `/kk/jiangzhaowei/share/ffmpeg/yasm-1.3.0'
/bin/mkdir -p '/usr/local/bin'
/usr/bin/install -c yasm ytasm vsyasm '/usr/local/bin'
/bin/mkdir -p '/usr/local/lib'
/usr/bin/install -c -m 644 libyasm.a '/usr/local/lib' ( cd '/usr/local/lib' && ranlib libyasm.a )make install-exec-hook
make[4]: 正在進入目錄 `/kk/jiangzhaowei/share/ffmpeg/yasm-1.3.0'
make[4]: 沒有什麼可以做的為 `install-exec-hook'。
make[4]:正在離開目錄 `/kk/jiangzhaowei/share/ffmpeg/yasm-1.3.0'
/bin/mkdir -p '/usr/local/include'
/usr/bin/install -c -m 644 libyasm.h '/usr/local/include'
/bin/mkdir -p '/usr/local/share/man/man1'
/bin/mkdir -p '/usr/local/share/man/man1'
/usr/bin/install -c -m 644 yasm.1 '/usr/local/share/man/man1'
/bin/mkdir -p '/usr/local/share/man/man7'
/usr/bin/install -c -m 644 yasm_arch.7 yasm_parsers.7 yasm_dbgfmts.7 yasm_objfmts.7 '/usr/local/share/man/man7'
/bin/mkdir -p '/usr/local/share/man/man7'
/bin/mkdir -p '/usr/local/include/libyasm'
/usr/bin/install -c -m 644 libyasm/arch.h libyasm/assocdat.h libyasm/bitvect.h libyasm/bytecode.h libyasm/compat-queue.h libyasm/coretype.h libyasm/dbgfmt.h libyasm/errwarn.h libyasm/expr.h libyasm/file.h libyasm/floatnum.h libyasm/hamt.h libyasm/insn.h libyasm/intnum.h libyasm/inttree.h libyasm/linemap.h libyasm/listfmt.h libyasm/md5.h libyasm/module.h libyasm/objfmt.h libyasm/parser.h libyasm/phash.h libyasm/preproc.h libyasm/section.h libyasm/symrec.h libyasm/valparam.h libyasm/value.h '/usr/local/include/libyasm'
/bin/mkdir -p '/usr/local/include'
/usr/bin/install -c -m 644 libyasm-stdint.h '/usr/local/include'
make[3]:正在離開目錄 `/kk/jiangzhaowei/share/ffmpeg/yasm-1.3.0'make[2]:正在離開目錄 `/kk/jiangzhaowei/share/ffmpeg/yasm-1.3.0'
make[1]:正在離開目錄 `/kk/jiangzhaowei/share/ffmpeg/yasm-1.3.0'
5.開始下載下傳FFmpeg,這裡下載下傳3.1.3 release ffmpeg的版本
jiangzhaowei@ubuntu$ wget http://ffmpeg.org/releases/ffmpeg-3.1.3.tar.gz
--2018-01-11 19:07:58-- http://ffmpeg.org/releases/ffmpeg-3.1.3.tar.gz
正在解析主機 ffmpeg.org (ffmpeg.org)... 79.124.17.100
正在連接配接 ffmpeg.org (ffmpeg.org)|79.124.17.100|:80... 已連接配接。
已發出 HTTP 請求,正在等待回應... 200 OK
長度: 11645295 (11M) [application/x-gzip]正在儲存至: “ffmpeg-3.1.3.tar.gz”
100%[=============================================================================================================>] 11,645,295 93.1KB/s 用時 94s
2018-01-11 19:09:33 (120 KB/s) - 已儲存 “ffmpeg-3.1.3.tar.gz” [11645295/11645295])
6.下載下傳完成後,用開始解壓
tar -zxvf ffmpeg-3.1.3.tar.gz
或者其它壓縮格式:
tar jxvf ffmpeg-3.4.1.tar.bz2
7.進入目錄,開始編譯
cd ffmpeg-3.1.3
./configuremake -j
X86ASM libavcodec/x86/simple_idct.o
STRIP libavcodec/x86/vp8dsp_loopfilter.o
STRIP libavcodec/x86/hevc_deblock.o
STRIP libavcodec/x86/vp9itxfm.o
AR libavcodec/libavcodec.a
LD ffmpeg_g
LD ffprobe_g
LD ffserver_g
STRIP ffserver
STRIP ffmpeg
STRIP ffprobe
8.安裝
sudo make install
FFmpeg HTTP媒體播放伺服器:
- “ffserver.conf”配置伺服器端口、最大連接配接數以及媒體本地路徑。
- 啟動FFmpeg伺服器:
kk@ubuntu:~/share/bak/ffmpeg$ ffserver -f ffserver.conf
ffserver version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
configuration:
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
ffserver.conf:164: Setting default value for video bit rate tolerance = 21333. Use NoDefaults to disable it.
ffserver.conf:164: Setting default value for video rate control equation = tex^qComp. Use NoDefaults to disable it.
ffserver.conf:164: Setting default value for video max rate = 128000. Use NoDefaults to disable it.
ffserver.conf:219: Setting default value for audio sample rate = 22050. Use NoDefaults to disable it.
ffserver.conf:219: Setting default value for audio channel count = 1. Use NoDefaults to disable it.
ffserver.conf:219: Setting default value for video bit rate tolerance = 64000. Use NoDefaults to disable it.
ffserver.conf:219: Setting default value for video rate control equation = tex^qComp. Use NoDefaults to disable it.
ffserver.conf:219: Setting default value for video max rate = 512000. Use NoDefaults to disable it.
Thu Jan 11 01:12:14 2018 Opening feed file '/home/kk/share/bak/ffmpeg/test.flv' for stream 'test.flv' //表示已經接收到播放請求
Thu Jan 11 01:12:14 2018 [ffm @ 0x9a85c20]Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Thu Jan 11 01:12:14 2018 [ffm @ 0x9a85c20]Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Thu Jan 11 01:12:14 2018 [ffm @ 0x9a85c20]Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Thu Jan 11 01:12:14 2018 [ffm @ 0x9a85c20]Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Thu Jan 11 01:12:14 2018 FFserver started.
Thu Jan 11 01:12:58 2018 [flv @ 0x9a97d20]Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Thu Jan 11 01:12:58 2018 [flv @ 0x9a97d20]Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Thu Jan 11 01:15:16 2018 192.168.199.141 - - [GET] "/test.flv HTTP/1.1" 200 23121984
Thu Jan 11 01:24:32 2018 192.168.199.141 - - [GET] "/test.flv HTTP/1.1" 200 3148385
Thu Jan 11 01:26:36 2018 192.168.199.164 - - [GET] "/test.flv HTTP/1.1" 200 11771070
Thu Jan 11 01:31:24 2018 192.168.199.164 - - [GET] "/test.flv HTTP/1.1" 200 3707111
Thu Jan 11 01:46:58 2018 192.168.199.164 - - [GET] "/test.flv HTTP/1.1" 200 146509
Thu Jan 11 02:13:11 2018 192.168.199.164 - - [GET] "/test.flv HTTP/1.1" 200 23121984
Thu Jan 11 02:14:26 2018 192.168.199.164 - - [GET] "/test.flv HTTP/1.1" 200 176099
Thu Jan 11 02:27:17 2018 192.168.199.164 - - [GET] "/test.flv HTTP/1.1" 200 2324539
Thu Jan 11 02:28:39 2018 192.168.199.164 - - [GET] "/test.flv HTTP/1.1" 200 23121984
Thu Jan 11 02:29:04 2018 192.168.199.164 - - [GET] "/test.flv HTTP/1.1" 200 23121984
Thu Jan 11 02:29:15 2018 192.168.199.164 - - [GET] "/test.flv HTTP/1.1" 200 8393075
Thu Jan 11 02:36:37 2018 192.168.199.164 - - [GET] "/test.flv HTTP/1.1" 200 23121984
Thu Jan 11 02:36:55 2018 192.168.199.164 - - [GET] "/test.flv HTTP/1.1" 200 170610
-
另外一台用戶端PC,使用VLC可以測試FFmpeg伺服器
VLC菜單欄->媒體->打開網絡串流,就可以正常播放HTTP伺服器流媒體了。
或者外網測試:
執行個體用法
編譯完成後,自然希望能我們有所作用,否則也不會沒事編譯ffmpeg。
- 把視訊的前120幀轉換成一個gif圖,大小指定為230*450:
ffmpeg -i device-2016-08-25-193402.mp4 -vframes 120 -s 230x405 -y -f gif Super3.gif
- 調用ffmpeg指令将一個視訊轉成3gp格式:
ffmpeg -i device-2016-08-25-193402.mp4 -y -b 20 -s sqcif -r 10 -acodec amr_wb -ab 23.85 -ac 1 -ar 16000 video.3gp
其他FFmpeg使用
文法:ffmpeg [[options][`-i’ input_file]]… {[options] output_file}…
截取一張352x240尺寸大小的,格式為jpg的圖檔
ffmpeg -i test.asf -y -f image2 -t 0.001 -s 352x240 s.jpg
截取指定時間的縮略圖
ffmpeg -i test.avi -y -f image2 -ss 8 -t 0.001 -s 350x240 test.jpg
-ss後跟的時間機關為秒
轉換檔案為3GP格式
ffmpeg -y -i test.mpeg -bitexact -vcodec h263 -b 128 -r 15 -s 176x144
-acodec aac -ac 2 -ar 22500 -ab 24 -f 3gp test.3gp
或
ffmpeg -y -i test.wmv -ac 1 -acodec libamr_nb -ar 8000 -ab 12200 -s 176x144 -b 128 -r 15 test.3gp
視訊格式轉換
如何使用 ffmpeg 編碼得到高品質的視訊
ffmpeg.exe -i “c:device-2016-08-25-193402.mp4” -target film-dvd -s 720x352
-padtop 64 -padbottom 64 -maxrate 7350000 -b 3700000 -sc_threshold 1000000000
-trellis -cgop -g 12 -bf 2 -qblur 0.3 -qcomp 0.7 -me full -dc 10 -mbd 2
-aspect 16:9 -pass 2 -passlogfile “D:Videoffmpegencode” -an -f mpeg2video “D:Fearless.m2v”
轉換指定格式檔案到FLV格式
ffmpeg.exe -i meng.mp3 -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 f:/device-2016-09.flv
ffmpeg.exe -i meng.wmv -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 f:/device-2016-09.flv
轉換檔案為MP4格式
ffmpeg -y -i input.wmv -f mp4 -async 1-s 480x320 -acodec libfaac -vcodec libxvid -qscale 7 -dts_delta_threshold 1 output.mp4
ffmpeg -y -i source_video.avi input -acodec libfaac -ab 128000 -vcodec mpeg4 -b 1200000 -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320x180 -title X final_video.mp4
使用ffmpeg錄像螢幕
ffmpeg -vcodec mpeg4 -b 1000 -r 10 -g 300 -vd x11:0,0 -s 1024x768 ~/device-2016-09-02-193402.avi
:其中,-vd x11:0,0 指錄制所使用的偏移為 x=0 和 y=0,-s 1024×768 指錄制視訊的大小為 1024×768。錄制的視訊檔案為 test.avi,将儲存到使用者主目錄中
如果你隻想錄制一個應用程式視窗或者桌面上的一個固定區域,那麼可以指定偏移位置和區域大小。使用xwininfo -frame指令可以完成查找上述參數。
重新調整視訊尺寸大小
ffmpeg -vcodec mpeg4 -b 1000 -r 10 -g 300 -i ~/device-2016-08-25-193402.avi -s 800×600 ~/device-2016-08-25-193402-800-600.avi
ffmpeg -f video4linux -s 320*240 -r 10 -i /dev/video0 test.asf