Jump to content

Install instructions with NVENC-enabled ffmpeg


Recommended Posts

anubious2k18
Posted (edited)

I got everything working just the way I wanted via the steps below. I hope this helps someone

Install some dependencies:

Quote

apt-get update
apt-get -y upgrade
apt-get install -y apt-transport-https ca-certificates curl \
software-properties-common nfs-common portmap \
apache2-utils gnutls-*

Modify GRUB so that nouveau is disabled. Making a modprobe conf file didn't work for me:

Quote

 

echo "" > /etc/default/grub
cat <<EOF | tee /etc/default/grub
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=" rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nouveau.modeset=0 maybe-ubiquity"
GRUB_CMDLINE_LINUX=""

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"
EOF

 

 

Update your initramfs:

Quote

update-initramfs -u


OPTIONAL: Install docker for 80/443 reverse proxy and ssl cert (Clouflare DNS challenge):

Install docker:

Quote

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
apt update
apt-cache policy docker-ce
apt install docker-ce docker-compose

Quote

systemctl restart docker
systemctl enable docker

 

Enable Ipv6 on docker. I had to do this a while ago and I've never stopped:

Quote

rm -rf /etc/docker/daemon.json
mkdir -p /etc/docker
touch /etc/docker/daemon.json
cat <<EOF | tee /etc/docker/daemon.json
{
"ipv6": true,
"fixed-cidr-v6": "2001:db8:1::/64"
}
EOF


Create nginx (reverse proxy) volumes for predictability:

Quote

docker volume create nginx-data
docker volume create nginx-logs

Create letsencrypt and dnsrobocert directories:

Quote

rm -rf /opt/docker/letsencrypt/
mkdir -p /opt/docker/letsencrypt/
chmod -R 755 /opt/docker
mkdir -p /opt/docker/dnsrobocert
touch /opt/docker/dnsrobocert/config.yml
rm -rf /opt/docker/dnsrobocert/config.yml


Create a dnsrobocert config file:

Quote

cat <<EOF | tee /opt/docker/dnsrobocert/config.yml
draft: false
acme:
  email_account: <YOUR EMAIL FROM CF WEBSITE>
  directory_url: https://acme-v02.api.letsencrypt.org/directory
  crontab_renew: 12 01,13 * * *se
profiles:
- name: cf_profile
  provider: cloudflare
  provider_options:
    auth_username: <YOUR EMAIL FROM CF WEBSITE>
    auth_token: <YOUR AUTH TOKEN FROM CF WEBSITE>
certificates:
- domains:
  - emby.domain.cx
  profile: cf_profile
EOF

Spinup  dnsrobocert:

Quote

docker rm -f certbot-dns
docker run -d \
  --name certbot-dns \
  -h certbot.foundry.cx \
  --env 'LEXICON_PROVIDER=cloudflare' \
  --restart always \
  -v /opt/docker/dnsrobocert:/etc/dnsrobocert \
  -v /opt/docker/letsencrypt:/etc/letsencrypt \
  --net=host \
adferrand/dnsrobocert

Make sure dnsrobocert is restarted once a week:

Quote

(crontab -l 2>/dev/null; echo "0 0 * * 0 docker restart certbot-dns") | crontab -

 

Spinup the reverse proxy:

Quote

docker pull nginx:latest
docker run -d \
    --name rproxy \
    --restart always \
    --volume nginx-data:/etc/nginx \
    --volume nginx-logs:/var/log/nginx \
    --volume /opt/docker/letsencrypt:/etc/letsencrypt \
    --net=host \
    nginx:latest

 


Configure nginx for reverse proxy:
 

Quote

 

certtool --generate-dh-params --outfile /opt/docker/letsencrypt/dh.pem

