centos8上安裝ffmpeg4.2.2並做視頻截圖


一,ffmpeg的作用:

FFmpeg是一套可以用來記錄、轉換數字音頻、視頻,並能將其轉化為流的開源計算機程序。

它提供了錄制、轉換以及流化音視頻的完整解決方案。它包含了非常先進的音頻/視頻編解碼庫libavcodec

作為多媒體視頻處理工具,FFmpeg有非常強大的功能:

包括視頻采集功能、視頻格式轉換、視頻抓圖、給視頻加水印等

 

說明:劉宏締的架構森林是一個專注架構的博客,地址:https://www.cnblogs.com/architectforest

         對應的源碼可以訪問這里獲取: https://github.com/liuhongdi/

說明:作者:劉宏締 郵箱: 371125307@qq.com

 

二,安裝rpmfusion倉庫

[root@blog ~]# dnf install https://download1.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm 

說明:默認安裝的倉庫中沒有ffmpeg這個軟件

看例子:

[root@blog ~]# dnf install ffmpeg
CentOS-8 - AppStream                                                 143 kB/s | 4.3 kB     00:00
CentOS-8 - Base                                                      123 kB/s | 3.9 kB     00:00
CentOS-8 - Extras                                                     57 kB/s | 1.5 kB     00:00
Extra Packages for Enterprise Linux Modular 8 - x86_64                10 kB/s | 9.8 kB     00:00
Extra Packages for Enterprise Linux 8 - x86_64                       1.2 kB/s | 4.8 kB     00:03
Official OpenResty Open Source Repository for RHEL                    45 kB/s | 3.0 kB     00:00
No match for argument: ffmpeg
Error: Unable to find a match: ffmpeg 

如果沒有rpmfusion這個倉庫,安裝ffmpeg時dnf會提示找不到匹配

 

三,安裝sdl軟件包

SDL(Simple DirectMedia Layer)是一個自由的跨平台的多媒體開發包,

適用於 游戲、游戲SDK、演示軟件、模擬器、MPEG播放器和其他應用軟件

下載

[root@blog ~]# wget http://mirror.centos.org/centos/8/PowerTools/x86_64/os/Packages/SDL2-2.0.8-7.el8.x86_64.rpm

安裝

[root@blog ~]# rpm -ivh SDL2-2.0.8-7.el8.x86_64.rpm
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:SDL2-2.0.8-7.el8                 ################################# [100%]

說明:ffmpeg依賴於sdl庫,必須先安裝它,否則安裝ffmpeg時會報錯

[root@blog ~]# dnf install ffmpeg
RPM Fusion for EL 8 - Free - Updates                                             6.2 kB/s | 250 kB     00:40
Last metadata expiration check: 0:00:30 ago on Wed 29 Apr 2020 10:36:49 AM CST.
Error:
 Problem: conflicting requests
  - nothing provides libSDL2-2.0.so.0()(64bit) needed by ffmpeg-4.2.2-5.el8.x86_64
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

可以看到,沒有sdl包的情況下安裝ffmpeg時,dnf會提示缺少libSDL2-2.0.so.0()

 

四,dnf安裝ffmpeg

[root@blog ~]# dnf install ffmpeg 

 

五,查看ffmpeg的版本和幫助:

1,查看版本:

[root@blog ~]# ffmpeg -version
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8 (GCC)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg 
--incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64
--optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,
-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches
-specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1
-m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection
'
--extra-ldflags='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld '
--extra-cflags=' ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc
--enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r
--enable-gcrypt --enable-gnutls --enable-ladspa --enable-libaom --enable-libdav1d --enable-libass
--enable-libbluray --enable-libcdio --enable-libdrm --enable-libjack --enable-libfreetype
--enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl
--enable-opengl --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librsvg --enable-libsrt
--enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libvorbis --enable-libv4l2
--enable-libvidstab --enable-libvmaf --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid
--enable-libzimg --enable-libzvbi --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads
--disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64
--enable-libmfx --enable-runtime-cpudetect libavutil 56. 31.100 / 56. 31.100 libavcodec 58. 54.100 / 58. 54.100 libavformat 58. 29.100 / 58. 29.100 libavdevice 58. 8.100 / 58. 8.100 libavfilter 7. 57.100 / 7. 57.100 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 5.100 / 5. 5.100 libswresample 3. 5.100 / 3. 5.100 libpostproc 55. 5.100 / 55. 5.100

 

2,查看幫助

[root@blog ~]# ffmpeg --help 

 

3,查看手冊

[root@blog ~]# man ffmpeg

 

六,查看已安裝的ffmpeg支持的特性

1,查看支持的編碼器

[root@blog ~]# ffmpeg -codecs 

 

2,查看支持的視頻格式

[root@blog ~]# ffmpeg -formats 

 

3,查看支持的濾鏡

[root@blog ~]# ffmpeg -filters 

 

4,查看可用的解碼器

[root@blog ~]# ffmpeg -decoders  

                                                                                                                                           

5,查看可用的聲道布局

[root@blog ~]# ffmpeg -layouts 

 

6,顯示可用的顏色名稱

[root@blog ~]# ffmpeg -colors 

 

7,顯示可用的協議

[root@blog ~]# ffmpeg -protocols 

 

8,查看build時的配置參數

[root@blog ~]# ffmpeg -buildconf

 

9,顯示許可證信息

[root@blog ~]# ffmpeg -L 

 

10,顯示可用的封裝器

[root@blog ~]# ffmpeg -muxers

 

11,顯示可用的解封裝器

[root@blog ~]# ffmpeg -demuxers

 

12,顯示可用的設備

[root@blog ~]# ffmpeg -devices

 

13,顯示可用的音頻采樣格式

[root@blog ~]# ffmpeg -sample_fmts

 

14,顯示可用的像素格式

[root@blog ~]# ffmpeg -pix_fmts 

 

15,顯示可用的比特流過濾器

[root@blog ~]# ffmpeg -bsfs 

 

16,顯示可用的編解碼器

[root@blog ~]# ffmpeg -codecs 

 

七,測試一個常用的例子:從視頻中截圖(截取一幀保存成圖片)

從一個視頻中截取一幀保存成截圖圖片

1,查看視頻文件的信息

#-i: 指定作為輸入的視頻文件

[root@blog 1]# ffmpeg -i 8_9f6fa300bacded7b.mp4
...
Duration: 00:02:00.13, start: 0.000000, bitrate: 512 kb/s
Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 
640x360 [SAR 1:1 DAR 16:9], 189 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 60k tbc (default) ...

可以看到:視頻文件:時長2分鍾,寬:640,高360

 

2,截圖

#-i :源視頻文件

#-y: 如果目標文件存在則進行覆蓋

#-ss: 在指定的時間進行截圖

#-vframes: 指定抽取的幀數  如果要生成gif文件,則需要指定多幀

[root@blog 1]# ffmpeg -i 8_9f6fa300bacded7b.mp4 -y -ss 00:00:03 -vframes 1 /data/dev/think_file/html/8_1.jpg

 

3,從瀏覽器查看截圖的圖片:

 

 

八,查看centos版本

[root@blog ~]$ cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core) 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM