Skip to content

Instantly share code, notes, and snippets.

@jeff47
Last active September 16, 2022 15:50
Show Gist options
  • Save jeff47/4ec428e329a485a102bab0398e6ac4be to your computer and use it in GitHub Desktop.
Save jeff47/4ec428e329a485a102bab0398e6ac4be to your computer and use it in GitHub Desktop.

Tdarr_Plugin_A47j_FFMPEG_NVENC_HEVC_Video_Only

Overview

The basis for this plugin is the work of JarBinks.

This is a Tdarr plugin that converts videos to H265/HEVC using nvenc GPU-accelerated encoding. Resolutions higher than 1080p are resized to 1080p. The target bitrate is calculated based on the resolution, frame rate, bitrate, and a compression factor selected by the user.

Audio, subtitles, chapters, and metadata are untouched.

Dependencies:

  • mediainfo
  • mkvpropedit

Bitrate Calculations

The target bitrate (passed to ffmpeg) is as follows:

target_bitrate equation

However, there are two exceptions:

  1. If the target bitrate is greater than 70% of the H264 bitrate, then 70% of the H264 bitrate will be used.
  2. The target bitrate will not be reduced to less than 60% of the original.
  3. If the video is already in H265/HEVC, then it will be transcoded only if it is more than 150% the target. This is avoid quality loss from transcoding for limited gains.

This is based on the theory that H265 provides similar video quality with significant savings over H264.

Additionally, the maximum bitrate (-maxrate) is set to 130% of the target. The minimum (-minrate) is set to 70% of the target.

Installation

It is expected that you have a working installation of Tdarr, with nvenc working in the docker container.

Once the Tdarr container is set up, connect to the container:

sudo docker exec -it tdarr /bin/bash

Then execute these commands:

sudo apt update && apt install mediainfo mkvtoolnix

Note, however, that these additions will be lost when the container is restarted and the plugin will fail. A better option is to use a Dockerfile:

FROM haveagitgat/tdarr:latest
 
RUN sudo apt-get update --allow-releaseinfo-change && \
   sudo apt-get install -y mediainfo mkvtoolnix && \  

Build command: docker build -t jeffr47/tdarr-plus:1.0 . (the name can be anything you want.)

Note:

I believe mediainfo and mkvtoolnix have been updated in the repos to support the needed commands. You can, if needed, use this code to get newer versions:

sudo apt-get update
sudo apt-get install wget
sudo wget https://mediaarea.net/repo/deb/repo-mediaarea_1.0-12_all.deb && sudo dpkg -i repo-mediaarea_1.0-12_all.deb && 

sudo wget -q -O - https://mkvtoolnix.download/gpg-pub-moritzbunkus.txt | sudo apt-key add -
sudo sh -c 'echo "deb https://mkvtoolnix.download/ubuntu/ bionic main" >> /etc/apt/sources.list.d/bunkus.org.list'
sudo sh -c 'echo "deb-src https://mkvtoolnix.download/ubuntu/ bionic main" >> /etc/apt/sources.list.d/bunkus.org.list'
sudo apt update
sudo apt install mkvtoolnix
@jeff47
Copy link
Author

jeff47 commented Jul 21, 2020

target_bitrate equation

@rubenqs12
Copy link

rubenqs12 commented Sep 15, 2020

Thank You!

Its possible this plugin only with the cpu? I have a dual xeon 2680 that I can use for this

PD: If I want a bitrate 12mb, what compression factor should I use? 0.07?

@phtp
Copy link

phtp commented Nov 20, 2020

Are there instructions for Windows?

Edit: Was able to get it going by copying the dependencies to C:\Windows\System32 so it can be called upon regardless of location.

@pwright225
Copy link

will this work with a windows node and a docker server (unraid)? so far i can't get it to work, and that is why i am asking. i really like the described feature set.

@mikiline-ONE
Copy link

mikiline-ONE commented Sep 16, 2022

please can you have a look at
https://github.com/HaveAGitGat/Tdarr_Plugins/issues/312

there is maybe a little bug in this plugin

is it possible to fix ?

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment