FFMpeg編譯支持NVidia CODEC(成功)

  • 下載頭文件
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git

cd nv-codec-headers

sudo make
sudo make install
  • 下載ffmpeg

http://ffmpeg.org/

最新的。

  • modify list

libavcodec/codec_list.c

static const AVCodec * const codec_list[] = {
    # move to head, I think it would be search first
    &ff_h264_nvenc_encoder,
    &ff_nvenc_h264_encoder,
    &ff_h264_cuvid_decoder,

    &ff_aac_encoder,
    &ff_libx264_encoder,
    &ff_h263_decoder,
    &ff_h264_decoder,
    &ff_hevc_decoder,
    &ff_mjpeg_decoder,
    &ff_mpeg1video_decoder,
    &ff_mpeg2video_decoder,
    &ff_mpeg4_decoder,
    &ff_png_decoder,
    &ff_vc1_decoder,
    &ff_vp8_decoder,
    &ff_vp9_decoder,
    &ff_aac_decoder,
    NULL };
  • 重新編譯 

# export is must use.
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:${PKG_CONFIG_PATH}
 
pkg-config --modversion ffnvcodec
 
X264_PATH=`pwd`/../x264-snapshot-20180101-2245-stable
CUDA_PATH=/usr/local/cuda-11.0

# can remove this
NV_CODEC=`pwd`/../Video_Codec_SDK_9.1.23
 
./configure \
     --extra-cflags='-I${NV_CODEC}/include -I$X264_PATH -I/usr/local/cuda/include' \
    --extra-ldflags='-L${NV_CODEC}/Lib/linux/stubs/x86_64 -L$X264_PATH -L/usr/local/cuda/lib64 -ldl ' \
    --pkg-config-flags=--static \
    --enable-libx264 --enable-gpl \
    --enable-cuvid --enable-nvenc --enable-nonfree \
    --nvcc=$CUDA_PATH/bin/nvcc \
    --disable-encoders --enable-encoder=h264_nvenc,nvenc_h264,aac,libx264 \
    --disable-decoders --enable-decoder=aac,h264,h264_cuvid,png \
    --disable-muxers   --enable-muxer=flv \
    --disable-demuxers --enable-demuxer=flv,image2 \
    --disable-filters  --enable-filter=overlay,amix,scale,pad,aformat,crop,aresample,crop,asplit \
    --enable-debug=gdb3
 
make
 
sudo make install
  • 測試h264_nvenc
ffmpeg -h encoder=h264_nvenc
ffmpeg version 4.2.3 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-39)
  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
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Encoder h264_nvenc [NVIDIA NVENC H.264 encoder]:
    General capabilities: delay hardware 
    Threading capabilities: none
    Supported pixel formats: yuv420p nv12 p010le yuv444p p016le yuv444p16le bgr0 rgb0 cuda
h264_nvenc AVOptions:
  -preset            <int>        E..V..... Set the encoding preset (from 0 to 11) (default medium)

  • test

    h264_cuvid

    ffmpeg -h decoder=h264_cuvid
    ffmpeg version 4.2.3 Copyright (c) 2000-2020 the FFmpeg developers
      built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-39)
      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
      libswscale      5.  5.100 /  5.  5.100
      libswresample   3.  5.100 /  3.  5.100
      libpostproc    55.  5.100 / 55.  5.100
    Decoder h264_cuvid [Nvidia CUVID H264 decoder]:
        General capabilities: delay avoidprobe hardware 
        Threading capabilities: none
        Supported hardware devices: cuda 
        Supported pixel formats: cuda nv12 p010le p016le
    h264_cuvid AVOptions:
      -deint             <int>        .D.V..... Set deinterlacing mode (from 0 to 2) (default weave)
         weave                        .D.V..... Weave deinterlacing (do nothing)
         bob                          .D.V..... Bob deinterlacing
         adaptive                     .D.V..... Adaptive deinterlacing
      -gpu               <string>     .D.V..... GPU to be used for decoding
      -surfaces          <int>        .D.V..... Maximum surfaces to be used for decoding (from 0 to INT_MAX) (default 25)
      -drop_second_field <boolean>    .D.V..... Drop second field when deinterlacing (default false)
      -crop              <string>     .D.V..... Crop (top)x(bottom)x(left)x(right)
      -resize            <string>     .D.V..... Resize (width)x(height)
    

     

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章