Created
June 8, 2021 15:39
-
-
Save nicko88/0c23f34edec96a1eb2bd04002826ba5a to your computer and use it in GitHub Desktop.
Plex Transcoder parameter modification script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import subprocess | |
import os | |
args = sys.argv | |
vidinfo = "" | |
bitrate = 0 | |
fixedRes = 0 | |
fhd = "false" | |
subs = "false" | |
audio = 0 | |
afIndex = 0 | |
#get some variables | |
for index, item in enumerate(args, start=0): | |
if "maxrate" in item: | |
bitrate = int(args[index + 1][:-1]) | |
bitrateIndex = index | |
if "scale_cuda=w" in item: | |
resIndex = index | |
if "Audio/Music" in item: | |
afIndex = index + 2 | |
#determine bitrates and resolution | |
if bitrate > 0 and bitrate < 500: | |
bitrate = 500 | |
fixedRes = "scale_cuda=720" | |
if bitrate > 500 and bitrate < 1000: | |
bitrate = 1000 | |
fixedRes = "scale_cuda=1024" | |
if bitrate > 1000 and bitrate < 1500: | |
bitrate = 1500 | |
fixedRes = "scale_cuda=1024" | |
if bitrate > 1500 and bitrate < 2000: | |
bitrate = 2000 | |
fixedRes = "scale_cuda=1280" | |
if bitrate > 2000 and bitrate < 3000: | |
bitrate = 3000 | |
fixedRes = "scale_cuda=1600" | |
if bitrate > 3000 and bitrate < 4000: | |
bitrate = 4000 | |
fixedRes = "scale_cuda=1920" | |
if bitrate > 4000: | |
bitrate = 8000 | |
fixedRes = "scale_cuda=1920" | |
#apply bitrates and resolution | |
if bitrate != 0 and fixedRes != 0: | |
args[bitrateIndex - 1] = str(bitrate) + 'k' | |
args[bitrateIndex + 1] = str(bitrate) + 'k' | |
args[bitrateIndex + 3] = str(bitrate * 2) + 'k' | |
resData = args[resIndex] | |
resPrefixIndex = resData.find("scale") | |
resPrefix = resData[0:resPrefixIndex] | |
resMiddle = fixedRes + ":trunc(ow/a/2)*2:" | |
resSuffixIndex = resData.find("format") | |
resSuffix = resData[resSuffixIndex:] | |
args[resIndex] = resPrefix + resMiddle + resSuffix | |
#airpods pro EQ | |
if afIndex != 0: | |
args[afIndex] = ("[0:0]volume=-5dB," | |
"equalizer=f=21:t=q:w=2.71:g=1.1," | |
"equalizer=f=539:t=q:w=1.17:g=-4.4," | |
"equalizer=f=1534:t=q:w=1.32:g=-2.1," | |
"equalizer=f=4329:t=q:w=2.38:g=2.7," | |
"equalizer=f=8622:t=q:w=0.54:g=5.0," | |
"equalizer=f=53:t=q:w=1.15:g=-0.9," | |
"equalizer=f=141:t=q:w=1.78:g=1.2," | |
"equalizer=f=6312:t=q:w=3.35:g=-1.6," | |
"equalizer=f=9536:t=q:w=0.92:g=2.2," | |
"equalizer=f=11139:t=q:w=2.17:g=-3.1" | |
"[0]") | |
#debug output | |
#f = open('/usr/lib/plexmediaserver/test/plexdebug.txt','w') | |
#f.write(resData) | |
#f.write('\n' + '\n' + resPrefix) | |
#f.write('\n' + '\n' + resMiddle) | |
#f.write('\n' + '\n' + resSuffix) | |
#f.write('\n' + '\n' + resPrefix + resMiddle + resSuffix) | |
#for item in args: | |
#f.write("%s\n" % item) | |
#f.write(args[afIndex]) | |
#f.close() | |
#run the real transcoder | |
os.execv('/usr/lib/plexmediaserver/Transcoder', args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment