最近賣掉 4090 主機,但考慮了一下又買回了一張 4070 顯卡,主要是希望能在主要用的機器上面進行編碼加速和一點點的 AI 應用。要進行編碼,就包擴了 H264, HEVC, 與 AV1。這次是參考了 NVIDIA 的官網,怎麼在 WSL 完成這個用途。https://docs.nvidia.com/video-technologies/video-codec-sdk/12.0/ffmpeg-with-nvidia-gpu/index.html
與 Linux 不同處應該是在 WSL 要完成這個 ffmpeg 加速,在 Linux 機器上的應用,之前應該有提過了。
編譯流程
1 2 3 4 5 6 7 8 9 |
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git cd nv-codec-headers && sudo make install git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg/ cd ffmpeg sudo apt-get install build-essential yasm cmake libtool libc6 libc6-dev unzip wget libnuma1 libnuma-dev sudo apt-get install nvidia-cuda-toolkit ./configure --enable-nonfree --enable-cuda-nvcc --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64 --enable-static --disable-x86asm make -j `nproc` sudo make install |
轉碼流程
1 |
ffmpeg -y -vsync 0 -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 -c:a copy -c:v h264_nvenc output_h264.mp4 |
1 |
ffmpeg -y -vsync 0 -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 -c:a copy -c:v hevc_nvenc output_265.mp4 |
1 |
ffmpeg -y -vsync 0 -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 -c:a copy -c:v av1_nvenc output_av1.mp4 |
結語
利用硬體來編碼影片,應該是一個普遍可行的方法了,但還不是普遍,需要自己下指令。希望此篇可以幫助更多人加速此流程。