Skip to content

Commit

Permalink
encoding: Fix low bitrate check
Browse files Browse the repository at this point in the history
  • Loading branch information
Penwy committed Dec 12, 2024
1 parent 5bff778 commit b7c327f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 49 deletions.
89 changes: 42 additions & 47 deletions checks/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import re


params_re = re.compile(r"\t(?P<key>\w+):\s*(?P<value>\S+)")


def checkAttempt(lines):
recordingStarts = search('== Recording Start ==', lines)
streamingStarts = search('== Streaming Start ==', lines)
Expand Down Expand Up @@ -42,21 +45,46 @@ def checkCustom(lines):
"""Custom FFMPEG output is in use. Only absolute professionals should use this. If you got your settings from a YouTube video advertising "Absolute best OBS settings" then we recommend using one of the presets in Simple output mode instead."""]


def checkStreamSettingsX264(lines):
streamingSessions = []
for i, s in enumerate(lines):
if "[x264 encoder: 'simple_h264_stream'] settings:" in s:
streamingSessions.append(i)

if (len(streamingSessions) > 0):
bitrate = float(lines[streamingSessions[-1] + 2].split()[-1])
fps_num = float(lines[streamingSessions[-1] + 5].split()[-1])
fps_den = float(lines[streamingSessions[-1] + 6].split()[-1])
width = float(lines[streamingSessions[-1] + 7].split()[-1])
height = float(lines[streamingSessions[-1] + 8].split()[-1])
def checkStreamSettings(lines):
streamingSessions = searchWithIndex("stream'] settings:", lines)
if streamingSessions:
encode_params = {"bitrate": None,
"height": None,
"width": None,
"fps_num": None,
"fps_den": None,
}
line = streamingSessions[-1][1]
match = params_re.search(lines[line + 1])
while match:
for key in encode_params:
if key in match.group("key"):
try:
encode_params[key] = float(match.group("value"))
except (ValueError, OverflowError):
pass
line += 1
try:
match = params_re.search(lines[line])
except IndexError:
match = False

# If bitrate isn't listed in the encode parameters or isn't a number, don't perform the check
if encode_params["bitrate"] is None:
return

# If fps or resolution aren't listed in encode parameters or aren't a number, fetch them from the video settings
line = searchWithIndex("video settings reset:", lines[:line])[-1][1]
try:
if encode_params["height"] is None or encode_params["width"] is None:
encode_params["width"], encode_params["height"] = (int(_) for _ in (lines[line + 2].split()[-1]).split("x"))
if encode_params["fps_den"] is None or encode_params["fps_num"] is None:
encode_params["fps_num"], encode_params["fps_den"] = (int(_) for _ in (lines[line + 4].split()[-1]).split("/"))
except (ValueError, OverflowError):
return # If fetching them from the video settings fails, don't perform the check

bitrateEstimate = (width * height * fps_num / fps_den) / 20000
if (bitrate < bitrateEstimate):
bitrateEstimate = (encode_params["width"] * encode_params["height"] * encode_params["fps_num"] / encode_params["fps_den"]) / 20000
if (encode_params["bitrate"] < bitrateEstimate):
return [LEVEL_INFO, "Low Stream Bitrate",
"Your stream encoder is set to a video bitrate that is too low. This will lower picture quality especially in high motion scenes like fast paced games. Use the Auto-Config Wizard to adjust your settings to the optimum for your situation. It can be accessed from the Tools menu in OBS, and then just follow the on-screen directions."]

Expand All @@ -69,39 +97,6 @@ def checkNVENC(lines):
"""The NVENC Encoder failed to start due of a variety of possible reasons. Make sure that Windows Game Bar and Windows Game DVR are disabled and that your GPU drivers are up to date. <br><br>You can perform a clean driver installation for your GPU by following the instructions at <a href="http://obsproject.com/forum/resources/performing-a-clean-gpu-driver-installation.65/"> Clean GPU driver installation</a>. <br>If this doesn't solve the issue, then it's possible your graphics card doesn't support NVENC. You can change to a different Encoder in Settings > Output."""]


def checkStreamSettingsNVENC(lines):
videoSettings = []
fps_num, fps_den = 0, 1
for i, s in enumerate(lines):
if "video settings reset:" in s:
videoSettings.append(i)
if (len(videoSettings) > 0):
for i in range(7):
chunks = lines[videoSettings[-1] + i].split()
if (chunks[-2] == 'fps:'):
fps_num, fps_den = (int(x) for x in chunks[-1].split('/'))
streamingSessions = []
for i, s in enumerate(lines):
if "[NVENC encoder: 'streaming_h264'] settings:" in s:
streamingSessions.append(i)
if (len(streamingSessions) > 0):
bitrate = 0
width = 0
height = 0
for i in range(12):
chunks = lines[streamingSessions[-1] + i].split()
if (chunks[-2] == 'bitrate:'):
bitrate = float(chunks[-1])
elif (chunks[-2] == 'width:'):
width = float(chunks[-1])
elif (chunks[-2] == 'height:'):
height = float(chunks[-1])
bitrateEstimate = (width * height * fps_num / fps_den) / 20000
if (bitrate < bitrateEstimate):
return [LEVEL_INFO, "Low Stream Bitrate",
"Your stream encoder is set to a video bitrate that is too low. This will lower picture quality especially in high motion scenes like fast paced games. Use the Auto-Config Wizard to adjust your settings to the optimum for your situation. It can be accessed from the Tools menu in OBS, and then just follow the on-screen directions."]


def checkEncodeError(lines):
if (len(search('Error encoding with encoder', lines)) > 0):
return [LEVEL_INFO, "Encoder start error",
Expand Down
3 changes: 1 addition & 2 deletions loganalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ def doAnalysis(url=None, filename=None):
checkEncodeError(logLines),
checkEncoding(logLines),
checkMulti(logLines),
checkStreamSettingsX264(logLines),
checkStreamSettingsNVENC(logLines),
checkStreamSettings(logLines),
checkMicrosoftSoftwareGPU(logLines),
checkWasapiSamples(logLines),
checkOpenGLonWindows(logLines),
Expand Down

0 comments on commit b7c327f

Please sign in to comment.