From c2cd7c1589b0a71c23625ed7abda362577b143f0 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 12 Oct 2025 20:27:25 +1300 Subject: [PATCH] Update transcode_bench.py --- transcode_bench.py | 66 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/transcode_bench.py b/transcode_bench.py index f3928d0..130ce2d 100755 --- a/transcode_bench.py +++ b/transcode_bench.py @@ -345,7 +345,7 @@ class TranscodeJob: """Execute the transcode job.""" try: # Build FFmpeg command - cmd = ['ffmpeg', '-y'] + cmd = ['ffmpeg', '-y', '-nostdin', '-stats'] # Add hardware acceleration args (before input) if self.hwaccel_args: @@ -404,12 +404,54 @@ class TranscodeJob: def _parse_fps(self, ffmpeg_output: str) -> float: """Parse average FPS from FFmpeg output.""" 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'): - if 'fps=' in line: - fps_str = line.split('fps=')[1].split()[0] - return float(fps_str) - except: + if 'fps=' in line and 'frame=' in line: + # Extract fps value + try: + 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 return 0.0 @@ -496,8 +538,18 @@ class Benchmark: print(f"✓ (avg {avg_fps:.1f} fps)") 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 - low, high = 2, 64 + low, high = 2, estimated_max while low <= high: mid = (low + high) // 2