bokumin.org

Github

I want to use ffmpeg even on an old GPU (openSUSE_TW, Geforce GTX 670)

This article is a translation of the following my article:

 

 

* Translated automatically by Google.
* Please note that some links or referenced content in this article may be in Japanese.
* Comments in the code are basically in Japanese.

 

by bokumin

 

FFmpeg on an Old GPU (OpenSUSE Tumbleweed, GeForce GTX 670)

 

Introduction

 

For me, when I work on a PC, I basically access it via SSH and do it on a terminal. I only use the GPU to occasionally connect it to a monitor and start it up in case of an emergency.
I’m basically a person who doesn’t need a graphics card, but I have a Geforce GTX 670 in it just in case. For a long time, it was just stuck, so I was looking for something I could do with it, and I thought that GPU encoding with FFmpeg might improve efficiency, so I decided to give it a try.
This time, I would like to write an article about how to use this old GPU to perform ffmpeg processing.

 

What I used

 

Geforce GTX 670 
‣This is a graphics card released in June 2012, and at that time it was a graphics card with outstanding cost performance and performance comparable to the higher-end model GTX680. Currently, used items are sold for around 4,000 to 6,000 yen.

OS: openSUSE TumbleWeed 6.13
‣Home lab main machine

 

Driver installation

 

Enter the product name in https://www.nvidia.com/ja-jp/drivers/
I found the driver version:470.256.02.

 

 

You can also select and download the file directly from

