如何使用 FFmpeg 减小视频大小
如何安裝FFmpeg
本文介紹如何在 8中安裝ffmpeg,FFmpeg 在默認(rèn)的CentOS 8 源倉(cāng)庫(kù)中沒(méi)有提供,可以從第三方軟件源中安裝:
[root@localhost?~]#?rpm?-ivh? [root@localhost?~]#?yum?config-manager?--enable?PowerTools [root@localhost?~]#?yum?-y?install?SDL2 [root@localhost?~]#?yum?-y?install?ffmpeg安裝完成之后可以查看一下ffmpeg的版本:
[root@localhost?~]#?ffmpeg?-version [root@localhost?~]#?ffmpeg?-version ffmpeg?version?4.2.4?Copyright?(c)?2000-2020?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-version3?--enable-vapoursynth?--enable-libvpx?--enable-libx264?--enable-libx265?--enable-libxvid?--enable-libzimg?--enable-libzvbi?--enable-avfilter?--enable-avresample?--enable-libmodplug?--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.100FFmpeg基本用法
轉(zhuǎn)換多媒體文件時(shí),選擇正確的編解碼器、容器和格式可能非常具有挑戰(zhàn)性。但是,使用 FFmpeg,可以堅(jiān)持默認(rèn)設(shè)置并期待出色的結(jié)果。要使用默認(rèn) FFmpeg 設(shè)置轉(zhuǎn)換文件,請(qǐng)使用以下 :
[root@localhost?~]#?ffmpeg?-i?video.mp4?out_video.mp4
可以看到下圖中,輸出的視頻變小了許多:
上面的 會(huì)將文件從指定格式轉(zhuǎn)換為輸出格式。但是,要有效地壓縮文件,我們需要使用編解碼器、比特率、容器和 fps。
如何使用 FFmpeg 減少視頻大小
沒(méi)有通用的方法來(lái)減小視頻文件的大小,因?yàn)楦鞣N文件類型的創(chuàng)建并不相同。在本教程中,我們將使用 x265 編解碼器。x265 編解碼器,它是一個(gè)免費(fèi)的庫(kù),用于視頻編碼為 H.254/MPEG-H HEVC 的壓縮格式。
CRF使用 0 到 51 之間的數(shù)字。恒定速率因子(CRF)是 x264 和 x265 編碼的默認(rèn)質(zhì)量設(shè)置。值越高,壓縮率越高,值越高這可能會(huì)導(dǎo)致質(zhì)量損失。
下面我們將一個(gè)274M的視頻文件進(jìn)行壓縮:
[root@localhost?~]#?ffmpeg?-i?video.mp4?-vcodec?libx265?-crf?25?compress_video.mp4總結(jié)
雖然使用自定義壓縮選項(xiàng)可以產(chǎn)生很好的結(jié)果,但在某些情況下使用默認(rèn)的 FFmpeg 選項(xiàng)可能會(huì)更好。
總結(jié)
以上是生活随笔為你收集整理的如何使用 FFmpeg 减小视频大小的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: linux配置本地yum源 centos
- 下一篇: AUTOSAR解决方案 — INTEWO