rm -rf /var/lib/docker/volumes/nginx-data/_data/conf.d/default.conf
touch /var/lib/docker/volumes/nginx-data/_data/conf.d/emby.foundry.cx.conf
cat <<EOF | tee /var/lib/docker/volumes/nginx-data/_data/conf.d/emby.foundry.cx.conf
server {
   listen 80;
   listen [::]:80;
   return 301 https://\$host\$request_uri;
}

server {
   listen       443 ssl http2;
   server_name  emby.foundry.cx;
   ssl_certificate      /etc/letsencrypt/live/emby.foundry.cx/cert.pem;
   ssl_certificate_key  /etc/letsencrypt/live/emby.foundry.cx/privkey.pem;
   ssl_session_timeout  5m;
   ssl_protocols  TLSv1.1 TLSv1.2;
   ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;
   ssl_prefer_server_ciphers   on;

   location / {
     proxy_pass http://localhost:8096;
     proxy_set_header X-Real-IP \$remote_addr;
     proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
     proxy_set_header Host \$http_host;
     proxy_set_header X-NginX-Proxy true;
     # Enables WS support
     proxy_http_version 1.1;
     proxy_set_header Upgrade \$http_upgrade;
     proxy_set_header Connection "upgrade";
     proxy_redirect off;
    }
}
EOF

docker restart rproxy

 

 

Install NVIDIA related dependencies group 1:

Quote

dpkg --add-architecture i386
apt-get update
apt-get -y install build-essential git yasm unzip wget sysstat nasm libc6:i386 \
libavcodec-dev libavformat-dev libavutil-dev pkgconf g++ freeglut3-dev apache2-utils \
libx11-dev libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev build-essential  gnutls-bin \
autoconf automake cmake checkinstall libtool git libcunit1 libcunit1-doc libcunit1-dev zlib1g-dev

Make a temporary directory:

Quote

mkdir ffmpegtemp
cd ffmpegtemp



Download the graphics driver for your hardware from NVIDIA Driver Downloads.  

Make the driver installation package executable:
 

Quote

chmod +x NVIDIA-Linux-*


Run the driver installation package:
 

Quote

 

./NVIDIA-Linux-*

During the installation, acknowledge the following prompts as follows:
 
Accept: License Agreement  
Yes: Install NVIDIA 32-bit compatibility OpenGL libraries  
Yes: Run nvidia-xconfig utility  
OK: Configuration successfully updated

 

 

Then reboot:

Quote

reboot

 

Install SDK samples:

Quote

wget https://www.dropbox.com/s/dejelt1gvt6hiir/Video_Codec_SDK_9.1.23.zip?dl=0
mv Video_Codec_SDK_9.1.23.zip?dl=0 Video_Codec_SDK_9.1.23.zip
unzip Video_Codec_SDK_9.1.23.zip
cp Video_Codec_SDK_9.1.23/Samples/common.mk /usr/local/include/

 

Install NVIDIA related dependencies group 2. I was too lazy to see what should be installed by this point:

Quote

apt-get -y install build-essential autoconf automake cmake libtool git \
checkinstall nasm yasm libass-dev libfreetype6-dev libsdl2-dev p11-kit \
libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev \
libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev libchromaprint-dev \
frei0r-plugins-dev gnutls-dev ladspa-sdk libcaca-dev libcdio-paranoia-dev \
libcodec2-dev libfontconfig1-dev libfreetype6-dev libfribidi-dev libgme-dev \
libgsm1-dev libjack-dev libmodplug-dev libmp3lame-dev libopencore-amrnb-dev \
libopencore-amrwb-dev libopenjp2-7-dev libopenmpt-dev libopus-dev \
libpulse-dev librsvg2-dev librubberband-dev librtmp-dev libshine-dev \
libsmbclient-dev libsnappy-dev libsoxr-dev libspeex-dev libssh-dev \
libtesseract-dev libtheora-dev libtwolame-dev libv4l-dev libvo-amrwbenc-dev \
libvorbis-dev libvpx-dev libwavpack-dev libwebp-dev libx264-dev libx265-dev \
libxvidcore-dev libxml2-dev libzmq3-dev libzvbi-dev liblilv-dev \
libopenal-dev opencl-dev libjack-dev libbluray-dev libfdk-aac-dev libdrm-common \
libdrm-dev libaom-dev aom-tools libmysofa libmysofa-dev

 

