【WSL2笔记6】Ubuntu 环境下编译支持GPU加速的定制化FFMPEG

5 篇文章 0 订阅
2 篇文章 0 订阅

1、安装编译工具

sudo apt-get install autoconf automake bzip2
sudo apt-get install cmake gcc g++ git       # C编译器
sudo apt-get install libtool make mercurial
sudo apt-get install aptitude yasm nasm      # 汇编编译器

2. 安装ffnvvodec依赖 (Nvidia硬件加速)

2.1 确定与显卡驱动对应的SDK版本

官方版本点这里

#Corresponds to Video Codec SDK version 12.0.16.
#Minimum required driver versions:
#Linux: 530.41.03 or newer
#Windows: 531.61 or newer

  • 查看显卡驱动版本,下载对应的ffnvvodec版本
    nvidia-smi
$ nvidia-smi
Thu Jan  4 15:32:48 2024
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 530.41.03              Driver Version: 531.41       CUDA Version: 12.1     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                  Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf            Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 4090         On | 00000000:01:00.0  On |                  Off |
|  0%   49C    P8               27W / 450W|    947MiB / 24564MiB |      1%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+

+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A        11      G   /Xwayland                                 N/A      |
+---------------------------------------------------------------------------------------+

2.2 下载安装ffnvvodec

mkdir ffmpeg-nv
cd ffmpeg-nv
wget https://github.com/FFmpeg/nv-codec-headers/releases/download/n12.0.16.1/nv-codec-headers-12.0.16.1.tar.gz
#wget https://github.com/FFmpeg/nv-codec-headers/archive/refs/tags/n12.0.16.1.tar.gz
tar -xzvf nv-codec-headers-12.0.16.1.tar.gz
cd nv-codec-headers-12.0.16.1
sudo make && make install

3. 安装编码解码库

sudo apt-get install \
	libavcodec-dev \
	libavformat-dev \
	libavutil-dev \
	libswscale-dev \
	libavdevice-dev \
	libx265-dev \
	libx264-dev

3.1 安装x264编码器

  • git下载x264源码
    git clone https://code.videolan.org/videolan/x264.git
$ git clone https://code.videolan.org/videolan/x264.git
Cloning into 'x264'...
remote: Enumerating objects: 24192, done.
remote: Counting objects: 100% (1732/1732), done.
remote: Compressing objects: 100% (372/372), done.
remote: Total 24192 (delta 1360), reused 1731 (delta 1360), pack-reused 22460
Receiving objects: 100% (24192/24192), 6.47 MiB | 3.73 MiB/s, done.
Resolving deltas: 100% (19992/19992), done.
  • 进入x264目录
$ cd x264
  • 配置config
$ ./configure --includedir=/usr/local/include --libdir=/usr/local/lib --enable-shared

–enable-shared 生成相关lib 库文件

  • 编译安装x264
$ sudo make
$ sudo make install
  • 检查安装状态
$ x264 -V
x264 0.164.3173 4815cca
(libswscale 5.5.100)
(libavformat 58.29.100)
built on Jan 19 2024, gcc: 11.3.0
x264 configuration: --chroma-format=all
libx264 configuration: --chroma-format=all
x264 license: GPL version 2 or later
libswscale/libavformat license: LGPL version 2.1 or later

3.2 为什么要安装x264编码器?

  • 没安装x264编译的ffmpeg使用[h264_v4l2m2m]

$ ffmpeg -codecs | grep 264
ffmpeg version 6.1.1 Copyright © 2000-2023 the FFmpeg developers
built with gcc 11 (Ubuntu 11.3.0-1ubuntu1~22.04)
configuration:
libavutil 58. 29.100 / 58. 29.100
libavcodec 60. 31.102 / 60. 31.102
libavformat 60. 16.100 / 60. 16.100
libavdevice 60. 3.100 / 60. 3.100
libavfilter 9. 12.100 / 9. 12.100
libswscale 7. 5.100 / 7. 5.100
libswresample 4. 12.100 / 4. 12.100
DEV.LS h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_v4l2m2m h264_cuvid) (encoders: h264_nvenc h264_v4l2m2m h264_vaapi)

  • 安装了x264编码器编译的ffmpeg

4. 定制编译FFmpeg

4.1 下载源码

  • Wget下载
$ wget http://www.ffmpeg.org/releases/ffmpeg-5.0.1.tar.gz
$ tar -zxvf   ffmpeg-5.0.1.tar.gz
$ cd ffmpeg_source
  • Git下载
$ cd ~
$ git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg_source
$ cd ffmpeg_source
  • 官网手动下载
    https://ffmpeg.org/download.html
    在这里插入图片描述在压缩包目录用tar命令解压
$ tar xvJf ffmpeg-6.1.1.tar.xz
$ cd ffmpeg_source

4.2 卸载上次编译(第一次编译跳过此步)

用于增加了新的编码库,重新编译新版时,清除编译和卸载上个版本

make uninstall
make clean

4.3 修改源码当前目录/子目录读写/运行权限