(https://ja.opensuse.org/SDB:NVIDIA_drivers), but in my case, I checked which driver was appropriate at the URL below and roughly confirmed it.
https://download.nvidia.com/opensuse/tumbleweed/x86_64/

 

For openSUSE, you can download the driver using the following method.

 

sudo zypper addrepo --refresh https://download.nvidia.com/opensuse/tumbleweed NVIDIA
sudo zypper in x11-video-nvidiaG05 
# インストール後、再起動
sudo reboot

# 再起動後、nvidia-smiコマンドで正常に認識されているか確認
nvidia-smi
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.256.02   Driver Version: 470.256.02   CUDA Version:          |
|-------------------------------+----------------------+----------------------+
| 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 ...  Off  | 00000000:01:00.0 N/A |                  N/A |
| 30%   30C    P8    N/A /  N/A |      1MiB /  1998MiB |     N/A      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

 

When you look at nvidia-smi, there are many parts that are N/A.
This does not mean that it is an error, but simply that it cannot be displayed because it is not compatible or old.
(Reference: GPU Memory Usage shows “N/A”)

 

Various things are marked [N/A], but as long as the command is executed and displayed, it’s OK for now. Next, we will download cuda and GCC.

 

CUDA/GCC installation

 

Unfortunately, cuda was not officially distributed with openSUSE TumbleWeed. This time, we will install CUDA distributed by Leap, which is considered to be the most compatible. The CUDA version was determined from the driver’s Release Note.

 

zypper ar https://developer.download.nvidia.com/compute/cuda/repos/opensuse15/x86_64/cuda-opensuse15.repo
zypper --gpg-auto-import-keys refresh
# 今回はcuda 11.4をインストール
zypper -n in -y --auto-agree-with-licenses --no-recommends \
     nv-prefer-signed-open-driver cuda-runtime-11-4

 

For the appropriate GCC version for this CUDA, I referred to the URL below.
https://stackoverflow.com/questions/6622454/cuda-incompatible-with-my-gcc-version
For those who have trouble opening it, I will post a table here.

 

CUDA バージョンGCCバージョン
12.4, 12.513.2
12.1, 12.2, 12.312.2
1212.1
11.4.1+, 11.5, 11.6, 11.7, 11.811
11.1, 11.2, 11.3, 11.4.010
119
10.1, 10.28
9.2, 10.07
9.0, 9.16
85.3
74.9
5.5, 64.8
4.2, 54.6
4.14.5
4.04.4

 

This time, I used CUDA version 11.4, so I downloaded GCC10.

 

sudo zypper install gcc10 gcc10-c++

 

 

nv-codec-headers,Install FFmpeg

 

nv-codec-headers is a group of header files to support NVIDIA GPU video encoding and decoding. Required to integrate FFmpeg and NVIDIA’s hardware acceleration features

 

Now, let’s actually install nv-codec-headers. I chose sdk8.1. *We determined that a relatively older version of the SDK is suitable for the 2012 GTX 670

 

git clone --branch sdk/8.1 https://git.videolan.org/git/ffmpeg/nv-codec-headers.git 
cd nv-codec-headers 
sudo make install

# パスが通ってなかったら
# PKG_CONFIG_PATHにffnvcodecのpkgconfigディレクトリを追加
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"

 

I felt that FFmpeg 4.4.x or FFmpeg 5.0 early release were more compatible, so I installed 5.1 this time.

 

git clone https://github.com/FFmpeg/FFmpeg.git
cd FFmpeg
git checkout release/5.1

 

Switch to GCC10 before installing FFmpeg.

 

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/g++-10 100

 

Install FFmpeg

 

CFLAGS="-O2 -march=native" ./configure --enable-nvenc --enable-cuda --enable-libnpp --enable-cuda-nvcc --enable-libvpx --enable-gpl --enable-version3 --enable-nonfree --enable-libfreetype --extra-cflags="-I/usr/local/cuda/include -I/usr/local/include/ffnvcodec" --extra-ldflags="-L/usr/local/cuda/lib64" --cc=gcc-10 --cxx=g++-10 --nvcc=/usr/local/cuda/bin/nvcc --extra-libs="-lnppc -lnppig -lnpps"

 

If you encounter an error when installing FFmpeg, you can install it by solving the problems one by one as shown below. I think you can find most solutions by searching on the internet.

 

# nvccエラーの場合はパスが通っているかチェック
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"

# freetype2 not found using pkg-configの場合はOpenSUSEの場合
sudo zypper install freetype2-devel

 

Finally, build and install ffmpeg.

 

# ffmpeg ビルド
sudo make

# インストール
sudo make install

# 共有ライブラリのキャッシュ更新
sudo ldconfig

# ffmpegが認識されているか確認
ffmpeg -version
```
ffmpeg version n5.1.6-11-gcde3c5fc0c Copyright (c) 2000-2024 the FFmpeg developers
built with gcc 10 (SUSE Linux)
configuration: --enable-nvenc --enable-cuda --enable-libnpp --enable-cuda-nvcc --enable-libvpx --enable-gpl --enable-version3 --enable-nonfree --enable-libfreetype --extra-cflags='-I/usr/local/cuda/include -I/usr/local/include/ffnvcodec' --extra-ldflags=-L/usr/local/cuda/lib64 --cc=gcc-10 --cxx=g++-10 --nvcc=/usr/local/cuda/bin/nvcc --extra-libs='-lnppc -lnppig -lnpps'
libavutil      57. 28.100 / 57. 28.100
libavcodec     59. 37.100 / 59. 37.100
libavformat    59. 27.100 / 59. 27.100
libavdevice    59.  7.100 / 59.  7.100
libavfilter     8. 44.100 /  8. 44.100
libswscale      6.  7.100 /  6.  7.100
libswresample   4.  7.100 /  4.  7.100
libpostproc    56.  6.100 / 56.  6.100

```

 

CPU/GPU speed comparison

 

The following uses GPU

 

# GPU
time ffmpeg -hwaccel cuda -i /mnt/hdd/movie/20241201_015957271.mp4 -c:v h264_nvenc -preset slow output_video.mp4
real 0m13.633s
user 0m8.239s
sys 0m0.555s

 

The following is what uses the CPU

 

# CPU
time ffmpeg -i /mnt/hdd/movie/20241201_015957271.mp4 -preset slow output_video.mp4
real	0m12.823s
user	0m27.100s
sys	0m0.437s

 

The processing speeds of the CPU and GPU were almost the same…I tried several encoding formats, but they all gave the same results. It’s possible that the hardware acceleration settings are not optimized, but I feel like this is the limit.
For CPU, we can see that although encoding effectively utilizes multiple cores, it consumes more CPU time compared to GPU encoding.
In the case of GPU, user (8.239 seconds) is sometimes shorter than real (13.633 seconds), which indicates that GPU encoding was able to perform encoding while significantly reducing CPU resource consumption.

 

 

Although it was unfortunate that the processing speed of GPU was slower than that of CPU, we found that GPU encoding can significantly reduce the consumption of CPU resources. This can be an important advantage, especially in multitasking environments or long encoding tasks.
In the first place, I think it has sufficient performance for a 2012 graphics card.

 

In the future, I would like to focus on the following points and try further optimization.

 

  • Advanced adjustment of FFmpeg configuration parameters
  • Optimization of CUDA and GCC version combination
  • Detailed configuration verification related to hardware acceleration

 

End