Hardware assisted ffmpeg with Jetpack 4.5.1

Hi all,

I’m still struggling with my Jetson Nano 2GB board.

After desisting for now to make OpenCV work with CUDA (will recover this topic in the future), the next thing is to try to get ffmpeg to encode video using the CUDA magic.

I’m playiog with this topic with both a VIZI AI board (Atom + Myriad X) and the Jetson Nano 2GB board.

In the case of the Vizi board, I have been able to compile ffmpeg to use Quick Sync, but the Atom is unable to reach my performance expectations (12FPS at 720p) due to the lack of power of the Atom GPU, and seems Quick Sync is unable to exploit Myriad X to encode video, thus no matter what I do to speed up inference, the truth is, I’m unable to encode fast enough with that board.

So, before getting to solve the other issues in the Nano, I need to check that at least is able to encode video at the required speed.

After installing latest cmake from source, I follow the intructions I found here:

Using FFmpeg with NVIDIA GPU Hardware Acceleration :: NVIDIA Video Codec SDK Documentation

I understand both CUDA Toolkit and Driver are installed as says the readme but when running:

./configure --enable-nonfree --enable-cuda-sdk --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
ERROR: failed checking for nvcc.

I get the error related to nvcc

What should I do?

It is a fresh Jetpack 4.5.1 install, with all packages upgraded and cmake in the latest version by compilation.

Thank you very much

Probably you’re lacking /usr/local/cuda/bin in PATH. Try:

export PATH=$PATH:/usr/local/cuda/bin

Ok, that make it partially.

After your suggestion, I have been able to configure, compile and install.

I see the nvenc are present in the binary:

ffmpeg -encoders | grep nvenc
ffmpeg version N-102605-g4c705a2775 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 7 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
  configuration: --enable-nonfree --enable-cuda-nvcc --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
  libavutil      57.  0.100 / 57.  0.100
  libavcodec     59.  1.100 / 59.  1.100
  libavformat    59.  2.101 / 59.  2.101
  libavdevice    59.  0.100 / 59.  0.100
  libavfilter     8.  0.101 /  8.  0.101
  libswscale      6.  0.100 /  6.  0.100
  libswresample   4.  0.100 /  4.  0.100
 V....D h264_nvenc           NVIDIA NVENC H.264 encoder (codec h264)
 V....D hevc_nvenc           NVIDIA NVENC hevc encoder (codec hevc)

But when running the sample command you have in the same instruction URL I get the following:

ffmpeg -y -vsync 0 -hwaccel cuda -hwaccel_output_format cuda -i sample.mp4 -c:a copy -c:v h264_nvenc -b:v 5M output.mp4
ffmpeg version N-102605-g4c705a2775 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 7 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
  configuration: --enable-nonfree --enable-cuda-nvcc --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
  libavutil      57.  0.100 / 57.  0.100
  libavcodec     59.  1.100 / 59.  1.100
  libavformat    59.  2.101 / 59.  2.101
  libavdevice    59.  0.100 / 59.  0.100
  libavfilter     8.  0.101 /  8.  0.101
  libswscale      6.  0.100 /  6.  0.100
  libswresample   4.  0.100 /  4.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'sample.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.44.100
  Duration: 00:00:05.76, start: 0.000000, bitrate: 3956 kb/s
  Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 3857 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc. Created on: 08/17/2020.
      vendor_id       : [0][0][0][0]
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc. Created on: 08/17/2020.
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_nvenc))
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[h264 @ 0x55cdb96f70] Cannot load libnvcuvid.so.1
[h264 @ 0x55cdb96f70] Failed loading nvcuvid.
[h264 @ 0x55cdb96f70] Failed setup for format cuda: hwaccel initialisation returned error.
[h264_nvenc @ 0x55cd65c280] Cannot load libnvidia-encode.so.1
[h264_nvenc @ 0x55cd65c280] The minimum required Nvidia driver for nvenc is 455.28 or newer
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!

Any clue?

Thank you VERY much

With Jetsons, you have dedicated HW encoder/decoder so you wouldn’t use GPU nor nvcuvid for that.
There is a NVIDIA jetson version of ffmeg that can be installed through apt. Not sure if recent versions provide more than decoding for H264.
I’ve also used jocover’s nvmpi version such as here for ffmpeg with HWENC.
However, this might be tricky with the ffmpeg include and library paths and setting further environment.

Hi,
Please check
Jetson Nano FAQ
[Q: Is hardware acceleration enabled in ffmpeg?]

We enable hardware decoding in our package. For hardware encoding, you may try the community contribution.

You may find the following post useful if you are looking for both hardware encoding and decoding in ffmpeg:

Yes, I’m aware the repository ffmpeg only supports hardware decoding. That’s why I tried to compile my own following the nvidia site instructions

Definetly will look into both alternatives you guys provide. Thank you. Will keep you posted.