Update transcode_bench.py
This commit is contained in:
@@ -345,7 +345,7 @@ class TranscodeJob:
|
|||||||
"""Execute the transcode job."""
|
"""Execute the transcode job."""
|
||||||
try:
|
try:
|
||||||
# Build FFmpeg command
|
# Build FFmpeg command
|
||||||
cmd = ['ffmpeg', '-y']
|
cmd = ['ffmpeg', '-y', '-nostdin', '-stats']
|
||||||
|
|
||||||
# Add hardware acceleration args (before input)
|
# Add hardware acceleration args (before input)
|
||||||
if self.hwaccel_args:
|
if self.hwaccel_args:
|
||||||
@@ -404,12 +404,54 @@ class TranscodeJob:
|
|||||||
def _parse_fps(self, ffmpeg_output: str) -> float:
|
def _parse_fps(self, ffmpeg_output: str) -> float:
|
||||||
"""Parse average FPS from FFmpeg output."""
|
"""Parse average FPS from FFmpeg output."""
|
||||||
try:
|
try:
|
||||||
# Look for the final fps value in output
|
# Look for the last line with fps= (the final summary line)
|
||||||
|
fps_value = None
|
||||||
for line in ffmpeg_output.split('\n'):
|
for line in ffmpeg_output.split('\n'):
|
||||||
if 'fps=' in line:
|
if 'fps=' in line and 'frame=' in line:
|
||||||
fps_str = line.split('fps=')[1].split()[0]
|
# Extract fps value
|
||||||
return float(fps_str)
|
try:
|
||||||
except:
|
fps_str = line.split('fps=')[1].split()[0]
|
||||||
|
fps_value = float(fps_str)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if fps_value and fps_value > 0:
|
||||||
|
return fps_value
|
||||||
|
|
||||||
|
# Fallback: calculate from time and speed
|
||||||
|
# Look for lines like "time=00:00:30.00" and "speed=2.5x"
|
||||||
|
time_seconds = None
|
||||||
|
speed_multiplier = None
|
||||||
|
|
||||||
|
for line in ffmpeg_output.split('\n'):
|
||||||
|
if 'time=' in line:
|
||||||
|
try:
|
||||||
|
time_str = line.split('time=')[1].split()[0]
|
||||||
|
# Parse time format HH:MM:SS.MS
|
||||||
|
parts = time_str.split(':')
|
||||||
|
if len(parts) == 3:
|
||||||
|
h, m, s = parts
|
||||||
|
time_seconds = int(h) * 3600 + int(m) * 60 + float(s)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if 'speed=' in line:
|
||||||
|
try:
|
||||||
|
speed_str = line.split('speed=')[1].split('x')[0]
|
||||||
|
speed_multiplier = float(speed_str)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Calculate effective FPS: if encoding 30fps video at 2x speed, effective fps = 60
|
||||||
|
if time_seconds and speed_multiplier and self.end_time and self.start_time:
|
||||||
|
wall_time = self.end_time - self.start_time
|
||||||
|
if wall_time > 0:
|
||||||
|
# Assume input is 30fps
|
||||||
|
input_fps = 30.0
|
||||||
|
frames = time_seconds * input_fps
|
||||||
|
return frames / wall_time
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
return 0.0
|
return 0.0
|
||||||
|
|
||||||
@@ -496,8 +538,18 @@ class Benchmark:
|
|||||||
print(f"✓ (avg {avg_fps:.1f} fps)")
|
print(f"✓ (avg {avg_fps:.1f} fps)")
|
||||||
max_streams = 1
|
max_streams = 1
|
||||||
|
|
||||||
|
# Estimate maximum possible streams based on single stream performance
|
||||||
|
# If 1 stream achieves X fps, we can theoretically handle X/min_fps streams
|
||||||
|
# Use 80% of theoretical max to account for overhead
|
||||||
|
theoretical_max = int((avg_fps / min_fps) * 0.8)
|
||||||
|
|
||||||
|
# Cap the search space reasonably
|
||||||
|
estimated_max = max(2, min(theoretical_max, 128))
|
||||||
|
|
||||||
|
print(f"Estimated capacity: ~{theoretical_max} streams (searching up to {estimated_max})")
|
||||||
|
|
||||||
# Binary search bounds
|
# Binary search bounds
|
||||||
low, high = 2, 64
|
low, high = 2, estimated_max
|
||||||
|
|
||||||
while low <= high:
|
while low <= high:
|
||||||
mid = (low + high) // 2
|
mid = (low + high) // 2
|
||||||
|
Reference in New Issue
Block a user