Install CUDA (MAKE SURE YOU GET THE LATEST VERSION):

Quote

 Permanantly set environment for toolkit usage

Quote

 

rm -rf /etc/profile.d/cuda.sh
touch /etc/profile.d/cuda.sh

cat <<EOF | tee /etc/profile.d/cuda.sh
export PATH=\$PATH:/usr/local/cuda-11.0/bin
export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/local/cuda-11.0/lib64
export CUDADIR=/usr/local/cuda-11.0
EOF

source /etc/profile.d/cuda.sh

touch /etc/ld.so.conf.d/cuda.conf
echo "/usr/local/cuda/lib64" >> /etc/ld.so.conf.d/cuda.conf
ldconfig

 


 

# Time to build more dependencies for NVENC goodness

Quote

git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
cd nv-codec-headers
make && checkinstall -y --deldoc=yes --pkgversion=1.0.0
cd ~/ffmpegtemp

 

Quote

git clone https://code.videolan.org/videolan/x264.git
cd x264/
./configure --disable-cli --enable-static --enable-shared --enable-strip
make -j 16 && checkinstall -y --deldoc=yes --pkgversion=1.0.0
ldconfig
cd ~/ffmpegtemp

 

Now we configure and build ffmpeg:

Quote

 

git clone git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg/

./configure --enable-gpl --enable-version3 --disable-static \
--enable-shared --enable-small --enable-chromaprint \
--enable-frei0r --enable-gmp --enable-gnutls --enable-ladspa \
--enable-libaom --enable-libass --enable-libcaca --enable-libcdio \
--enable-libcodec2 --enable-libfontconfig --enable-libfreetype \
--enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack \
--enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb \
--enable-libopencore-amrwb --enable-libopencore-amrwb \
--enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse \
--enable-librsvg --enable-librubberband --enable-librtmp --enable-libshine \
--enable-libsnappy --enable-libsoxr --enable-libspeex \
--enable-libssh --enable-libtesseract --enable-libtheora \
--enable-libtwolame --enable-libv4l2 --enable-libvo-amrwbenc \
--enable-libvorbis --enable-libvpx --enable-libwebp \
--enable-libx264 --enable-libx265 --enable-libxvid --enable-libxml2 \
--enable-libzmq --enable-libzvbi --enable-lv2 --enable-libmysofa \
--enable-openal --enable-opencl --enable-opengl --enable-libdrm \
--enable-nonfree --enable-libfdk-aac --enable-libbluray --enable-nvenc \
--enable-cuda --enable-cuvid --enable-cuda-nvcc
make -j 16  && checkinstall -y --deldoc=yes --pkgversion=10:4.2.1

ldconfig

 

# To check NVENC support in FFmpeg:
 

Quote

ffmpeg -codecs | grep nvenc

 

Install emby:

Quote

 

Enable emby:

Quote

systemctl enable emby-server
systemctl restart emby-server


 

Don't forget to open 80,443, and 8096 TCP via ufw.

Thanks and I hope I did not break any forum rules by posting this. 

 

 

 

 

 

Edited by anubious2k18
added steps
Posted

Hi, Emby embeds it's own ffmpeg build. Are you sure yours is actually being used?

anubious2k18
Posted (edited)

I read somewhere that ffmpeg had to be compiled with nvenc support. This was a few emby builds ago. I could not get transcoding to work until I built my own ffmpeg. Maybe it's changed. FYSA, I use a P4000.

 

 

Edit: Here's the link:

 

Edited by anubious2k18
Posted

Can you attach an ffmpeg log example from the server? We'll be able to find out from that.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...