Skip to content

Instantly share code, notes, and snippets.

@sbrown7792
Last active August 30, 2023 04:10
Show Gist options
  • Save sbrown7792/855858a2a6ab812126dbb6580ae4418e to your computer and use it in GitHub Desktop.
Save sbrown7792/855858a2a6ab812126dbb6580ae4418e to your computer and use it in GitHub Desktop.
TDarr mod to run second node (same PC) on second GPU - For reference only (took me 5 hours to come up with this, I probably won't be able to help if you run into problems)
@echo off
echo %* > D:\TDarr_1\Tdarr_Node\node_modules\@ffmpeg-installer\win32-x64\arg.txt
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "D:\TDarr_1\Tdarr_Node\node_modules\@ffmpeg-installer\win32-x64\ffmpeg_gpu1.ps1"
$Logfile = "D:\TDarr_1\Tdarr_Node\PS.log"
Function LogWrite
{
Param ([string]$logstring)
Add-content $Logfile -value $logstring
}
#get the saved arguments from the batch file
$desired_args = Get-Content "D:\TDarr_1\Tdarr_Node\node_modules\@ffmpeg-installer\win32-x64\arg.txt" -First 1
LogWrite "Before: "
LogWrite $desired_args
#insert the -gpu 1 flag where it belongs. hopefully the 9999 argumenent will always be there....
$desired_args = $desired_args -replace "-i", "-gpu 1 -i"
$desired_args = $desired_args -replace "9999", "9999 -gpu 1"
LogWrite "After: "
LogWrite $desired_args
#tdarr seems to execute ffmpeg when booting to make sure it works, so allow it to run without args
if ($desired_args -eq $null) {
& D:\TDarr_1\Tdarr_Node\node_modules\@ffmpeg-installer\win32-x64\ffmpeg_gpu1.exe
} else {
Start-Process D:\TDarr_1\Tdarr_Node\node_modules\@ffmpeg-installer\win32-x64\ffmpeg_gpu1.exe -NoNewWindow -ArgumentList $desired_args
}
@sbrown7792
Copy link
Author

@heinowalther Much thanks to you and the discord! I haven't tested it on my system yet, but once I do, I will update the gist accordingly :)

@simeononsecurity
Copy link

Would be great if you had a linux version of this. Thanks!

@sbrown7792
Copy link
Author

@heinowalther Finally got a chance to test this - worked perfectly! I updated the gist, thanks!

@simeononsecurity Unfortunately none of my linux servers have GPUs in them, so I don't use them for transcoding & wouldn't be able to test out anything. At a high-level though, the powershell could be replaced with a bash script, and something like "sed 's/9999/9999 -gpu 1/'" would do the argument insertion.

@CanonCan
Copy link

CanonCan commented May 30, 2022

Hi there @sbrown7792

Running two nvidia card on one system (Windows 10 21H2) one RTX 3060 (GPU-0) and a Quadro P2000 (GPU-1) i tried your gist and get and find ffmpeg is still using gpu 0 (the RTX) when transcoding

here is my PS1

$Logfile = "C:\Tdarr_Updater-p2000\Tdarr_Node\PS.log"

Function LogWrite
{
Param ([string]$logstring)

Add-content $Logfile -value $logstring
}

#get the saved arguments from the batch file
$desired_args = Get-Content "C:\Tdarr_Updater-p2000\Tdarr_Node\node_modules@ffmpeg-installer\win32-x64\arg.txt" -First 1

LogWrite "Before: "
LogWrite $desired_args

#insert the -gpu 1 flag where it belongs. hopefully the 9999 argumenent will always be there....
$desired_args = $desired_args -replace "-i", "-gpu 1 -i"
$desired_args = $desired_args -replace "9999", "9999 -gpu 1"

LogWrite "After: "
LogWrite $desired_args

#tdarr seems to execute ffmpeg when booting to make sure it works, so allow it to run without args
if ($desired_args -eq $null) {
& C:\Tdarr_Updater-p2000\Tdarr_Node\node_modules@ffmpeg-installer\win32-x64\ffmpeg.exe
} else {
Start-Process C:\Tdarr_Updater-p2000\Tdarr_Node\node_modules@ffmpeg-installer\win32-x64\ffmpeg.exe -NoNewWindow -ArgumentList $desired_args
}

@jbeck22
Copy link

jbeck22 commented Sep 17, 2022

can someone help me with the .bat file. My arg.txt file only contains %* and I get [NULL @ 000001c42af49c40] Unable to find a suitable output format for 'ECHO'
ECHO: Invalid argument
can anyone help?

@SQLServerIO
Copy link

I couldn't get ffmpeg to actually pick up my second gpu a RTX A2000. I ended up replacing this:
#insert the -gpu 1 flag where it belongs. hopefully the 9999 argumenent will always be there....
$desired_args = $desired_args -replace "-i", "-gpu 1 -i"
$desired_args = $desired_args -replace "9999", "9999 -gpu 1"

with this:
$desired_args = $desired_args -replace "-v error", "-v error -hwaccel_device 1"

and it seems to work for me.

@SQLServerIO
Copy link

Well,
-hwaccel_device 1 doesn't work with encodes just decodes apparently.

@sbrown7792
Copy link
Author

@jbeck22 , @SQLServerIO , @CanonCan , and @anyone_else

Not sure if any of you are still having problems with this, but looks like TDarr officially got a new plugin which does the multi-GPU support natively. I haven't had a chance to check it out, but just wanted to bring it to your attention, should you still need it.

HaveAGitGat/Tdarr_Plugins#423

@CanonCan
Copy link

CanonCan commented Aug 29, 2023 via email

@SQLServerIO
Copy link

I'm still running custom scripts. I'll take a poke at it.

@jbeck22
Copy link

jbeck22 commented Aug 30, 2023

I want to try it out, but how do I add it to Tdarr? I know how to add community plugins already...just not sure which one this is listed under.

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