admin管理员组

文章数量:1125555

This is a video frame receiving program using TCP data transfer. I am sending 5400x3010 pixel frame data, but on the receiving side, the video becomes slow. Why is this happening? and how can I solve it?

The 1080p video is being received correctly.

FIFO_PATH = '/tmp/video_fifo'

# Create a named pipe (FIFO)
if not os.path.exists(FIFO_PATH):
os.mkfifo(FIFO_PATH)

# Start the GStreamer pipeline in a subprocess
gst_command = f"gst-launch-1.0 -v filesrc location={FIFO_PATH} ! decodebin ! videoscale ! video/x-raw,width=800,height=480 ! autovideosink"
gst_process = subprocess.Popen(gst_command, shell=True)

# Set up socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind((SERVER_IP, PORT))
sock.listen(1)

print("Waiting for connection...")
conn, addr = sock.accept()
print(f"Connection established with {addr}")

# Prepare to receive data
header = struct.Struct('>L')  # for 4 bytes frame size header

# Open the FIFO for writing
with open(FIFO_PATH, 'wb') as fifo:
  try:
    while True:
        # Receive the frame size header
        data = conn.recv(header.size)
        if not data:
            break
        frame_size = header.unpack(data)[0]

        # Receive the actual frame data
        frame_data = b''
        while len(frame_data) < frame_size:
            packet = conn.recv(frame_size - len(frame_data))
            if not packet:
                break
            frame_data += packet

        # Write the frame data to the FIFO
        fifo.write(frame_data)
        fifo.flush()
except Exception as e:
    print(f"Error: {e}")
finally:
    print("Closing connection...")
    conn.close()

本文标签: pythonHow to solve the lagging issue of gstlaunch10 running videoStack Overflow