New setting Always transcode if bitrate is above

- Fixes #163
This commit is contained in:
tomkat83 2016-12-17 17:54:46 +01:00
parent cb32ffae56
commit 08eaf21a17
4 changed files with 64 additions and 43 deletions

View file

@ -127,6 +127,8 @@
<string id="30141">Enable Background Image (Requires Restart)</string>
<string id="30142">Services</string>
<string id="30143">Always transcode if video bitrate is above</string>
<string id="30150">Skin does not support setting views</string>
<string id="30151">Select item action (Requires Restart)</string>

View file

@ -151,7 +151,8 @@
<string id="30140"> - Themen-Musik in Schleife abspielen</string>
<string id="30141">Laden im Hintergrund aktivieren (Erfordert Neustart)</string>
<string id="30142">Dienste</string>
<string id="30143">Info-Loader aktivieren (Erfordert Neustart)</string>
<string id="30143">Immer transkodieren falls Bitrate höher als</string>
<string id="30144">Menü-Loader aktivieren (Erfordert Neustart)</string>
<string id="30145">WebSocket Fernbedienung aktivieren (Erfordert Neustart)</string>
<string id="30146">'Laufende Medien'-Loader aktivieren (Erfordert Neustart)</string>

View file

@ -59,8 +59,8 @@ class PlayUtils():
playurl = tryEncode(self.API.getTranscodeVideoPath(
'Transcode',
quality={
'maxVideoBitrate': self.getBitrate(),
'videoResolution': self.getResolution(),
'maxVideoBitrate': self.get_bitrate(),
'videoResolution': self.get_resolution(),
'videoQuality': '100'
}))
# Set playmethod property
@ -157,10 +157,17 @@ class PlayUtils():
- HEVC codec
- window variable 'plex_forcetranscode' set to 'true'
(excepting trailers etc.)
- video bitrate above specified settings bitrate
if the corresponding file settings are set to 'true'
"""
videoCodec = self.API.getVideoCodec()
log.info("videoCodec: %s" % videoCodec)
if self.API.getType() in ('clip', 'track'):
log.info('Plex clip or music track, not transcoding')
return False
if window('plex_forcetranscode') == 'true':
log.info('User chose to force-transcode')
return True
if (settings('transcodeHi10P') == 'true' and
videoCodec['bitDepth'] == '10'):
log.info('Option to transcode 10bit video content enabled.')
@ -173,8 +180,15 @@ class PlayUtils():
# e.g. trailers. Avoids TypeError with "'h265' in codec"
log.info('No codec from PMS, not transcoding.')
return False
if window('plex_forcetranscode') == 'true':
log.info('User chose to force-transcode')
try:
bitrate = int(videoCodec['bitrate'])
except (TypeError, ValueError):
log.info('No video bitrate from PMS, not transcoding.')
return False
if bitrate > self.get_max_bitrate():
log.info('Video bitrate of %s is higher than the maximal video'
'bitrate of %s that the user chose. Transcoding'
% (bitrate, self.get_max_bitrate()))
return True
try:
resolution = int(videoCodec['resolution'])
@ -200,32 +214,47 @@ class PlayUtils():
return False
if self.mustTranscode():
return False
# Verify the bitrate
if not self.isNetworkSufficient():
log.info("The network speed is insufficient to direct stream "
"file. Transcoding")
return False
return True
def isNetworkSufficient(self):
"""
Returns True if the network is sufficient (set in file settings)
"""
try:
sourceBitrate = int(self.API.getDataFromPartOrMedia('bitrate'))
except:
log.info('Could not detect source bitrate. It is assumed to be'
'sufficient')
return True
settings = self.getBitrate()
log.info("The add-on settings bitrate is: %s, the video bitrate"
"required is: %s" % (settings, sourceBitrate))
if settings < sourceBitrate:
return False
return True
def getBitrate(self):
def get_max_bitrate(self):
# get the addon video quality
videoQuality = settings('maxVideoQualities')
bitrate = {
'0': 320,
'1': 720,
'2': 1500,
'3': 2000,
'4': 3000,
'5': 4000,
'6': 8000,
'7': 10000,
'8': 12000,
'9': 20000,
'10': 40000,
'11': 99999999 # deactivated
}
# max bit rate supported by server (max signed 32bit integer)
return bitrate.get(videoQuality, 2147483)
def getH265(self):
"""
Returns the user settings for transcoding h265: boundary resolutions
of 480, 720 or 1080 as an int
OR 9999999 (int) if user chose not to transcode
"""
H265 = {
'0': 99999999,
'1': 480,
'2': 720,
'3': 1080
}
return H265[settings('transcodeH265')]
def get_bitrate(self):
"""
Get the desired transcoding bitrate from the settings
"""
videoQuality = settings('transcoderVideoQualities')
bitrate = {
'0': 320,
@ -243,22 +272,10 @@ class PlayUtils():
# max bit rate supported by server (max signed 32bit integer)
return bitrate.get(videoQuality, 2147483)
def getH265(self):
def get_resolution(self):
"""
Returns the user settings for transcoding h265: boundary resolutions
of 480, 720 or 1080 as an int
OR 9999999 (int) if user chose not to transcode
Get the desired transcoding resolutions from the settings
"""
H265 = {
'0': 9999999,
'1': 480,
'2': 720,
'3': 1080
}
return H265[settings('transcodeH265')]
def getResolution(self):
chosen = settings('transcoderVideoQualities')
res = {
'0': '420x420',

View file

@ -98,7 +98,8 @@
<setting id="resumeJumpBack" type="slider" label="30521" default="10" range="0,1,120" option="int" />
<setting type="sep" />
<setting id="playType" type="enum" label="30002" values="Direct Play (default)|Direct Stream|Force Transcode" default="0" />
<setting id="transcoderVideoQualities" type="enum" label="30160" values="420x420, 320Kbps|576x320, 720Kbps|720x480, 1.5Mbps|1024x768, 2Mbps|1280x720, 3Mbps|1280x720, 4Mbps|1920x1080, 8Mbps|1920x1080, 10Mbps|1920x1080, 12Mbps|1920x1080, 20Mbps|1920x1080, 40Mbps" default="10" />
<setting id="transcoderVideoQualities" type="enum" label="30160" values="420x420, 320kbps|576x320, 720kbps|720x480, 1.5Mbps|1024x768, 2Mbps|1280x720, 3Mbps|1280x720, 4Mbps|1920x1080, 8Mbps|1920x1080, 10Mbps|1920x1080, 12Mbps|1920x1080, 20Mbps|1920x1080, 40Mbps" default="10" /><!-- Video Quality if Transcoding necessary -->
<setting id="maxVideoQualities" type="enum" label="30143" values="320kbps|720kbps|1.5Mbps|2Mbps|3Mbps|4Mbps|8Mbps|10Mbps|12Mbps|20Mbps|40Mbps|deactivated" default="11" /><!-- Always transcode if video bitrate is above -->
<setting id="transcodeH265" type="enum" label="30522" default="0" values="Disabled (default)|480p (and higher)|720p (and higher)|1080p" />
<setting id="transcodeHi10P" type="bool" label="39063" default="false"/>
<setting id="transcodeHEVC" type="bool" label="39065" default="false"/>