91 lines
2.4 KiB
Python
91 lines
2.4 KiB
Python
"""
|
|
Test decoder frame rate in isolation without any processing.
|
|
"""
|
|
|
|
import time
|
|
import os
|
|
from dotenv import load_dotenv
|
|
|
|
import sys
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
|
|
|
from services.stream_decoder import StreamDecoderFactory
|
|
|
|
load_dotenv()
|
|
|
|
def main():
|
|
GPU_ID = 0
|
|
STREAM_URL = os.getenv('CAMERA_URL_1', 'rtsp://localhost:8554/test')
|
|
MAX_FRAMES = 100
|
|
|
|
print("=" * 80)
|
|
print("Decoder Frame Rate Test (No Processing)")
|
|
print("=" * 80)
|
|
print(f"\nStream: {STREAM_URL}")
|
|
print(f"Monitoring for {MAX_FRAMES} frames...\n")
|
|
|
|
# Create decoder
|
|
factory = StreamDecoderFactory(gpu_id=GPU_ID)
|
|
decoder = factory.create_decoder(STREAM_URL, buffer_size=30)
|
|
|
|
# Start decoder
|
|
decoder.start()
|
|
|
|
# Wait for connection
|
|
print("Waiting for connection...")
|
|
max_wait = 10
|
|
waited = 0
|
|
while not decoder.is_connected() and waited < max_wait:
|
|
time.sleep(0.5)
|
|
waited += 0.5
|
|
|
|
if not decoder.is_connected():
|
|
print(f"Failed to connect after {max_wait}s!")
|
|
decoder.stop()
|
|
return
|
|
|
|
print(f"✓ Connected\n")
|
|
print("Monitoring frame arrivals...")
|
|
print("-" * 60)
|
|
|
|
last_count = 0
|
|
frame_times = []
|
|
start_time = time.time()
|
|
last_frame_time = start_time
|
|
|
|
while decoder.get_frame_count() < MAX_FRAMES:
|
|
current_count = decoder.get_frame_count()
|
|
|
|
if current_count > last_count:
|
|
current_time = time.time()
|
|
interval = (current_time - last_frame_time) * 1000
|
|
|
|
frame_times.append(interval)
|
|
print(f"Frame {current_count:3d}: interval={interval:6.1f}ms")
|
|
|
|
last_count = current_count
|
|
last_frame_time = current_time
|
|
|
|
time.sleep(0.001) # 1ms poll
|
|
|
|
# Stop decoder
|
|
decoder.stop()
|
|
|
|
# Analysis
|
|
elapsed = time.time() - start_time
|
|
actual_fps = MAX_FRAMES / elapsed
|
|
|
|
print("\n" + "=" * 80)
|
|
print("DECODER PERFORMANCE")
|
|
print("=" * 80)
|
|
print(f"\nFrames received: {MAX_FRAMES}")
|
|
print(f"Time: {elapsed:.1f}s")
|
|
print(f"Actual FPS: {actual_fps:.2f}")
|
|
print(f"\nFrame Intervals:")
|
|
print(f" Min: {min(frame_times[1:]):.1f}ms") # Skip first
|
|
print(f" Max: {max(frame_times[1:]):.1f}ms")
|
|
print(f" Avg: {sum(frame_times[1:])/len(frame_times[1:]):.1f}ms")
|
|
print(f" Expected (6 FPS): 166.7ms")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|