sudo chmod u+x ./* -R

4.4 配置编译参数

  • 配置需要安装的组件与路径
sudo ./configure 
  --prefix=/usr/local/ffmpeg \
  --disable-x86asm \
  --enable-libmfx \
  --enable-gpl \
  --enable-version3 \
  --enable-libspeex \
  --enable-libmp3lame \
  --enable-libvorbis \
  --enable-shared \
  --enable-libfdk-aac \
  --enable-libass \
  --enable-libfontconfig \
  --enable-libfreetype \
  --enable-libopencore_amrnb \
  --enable-libopencore_amrwb \
  --enable-libopus \
  --enable-libtheora \
  --enable-libtwolame \
  --enable-libvpx \
  --enable-libx264 \
  --enable-libx265 \
  --enable-libxvid \
  --enable-nonfree \
  --enable-cuda-nvcc \
  --enable-cuvid \
  --enable-nvenc \
  --enable-ffnvcodec \
  --enable-nvdec \
  --enable-opencl \
  --extra-cflags=-I/usr/local/cuda/include \
  --extra-ldflags=-L/usr/local/cuda/lib64 \
  --extra-ldflags=-L/usr/local/lib \
  --extra-libs=-liconv
  • 配置返回结果
install prefix            /usr/local/ffmpeg
source path               .
C compiler                gcc
C library                 glibc
ARCH                      x86 (generic)
big-endian                no
runtime cpu detection     yes
standalone assembly       yes
x86 assembler             nasm
MMX enabled               yes
MMXEXT enabled            yes
3DNow! enabled            yes
3DNow! extended enabled   yes
SSE enabled               yes
SSSE3 enabled             yes
AESNI enabled             yes
AVX enabled               yes
AVX2 enabled              yes
AVX-512 enabled           yes
AVX-512ICL enabled        yes
XOP enabled               yes
FMA3 enabled              yes
FMA4 enabled              yes
i686 features enabled     yes
CMOV is fast              yes
EBX available             yes
EBP available             yes
debug symbols             yes
strip symbols             yes
optimize for size         no
optimizations             yes
static                    yes
shared                    no
postprocessing support    no
network support           yes
threading support         pthreads
safe bitstream reader     yes
texi2html enabled         no
perl enabled              yes
pod2man enabled           yes
makeinfo enabled          no
makeinfo supports HTML    no
xmllint enabled           yes

External libraries:
alsa                    iconv                   libxcb                  lzma                    zlib

External libraries providing hardware acceleration:
cuda                    ffnvcodec               nvenc
cuvid                   nvdec                   v4l2_m2m

Libraries:
avcodec                 avfilter                avutil                  swscale
avdevice                avformat                swresample

Programs:
ffmpeg                  ffprobe

Enabled decoders:
aac                     bmv_video               idcin                   pcm_f64le               sunrast
aac_fixed               bonk                    idf                     pcm_lxf                 svq1
aac_latm                brender_pix             iff_ilbm                pcm_mulaw               svq3
aasc                    c93                     ilbc                    pcm_s16be               tak
ac3                     cavs                    imc                     pcm_s16be_planar        targa
ac3_fixed               cbd2_dpcm               imm4                    pcm_s16le               targa_y216
acelp_kelvin            ccaption                imm5                    pcm_s16le_planar        tdsc
adpcm_4xm               cdgraphics              indeo2                  pcm_s24be               text
adpcm_adx               cdtoons                 indeo3                  pcm_s24daud             theora
adpcm_afc               cdxl                    indeo4                  pcm_s24le               thp
adpcm_agm               cfhd                    indeo5                  pcm_s24le_planar        tiertexseqvideo
adpcm_aica              cinepak                 interplay_acm           pcm_s32be               tiff
adpcm_argo              clearvideo              interplay_dpcm          pcm_s32le               tmv
adpcm_ct                cljr                    interplay_video         pcm_s32le_planar        truehd
adpcm_dtk               cllc                    ipu                     pcm_s64be               truemotion1
adpcm_ea                comfortnoise            jacosub                 pcm_s64le               truemotion2
adpcm_ea_maxis_xa       cook                    jpeg2000                pcm_s8                  truemotion2rt
adpcm_ea_r1             cpia                    jpegls                  pcm_s8_planar           truespeech
adpcm_ea_r2             cri                     jv                      pcm_sga                 tscc
adpcm_ea_r3             cscd                    kgv1                    pcm_u16be               tscc2
adpcm_ea_xas            cyuv                    kmvc                    pcm_u16le               tta
adpcm_g722              dca                     lagarith                pcm_u24be               twinvq
adpcm_g726              dds                     lead                    pcm_u24le               txd
adpcm_g726le            derf_dpcm               loco                    pcm_u32be               ulti
adpcm_ima_acorn         dfa                     lscr                    pcm_u32le               utvideo
adpcm_ima_alp           dfpwm                   m101                    pcm_u8                  v210
adpcm_ima_amv           dirac                   mace3                   pcm_vidc                v210x
adpcm_ima_apc           dnxhd                   mace6                   pcx                     v308
adpcm_ima_apm           dolby_e                 magicyuv                pdv                     v408
adpcm_ima_cunning       dpx                     mdec                    pfm                     v410
adpcm_ima_dat4          dsd_lsbf                media100                pgm                     vb
adpcm_ima_dk3           dsd_lsbf_planar         metasound               pgmyuv                  vble
adpcm_ima_dk4           dsd_msbf                microdvd                pgssub                  vbn
adpcm_ima_ea_eacs       dsd_msbf_planar         mimic                   pgx                     vc1
adpcm_ima_ea_sead       dsicinaudio             misc4                   phm                     vc1_cuvid
adpcm_ima_iss           dsicinvideo             mjpeg                   photocd                 vc1_v4l2m2m
adpcm_ima_moflex        dss_sp                  mjpeg_cuvid             pictor                  vc1image
adpcm_ima_mtf           dst                     mjpegb                  pixlet                  vcr1
adpcm_ima_oki           dvaudio                 mlp                     pjs                     vmdaudio
adpcm_ima_qt            dvbsub                  mmvideo                 png                     vmdvideo
adpcm_ima_rad           dvdsub                  mobiclip                ppm                     vmix
adpcm_ima_smjpeg        dvvideo                 motionpixels            prores                  vmnc
adpcm_ima_ssi           dxa                     movtext                 prosumer                vnull
adpcm_ima_wav           dxtory                  mp1                     psd                     vorbis
adpcm_ima_ws            dxv                     mp1float                ptx                     vp3
adpcm_ms                eac3                    mp2                     qcelp                   vp4
adpcm_mtaf              eacmv                   mp2float                qdm2                    vp5
adpcm_psx               eamad                   mp3                     qdmc                    vp6
adpcm_sbpro_2           eatgq                   mp3adu                  qdraw                   vp6a
adpcm_sbpro_3           eatgv                   mp3adufloat             qoa                     vp6f
adpcm_sbpro_4           eatqi                   mp3float                qoi                     vp7
adpcm_swf               eightbps                mp3on4                  qpeg                    vp8
adpcm_thp               eightsvx_exp            mp3on4float             qtrle                   vp8_cuvid
adpcm_thp_le            eightsvx_fib            mpc7                    r10k                    vp8_v4l2m2m
adpcm_vima              escape124               mpc8                    r210                    vp9
adpcm_xa                escape130               mpeg1_cuvid             ra_144                  vp9_cuvid
adpcm_xmd               evrc                    mpeg1_v4l2m2m           ra_288                  vp9_v4l2m2m
adpcm_yamaha            exr                     mpeg1video              ralf                    vplayer
adpcm_zork              fastaudio               mpeg2_cuvid             rasc                    vqa
agm                     ffv1                    mpeg2_v4l2m2m           rawvideo                vqc
aic                     ffvhuff                 mpeg2video              realtext                vvc
alac                    ffwavesynth             mpeg4                   rka                     wady_dpcm
alias_pix               fic                     mpeg4_cuvid             rl2                     wavarc
als                     fits                    mpeg4_v4l2m2m           roq                     wavpack
amrnb                   flac                    mpegvideo               roq_dpcm                wbmp
amrwb                   flashsv                 mpl2                    rpza                    wcmv
amv                     flashsv2                msa1                    rscc                    webp
anm                     flic                    mscc                    rtv1                    webvtt
ansi                    flv                     msmpeg4v1               rv10                    wmalossless
anull                   fmvc                    msmpeg4v2               rv20                    wmapro
apac                    fourxm                  msmpeg4v3               rv30                    wmav1
ape                     fraps                   msnsiren                rv40                    wmav2
apng                    frwu                    msp2                    s302m                   wmavoice
aptx                    ftr                     msrle                   sami                    wmv1
aptx_hd                 g2m                     mss1                    sanm                    wmv2
arbc                    g723_1                  mss2                    sbc                     wmv3
argo                    g729                    msvideo1                scpr                    wmv3image
ass                     gdv                     mszh                    screenpresso            wnv1
asv1                    gem                     mts2                    sdx2_dpcm               wrapped_avframe
asv2                    gif                     mv30                    sga                     ws_snd1
atrac1                  gremlin_dpcm            mvc1                    sgi                     xan_dpcm
atrac3                  gsm                     mvc2                    sgirle                  xan_wc3
atrac3al                gsm_ms                  mvdv                    sheervideo              xan_wc4
atrac3p                 h261                    mvha                    shorten                 xbin
atrac3pal               h263                    mwsc                    simbiosis_imx           xbm
atrac9                  h263_v4l2m2m            mxpeg                   sipr                    xface
aura                    h263i                   nellymoser              siren                   xl
aura2                   h263p                   notchlc                 smackaud                xma1
av1                     h264                    nuv                     smacker                 xma2
av1_cuvid               h264_cuvid              on2avc                  smc                     xpm
avrn                    h264_v4l2m2m            opus                    smvjpeg                 xsub
avrp                    hap                     osq                     snow                    xwd
avs                     hca                     paf_audio               sol_dpcm                y41p
avui                    hcom                    paf_video               sonic                   ylc
ayuv                    hdr                     pam                     sp5x                    yop
bethsoftvid             hevc                    pbm                     speedhq                 yuv4
bfi                     hevc_cuvid              pcm_alaw                speex                   zero12v
bink                    hevc_v4l2m2m            pcm_bluray              srgc                    zerocodec
binkaudio_dct           hnm4_video              pcm_dvd                 srt                     zlib
binkaudio_rdft          hq_hqa                  pcm_f16le               ssa                     zmbv
bintext                 hqx                     pcm_f24le               stl
bitpacked               huffyuv                 pcm_f32be               subrip
bmp                     hymt                    pcm_f32le               subviewer
bmv_audio               iac                     pcm_f64be               subviewer1

Enabled encoders:
a64multi                cljr                    mp2fixed                pcm_u24be               sunrast
a64multi5               comfortnoise            mpeg1video              pcm_u24le               svq1
aac                     dca                     mpeg2video              pcm_u32be               targa
ac3                     dfpwm                   mpeg4                   pcm_u32le               text
ac3_fixed               dnxhd                   mpeg4_v4l2m2m           pcm_u8                  tiff
adpcm_adx               dpx                     msmpeg4v2               pcm_vidc                truehd
adpcm_argo              dvbsub                  msmpeg4v3               pcx                     tta
adpcm_g722              dvdsub                  msrle                   pfm                     ttml
adpcm_g726              dvvideo                 msvideo1                pgm                     utvideo
adpcm_g726le            eac3                    nellymoser              pgmyuv                  v210
adpcm_ima_alp           exr                     opus                    phm                     v308
adpcm_ima_amv           ffv1                    pam                     png                     v408
adpcm_ima_apm           ffvhuff                 pbm                     ppm                     v410
adpcm_ima_qt            fits                    pcm_alaw                prores                  vbn
adpcm_ima_ssi           flac                    pcm_bluray              prores_aw               vc2
adpcm_ima_wav           flashsv                 pcm_dvd                 prores_ks               vnull
adpcm_ima_ws            flashsv2                pcm_f32be               qoi                     vorbis
adpcm_ms                flv                     pcm_f32le               qtrle                   vp8_v4l2m2m
adpcm_swf               g723_1                  pcm_f64be               r10k                    wavpack
adpcm_yamaha            gif                     pcm_f64le               r210                    wbmp
alac                    h261                    pcm_mulaw               ra_144                  webvtt
alias_pix               h263                    pcm_s16be               rawvideo                wmav1
amv                     h263_v4l2m2m            pcm_s16be_planar        roq                     wmav2
anull                   h263p                   pcm_s16le               roq_dpcm                wmv1
apng                    h264_nvenc              pcm_s16le_planar        rpza                    wmv2
aptx                    h264_v4l2m2m            pcm_s24be               rv10                    wrapped_avframe
aptx_hd                 hdr                     pcm_s24daud             rv20                    xbm
ass                     hevc_nvenc              pcm_s24le               s302m                   xface
asv1                    hevc_v4l2m2m            pcm_s24le_planar        sbc                     xsub
asv2                    huffyuv                 pcm_s32be               sgi                     xwd
av1_nvenc               jpeg2000                pcm_s32le               smc                     y41p
avrp                    jpegls                  pcm_s32le_planar        snow                    yuv4
avui                    ljpeg                   pcm_s64be               sonic                   zlib
ayuv                    magicyuv                pcm_s64le               sonic_ls                zmbv
bitpacked               mjpeg                   pcm_s8                  speedhq
bmp                     mlp                     pcm_s8_planar           srt
cfhd                    movtext                 pcm_u16be               ssa
cinepak                 mp2                     pcm_u16le               subrip

Enabled hwaccels:
av1_nvdec               mjpeg_nvdec             mpeg4_nvdec             vp9_nvdec
h264_nvdec              mpeg1_nvdec             vc1_nvdec               wmv3_nvdec
hevc_nvdec              mpeg2_nvdec             vp8_nvdec

Enabled parsers:
aac                     dca                     g723_1                  misc4                   sipr
aac_latm                dirac                   g729                    mjpeg                   tak
ac3                     dnxhd                   gif                     mlp                     vc1
adx                     dolby_e                 gsm                     mpeg4video              vorbis
amr                     dpx                     h261                    mpegaudio               vp3
av1                     dvaudio                 h263                    mpegvideo               vp8
avs2                    dvbsub                  h264                    opus                    vp9
avs3                    dvd_nav                 hdr                     png                     vvc
bmp                     dvdsub                  hevc                    pnm                     webp
cavsvideo               evc                     ipu                     qoi                     xbm
cook                    flac                    jpeg2000                rv34                    xma
cri                     ftr                     jpegxl                  sbc                     xwd

Enabled demuxers:
aa                      dirac                   image_pgm_pipe          musx                    ser
aac                     dnxhd                   image_pgmyuv_pipe       mv                      sga
aax                     dsf                     image_pgx_pipe          mvi                     shorten
ac3                     dsicin                  image_phm_pipe          mxf                     siff
ac4                     dss                     image_photocd_pipe      mxg                     simbiosis_imx
ace                     dts                     image_pictor_pipe       nc                      sln
acm                     dtshd                   image_png_pipe          nistsphere              smacker
act                     dv                      image_ppm_pipe          nsp                     smjpeg
adf                     dvbsub                  image_psd_pipe          nsv                     smush
adp                     dvbtxt                  image_qdraw_pipe        nut                     sol
ads                     dxa                     image_qoi_pipe          nuv                     sox
adx                     ea                      image_sgi_pipe          obu                     spdif
aea                     ea_cdata                image_sunrast_pipe      ogg                     srt
afc                     eac3                    image_svg_pipe          oma                     stl
aiff                    epaf                    image_tiff_pipe         osq                     str
aix                     evc                     image_vbn_pipe          paf                     subviewer
alp                     ffmetadata              image_webp_pipe         pcm_alaw                subviewer1
amr                     filmstrip               image_xbm_pipe          pcm_f32be               sup
amrnb                   fits                    image_xpm_pipe          pcm_f32le               svag
amrwb                   flac                    image_xwd_pipe          pcm_f64be               svs
anm                     flic                    ingenient               pcm_f64le               swf
apac                    flv                     ipmovie                 pcm_mulaw               tak
apc                     fourxm                  ipu                     pcm_s16be               tedcaptions
ape                     frm                     ircam                   pcm_s16le               thp
apm                     fsb                     iss                     pcm_s24be               threedostr
apng                    fwse                    iv8                     pcm_s24le               tiertexseq
aptx                    g722                    ivf                     pcm_s32be               tmv
aptx_hd                 g723_1                  ivr                     pcm_s32le               truehd
aqtitle                 g726                    jacosub                 pcm_s8                  tta
argo_asf                g726le                  jpegxl_anim             pcm_u16be               tty
argo_brp                g729                    jv                      pcm_u16le               txd
argo_cvg                gdv                     kux                     pcm_u24be               ty
asf                     genh                    kvag                    pcm_u24le               usm
asf_o                   gif                     laf                     pcm_u32be               v210
ass                     gsm                     live_flv                pcm_u32le               v210x
ast                     gxf                     lmlm4                   pcm_u8                  vag
au                      h261                    loas                    pcm_vidc                vc1
av1                     h263                    lrc                     pdv                     vc1t
avi                     h264                    luodat                  pjs                     vividas
avr                     hca                     lvf                     pmp                     vivo
avs                     hcom                    lxf                     pp_bnk                  vmd
avs2                    hevc                    m4v                     pva                     vobsub
avs3                    hls                     matroska                pvf                     voc
bethsoftvid             hnm                     mca                     qcp                     vpk
bfi                     iamf                    mcc                     qoa                     vplayer
bfstm                   ico                     mgsts                   r3d                     vqf
bink                    idcin                   microdvd                rawvideo                vvc
binka                   idf                     mjpeg                   realtext                w64
bintext                 iff                     mjpeg_2000              redspark                wady
bit                     ifv                     mlp                     rka                     wav
bitpacked               ilbc                    mlv                     rl2                     wavarc
bmv                     image2                  mm                      rm                      wc3
boa                     image2_alias_pix        mmf                     roq                     webm_dash_manifest
bonk                    image2_brender_pix      mods                    rpl                     webvtt
brstm                   image2pipe              moflex                  rsd                     wsaud
c93                     image_bmp_pipe          mov                     rso                     wsd
caf                     image_cri_pipe          mp3                     rtp                     wsvqa
cavsvideo               image_dds_pipe          mpc                     rtsp                    wtv
cdg                     image_dpx_pipe          mpc8                    s337m                   wv
cdxl                    image_exr_pipe          mpegps                  sami                    wve
cine                    image_gem_pipe          mpegts                  sap                     xa
codec2                  image_gif_pipe          mpegtsraw               sbc                     xbin
codec2raw               image_hdr_pipe          mpegvideo               sbg                     xmd
concat                  image_j2k_pipe          mpjpeg                  scc                     xmv
data                    image_jpeg_pipe         mpl2                    scd                     xvag
daud                    image_jpegls_pipe       mpsub                   sdns                    xwma
dcstr                   image_jpegxl_pipe       msf                     sdp                     yop
derf                    image_pam_pipe          msnwc_tcp               sdr2                    yuv4mpegpipe
dfa                     image_pbm_pipe          msp                     sds
dfpwm                   image_pcx_pipe          mtaf                    sdx
dhav                    image_pfm_pipe          mtv                     segafilm

Enabled muxers:
a64                     dnxhd                   ircam                   ogg                     segafilm
ac3                     dts                     ismv                    ogv                     segment
ac4                     dv                      ivf                     oma                     smjpeg
adts                    eac3                    jacosub                 opus                    smoothstreaming
adx                     evc                     kvag                    pcm_alaw                sox
aiff                    f4v                     latm                    pcm_f32be               spdif
alp                     ffmetadata              lrc                     pcm_f32le               spx
amr                     fifo                    m4v                     pcm_f64be               srt
amv                     fifo_test               matroska                pcm_f64le               stream_segment
apm                     filmstrip               matroska_audio          pcm_mulaw               streamhash
apng                    fits                    md5                     pcm_s16be               sup
aptx                    flac                    microdvd                pcm_s16le               swf
aptx_hd                 flv                     mjpeg                   pcm_s24be               tee
argo_asf                framecrc                mkvtimestamp_v2         pcm_s24le               tg2
argo_cvg                framehash               mlp                     pcm_s32be               tgp
asf                     framemd5                mmf                     pcm_s32le               truehd
asf_stream              g722                    mov                     pcm_s8                  tta
ass                     g723_1                  mp2                     pcm_u16be               ttml
ast                     g726                    mp3                     pcm_u16le               uncodedframecrc
au                      g726le                  mp4                     pcm_u24be               vc1
avi                     gif                     mpeg1system             pcm_u24le               vc1t
avif                    gsm                     mpeg1vcd                pcm_u32be               voc
avm2                    gxf                     mpeg1video              pcm_u32le               vvc
avs2                    h261                    mpeg2dvd                pcm_u8                  w64
avs3                    h263                    mpeg2svcd               pcm_vidc                wav
bit                     h264                    mpeg2video              psp                     webm
caf                     hash                    mpeg2vob                rawvideo                webm_chunk
cavsvideo               hds                     mpegts                  rm                      webm_dash_manifest
codec2                  hevc                    mpjpeg                  roq                     webp
codec2raw               hls                     mxf                     rso                     webvtt
crc                     iamf                    mxf_d10                 rtp                     wsaud
dash                    ico                     mxf_opatom              rtp_mpegts              wtv
data                    ilbc                    null                    rtsp                    wv
daud                    image2                  nut                     sap                     yuv4mpegpipe
dfpwm                   image2pipe              obu                     sbc
dirac                   ipod                    oga                     scc

Enabled protocols:
async                   ffrtmphttp              icecast                 rtmpt                   udp
cache                   file                    md5                     rtp                     udplite
concat                  ftp                     mmsh                    sctp                    unix
concatf                 gopher                  mmst                    srtp
crypto                  hls                     pipe                    subfile
data                    http                    prompeg                 tcp
fd                      httpproxy               rtmp                    tee

Enabled filters:
a3dscope                asisdr                  dialoguenhance          lowshelf                showpalette
aap                     asoftclip               dilation                lumakey                 showspatial
abench                  aspectralstats          displace                lut                     showspectrum
abitscope               asplit                  dnn_classify            lut1d                   showspectrumpic
acompressor             astats                  dnn_detect              lut2                    showvolume
acontrast               astreamselect           dnn_processing          lut3d                   showwaves
acopy                   asubboost               doubleweave             lutrgb                  showwavespic
acrossfade              asubcut                 drawbox                 lutyuv                  shuffleframes
acrossover              asupercut               drawgraph               mandelbrot              shufflepixels
acrusher                asuperpass              drawgrid                maskedclamp             shuffleplanes
acue                    asuperstop              drmeter                 maskedmax               sidechaincompress
addroi                  atadenoise              dynaudnorm              maskedmerge             sidechaingate
adeclick                atempo                  earwax                  maskedmin               sidedata
adeclip                 atilt                   ebur128                 maskedthreshold         sierpinski
adecorrelate            atrim                   edgedetect              maskfun                 signalstats
adelay                  avectorscope            elbg                    mcompand                silencedetect
adenorm                 avgblur                 entropy                 median                  silenceremove
aderivative             avsynctest              epx                     mergeplanes             sinc
adrawgraph              axcorrelate             equalizer               mestimate               sine
adrc                    backgroundkey           erosion                 metadata                siti
adynamicequalizer       bandpass                estdif                  midequalizer            smptebars
adynamicsmooth          bandreject              exposure                minterpolate            smptehdbars
aecho                   bass                    extractplanes           mix                     sobel
aemphasis               bbox                    extrastereo             monochrome              spectrumsynth
aeval                   bench                   fade                    morpho                  speechnorm
aevalsrc                bilateral               feedback                movie                   split
aexciter                biquad                  fftdnoiz                msad                    sr
afade                   bitplanenoise           fftfilt                 multiply                ssim
afdelaysrc              blackdetect             field                   negate                  ssim360
afftdn                  blend                   fieldhint               nlmeans                 stereotools
afftfilt                blockdetect             fieldmatch              noformat                stereowiden
afifo                   blurdetect              fieldorder              noise                   streamselect
afir                    bm3d                    fifo                    normalize               superequalizer
afireqsrc               bwdif                   fillborders             null                    surround
afirsrc                 cas                     firequalizer            nullsink                swaprect
aformat                 ccrepack                flanger                 nullsrc                 swapuv
afreqshift              cellauto                floodfill               oscilloscope            tblend
afwtdn                  channelmap              format                  overlay                 telecine
agate                   channelsplit            fps                     pad                     testsrc
agraphmonitor           chorus                  framepack               pal100bars              testsrc2
ahistogram              chromahold              framerate               pal75bars               thistogram
aiir                    chromakey               framestep               palettegen              threshold
aintegral               chromanr                freezedetect            paletteuse              thumbnail
ainterleave             chromashift             freezeframes            pan                     tile
alatency                ciescope                gblur                   perms                   tiltandshift
alimiter                codecview               geq                     photosensitivity        tiltshelf
allpass                 color                   gradfun                 pixdesctest             tlut2
allrgb                  colorbalance            gradients               pixelize                tmedian
allyuv                  colorchannelmixer       graphmonitor            pixscope                tmidequalizer
aloop                   colorchart              grayworld               premultiply             tmix
alphaextract            colorcontrast           greyedge                prewitt                 tonemap
alphamerge              colorcorrect            guided                  pseudocolor             tpad
amerge                  colorhold               haas                    psnr                    transpose
ametadata               colorize                haldclut                qp                      treble
amix                    colorkey                haldclutsrc             random                  tremolo
amovie                  colorlevels             hdcd                    readeia608              trim
amplify                 colormap                headphone               readvitc                unpremultiply
amultiply               colorspace              hflip                   realtime                unsharp
anequalizer             colorspectrum           highpass                remap                   untile
anlmdn                  colortemperature        highshelf               removegrain             v360
anlmf                   compand                 hilbert                 removelogo              varblur
anlms                   compensationdelay       histogram               replaygain              vectorscope
anoisesrc               concat                  hqx                     reverse                 vflip
anull                   convolution             hstack                  rgbashift               vfrdet
anullsink               convolve                hsvhold                 rgbtestsrc              vibrance
anullsrc                copy                    hsvkey                  roberts                 vibrato
apad                    corr                    hue                     rotate                  vif
aperms                  crop                    huesaturation           scale                   vignette
aphasemeter             crossfeed               hwdownload              scale2ref               virtualbass
aphaser                 crystalizer             hwmap                   scdet                   vmafmotion
aphaseshift             cue                     hwupload                scharr                  volume
apsnr                   curves                  hwupload_cuda           scroll                  volumedetect
apsyclip                datascope               hysteresis              segment                 vstack
apulsator               dblur                   identity                select                  w3fdif
arealtime               dcshift                 idet                    selectivecolor          waveform
aresample               dctdnoiz                il                      sendcmd                 weave
areverse                deband                  inflate                 separatefields          xbr
arls                    deblock                 interleave              setdar                  xcorrelate
arnndn                  decimate                join                    setfield                xfade
asdr                    deconvolve              kirsch                  setparams               xmedian
asegment                dedot                   lagfun                  setpts                  xstack
aselect                 deesser                 latency                 setrange                yadif
asendcmd                deflate                 lenscorrection          setsar                  yaepblur
asetnsamples            deflicker               life                    settb                   yuvtestsrc
asetpts                 dejudder                limitdiff               shear                   zoneplate
asetrate                derain                  limiter                 showcqt                 zoompan
asettb                  deshake                 loop                    showcwt
ashowinfo               despill                 loudnorm                showfreqs
asidedata               detelecine              lowpass                 showinfo

Enabled bsfs:
aac_adtstoasc           eac3_core               hevc_mp4toannexb        noise                   trace_headers
av1_frame_merge         evc_frame_merge         imx_dump_header         null                    truehd_core
av1_frame_split         extract_extradata       media100_to_mjpegb      opus_metadata           vp9_metadata
av1_metadata            filter_units            mjpeg2jpeg              pcm_rechunk             vp9_raw_reorder
chomp                   h264_metadata           mjpega_dump_header      pgs_frame_merge         vp9_superframe
dca_core                h264_mp4toannexb        mov2textsub             prores_metadata         vp9_superframe_split
dts2pts                 h264_redundant_pps      mp3_header_decompress   remove_extradata        vvc_metadata
dump_extradata          hapqa_extract           mpeg2_metadata          setts                   vvc_mp4toannexb
dv_error_marker         hevc_metadata           mpeg4_unpack_bframes    text2movsub

Enabled indevs:
alsa                    lavfi                   v4l2
fbdev                   oss                     xcbgrab

Enabled outdevs:
alsa                    fbdev                   oss                     v4l2

License: LGPL version 2.1 or later
config.h is unchanged
config.asm is unchanged
config_components.h is unchanged
libavutil/avconfig.h is unchanged
libavfilter/filter_list.c is unchanged
libavcodec/codec_list.c is unchanged
libavcodec/parser_list.c is unchanged
libavcodec/bsf_list.c is unchanged
libavformat/demuxer_list.c is unchanged
libavformat/muxer_list.c is unchanged
libavdevice/indev_list.c is unchanged
libavdevice/outdev_list.c is unchanged
libavformat/protocol_list.c is unchanged
ffbuild/config.sh is unchanged

4.5 编译及安装

  • 编译安装
sudo make -j12 # 开启12线程编译 
# sudo make -j$(nproc) # 开启所有CPU
sudo make install # 安装ffmpeg
  • 查看软件安装路径
    which ffmpeg

  • 复制ffmpeg到指定env环境
    sudo cp /usr/local/ffmpeg/bin/ffmpeg /home/gpu/anaconda3/envs/test/bin/ffmpeg

  • 查看FFmpeg硬件加速
    ffmpeg -hwaccels

ffmpeg version N-113193-g59686eaf33 Copyright (c) 2000-2024 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.3.0-1ubuntu1~22.04)
  configuration:
  libavutil      58. 36.100 / 58. 36.100
  libavcodec     60. 37.100 / 60. 37.100
  libavformat    60. 20.100 / 60. 20.100
  libavdevice    60.  4.100 / 60.  4.100
  libavfilter     9. 16.100 /  9. 16.100
  libswscale      7.  6.100 /  7.  6.100
  libswresample   4. 13.100 /  4. 13.100
Hardware acceleration methods:
cuda

ffmpeg -codecs | grep cuvid

ffmpeg version N-113193-g59686eaf33 Copyright (c) 2000-2024 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.3.0-1ubuntu1~22.04)
  configuration:
  libavutil      58. 36.100 / 58. 36.100
  libavcodec     60. 37.100 / 60. 37.100
  libavformat    60. 20.100 / 60. 20.100
  libavdevice    60.  4.100 / 60.  4.100
  libavfilter     9. 16.100 /  9. 16.100
  libswscale      7.  6.100 /  7.  6.100
  libswresample   4. 13.100 /  4. 13.100
 DEV.L. av1                  Alliance for Open Media AV1 (decoders: av1 av1_cuvid) (encoders: av1_nvenc)
 DEV.LS h264                 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_v4l2m2m h264_cuvid) (encoders: h264_nvenc h264_v4l2m2m)
 DEV.L. hevc                 H.265 / HEVC (High Efficiency Video Coding) (decoders: hevc hevc_v4l2m2m hevc_cuvid) (encoders: hevc_nvenc hevc_v4l2m2m)
 DEVIL. mjpeg                Motion JPEG (decoders: mjpeg mjpeg_cuvid)
 DEV.L. mpeg1video           MPEG-1 video (decoders: mpeg1video mpeg1_v4l2m2m mpeg1_cuvid)
 DEV.L. mpeg2video           MPEG-2 video (decoders: mpeg2video mpegvideo mpeg2_v4l2m2m mpeg2_cuvid)
 DEV.L. mpeg4                MPEG-4 part 2 (decoders: mpeg4 mpeg4_v4l2m2m mpeg4_cuvid) (encoders: mpeg4 mpeg4_v4l2m2m)
 D.V.L. vc1                  SMPTE VC-1 (decoders: vc1 vc1_v4l2m2m vc1_cuvid)
 DEV.L. vp8                  On2 VP8 (decoders: vp8 vp8_v4l2m2m vp8_cuvid) (encoders: vp8_v4l2m2m)
 D.V.L. vp9                  Google VP9 (decoders: vp9 vp9_v4l2m2m vp9_cuvid)
  • 查看GPU编码器
    ffmpeg -encoders | grep nvenc
ffmpeg version N-113193-g59686eaf33 Copyright (c) 2000-2024 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.3.0-1ubuntu1~22.04)
  configuration:
  libavutil      58. 36.100 / 58. 36.100
  libavcodec     60. 37.100 / 60. 37.100
  libavformat    60. 20.100 / 60. 20.100
  libavdevice    60.  4.100 / 60.  4.100
  libavfilter     9. 16.100 /  9. 16.100
  libswscale      7.  6.100 /  7.  6.100
  libswresample   4. 13.100 /  4. 13.100
 V....D av1_nvenc            NVIDIA NVENC av1 encoder (codec av1)
 V....D h264_nvenc           NVIDIA NVENC H.264 encoder (codec h264)
 V....D hevc_nvenc           NVIDIA NVENC hevc encoder (codec hevc)
  • 查看GPU解码器
    ffmpeg -decoders | grep cuvid
ffmpeg version N-113193-g59686eaf33 Copyright (c) 2000-2024 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.3.0-1ubuntu1~22.04)
  configuration:
  libavutil      58. 36.100 / 58. 36.100
  libavcodec     60. 37.100 / 60. 37.100
  libavformat    60. 20.100 / 60. 20.100
  libavdevice    60.  4.100 / 60.  4.100
  libavfilter     9. 16.100 /  9. 16.100
  libswscale      7.  6.100 /  7.  6.100
  libswresample   4. 13.100 /  4. 13.100
 V..... av1_cuvid            Nvidia CUVID AV1 decoder (codec av1)
 V..... h264_cuvid           Nvidia CUVID H264 decoder (codec h264)
 V..... hevc_cuvid           Nvidia CUVID HEVC decoder (codec hevc)
 V..... mjpeg_cuvid          Nvidia CUVID MJPEG decoder (codec mjpeg)
 V..... mpeg1_cuvid          Nvidia CUVID MPEG1VIDEO decoder (codec mpeg1video)
 V..... mpeg2_cuvid          Nvidia CUVID MPEG2VIDEO decoder (codec mpeg2video)
 V..... mpeg4_cuvid          Nvidia CUVID MPEG4 decoder (codec mpeg4)
 V..... vc1_cuvid            Nvidia CUVID VC1 decoder (codec vc1)
 V..... vp8_cuvid            Nvidia CUVID VP8 decoder (codec vp8)
 V..... vp9_cuvid            Nvidia CUVID VP9 decoder (codec vp9)

4.6 使用GPU加速

ffmpeg -hwaccel cuda

  • 转码演示
    使用GPU解码器:h264_cuvid
    使用GPU编码器:h264_nvenc
$ ffmpeg -hwaccel cuda -c:v h264_cuvid -i test_in.mp4 -c:v h264_nvenc -y test-gpu.mp4
ffmpeg version N-113193-g59686eaf33 Copyright (c) 2000-2024 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.3.0-1ubuntu1~22.04)
  configuration:
  libavutil      58. 36.100 / 58. 36.100
  libavcodec     60. 37.100 / 60. 37.100
  libavformat    60. 20.100 / 60. 20.100
  libavdevice    60.  4.100 / 60.  4.100
  libavfilter     9. 16.100 /  9. 16.100
  libswscale      7.  6.100 /  7.  6.100
  libswresample   4. 13.100 /  4. 13.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test_in.mp4':
  Metadata:
    minor_version   : 0
    major_brand     : mp42
    compatible_brands: mp42mp41
    encoder         : Lavf58.76.100
  Duration: 00:00:16.24, start: 0.000000, bitrate: 34633 kb/s
  Stream #0:0[0x1](eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 1920x2160 [SAR 1:1 DAR 8:9], 34311 kb/s, 25 fps, 25 tbr, 25k tbn (default)
      Metadata:
        handler_name    : ?Mainconcept Video Media Handler
        vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
      Metadata:
        handler_name    : #Mainconcept MP4 Sound Media Handler
        vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (h264_cuvid) -> h264 (h264_nvenc))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
Output #0, mp4, to 'test-gpu.mp4':
  Metadata:
    minor_version   : 0
    major_brand     : mp42
    compatible_brands: mp42mp41
    encoder         : Lavf60.20.100
  Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), nv12(tv, progressive), 1920x2160 [SAR 1:1 DAR 8:9], q=2-31, 2000 kb/s, 25 fps, 12800 tbn (default)
      Metadata:
        handler_name    : ?Mainconcept Video Media Handler
        vendor_id       : [0][0][0][0]
        encoder         : Lavc60.37.100 h264_nvenc
      Side data:
        cpb: bitrate max/min/avg: 0/0/2000000 buffer size: 4000000 vbv_delay: N/A
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
      Metadata:
        handler_name    : #Mainconcept MP4 Sound Media Handler
        vendor_id       : [0][0][0][0]
        encoder         : Lavc60.37.100 aac
[out#0/mp4 @ 0x5561f8097500] video:3035kB audio:255kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.411259%
frame=  406 fps=228 q=29.0 Lsize=    3303kB time=00:00:16.12 bitrate=1678.7kbits/s speed=9.06x
[aac @ 0x5561f8d3be00] Qavg: 763.915

本文完

  • 10
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值