我参考文档中的decoder Python API的代码,用12个线程进行12路解码输出,码流使用的是官方测试码流1080P_test.h264, 但是在运行没多久后就会报错,报错信息如下
2025/02/20 21:25:42.974 ERROR [vp_codec_set_input][0714]hb_mm_mc_dequeue_input_buffer failed ret = -268435443
2025/02/20 21:25:42.996 ERROR [vp_codec_set_input][0714]hb_mm_mc_dequeue_input_buffer failed ret = -268435443
2025/02/20 21:25:43.013 ERROR [vp_codec_set_input][0714]hb_mm_mc_dequeue_input_buffer failed ret = -268435443
2025/02/20 21:25:43.028 ERROR [vp_codec_set_input][0714]hb_mm_mc_dequeue_input_buffer failed ret = -268435443
2025/02/20 21:25:43.061 ERROR [vp_codec_set_input][0714]hb_mm_mc_dequeue_input_buffer failed ret = -268435443
2025/02/20 21:25:43.093 ERROR [vp_codec_set_input][0714]hb_mm_mc_dequeue_input_buffer failed ret = -268435443
2025/02/20 21:25:43.096 ERROR [vp_codec_set_input][0714]hb_mm_mc_dequeue_input_buffer failed ret = -268435443
2025/02/20 21:25:43.097 ERROR [vp_codec_set_input][0714]hb_mm_mc_dequeue_input_buffer failed ret = -268435443
2025/02/20 21:25:43.104 ERROR [vp_codec_set_input][0714]hb_mm_mc_dequeue_input_buffer failed ret = -268435443
import time
import signal
import threading
import numpy as np
from hobot_vio import libsrcampy
# Global flag for graceful shutdown
is_running = True
def signal_handler(sig, frame):
global is_running
print("\nCtrl+C received. Stopping all decoders...")
is_running = False
signal.signal(signal.SIGINT, signal_handler)
class DecoderThread(threading.Thread):
def __init__(self, input_file, dec_chn, width=1920, height=1080):
threading.Thread.__init__(self)
self.input_file = input_file
self.dec_chn = dec_chn
self.width = width
self.height = height
self.frame_count = 0
self.decoder = None
def run(self):
global is_running
try:
# Create decoder instance
self.decoder = libsrcampy.Decoder()
# Initialize decoder
ret = self.decoder.decode(self.input_file, self.dec_chn, 1, self.width, self.height)
if ret[0] != 0:
print(f"Channel {self.dec_chn}: Failed to initialize decoder. Return code: {ret[0]}")
return
print(f"Channel {self.dec_chn}: Decoder initialized successfully")
# Main decoding loop
while is_running:
frame = self.decoder.get_img()
if frame is None:
time.sleep(0.01) # Short sleep before retry
continue
self.frame_count += 1
if self.frame_count % 30 == 0: # Print status every 30 frames
print(f"Channel {self.dec_chn}: Decoded {self.frame_count} frames")
except Exception as e:
print(f"Channel {self.dec_chn}: Error during decoding: {str(e)}")
finally:
if self.decoder:
self.decoder.close()
print(f"Channel {self.dec_chn}: Decoder closed. Total frames: {self.frame_count}")
def start_multi_decode(num_channels=12, width=1920, height=1080):
"""
Start multiple decoder threads
"""
# Create and start decoder threads
decoders = []
for i in range(num_channels):
# 使用不同的输入文件
if i == 0:
input_file = "/home/sunrise/evaluation/1080P_test.h264"
else:
input_file = f"/home/sunrise/evaluation/1080P_test_{i}.h264"
decoder = DecoderThread(input_file, i, width, height)
decoders.append(decoder)
decoder.start()
print(f"Started decoder channel {i} with file: {input_file}")
time.sleep(0.5) # Delay between starting decoders
# Wait for all decoders to finish
try:
for decoder in decoders:
decoder.join()
except KeyboardInterrupt:
print("\nWaiting for decoders to stop...")
global is_running
is_running = False
for decoder in decoders:
decoder.join()
print("All decoders stopped")
if __name__ == "__main__":
print("Starting multi-channel video decode")
print("Press Ctrl+C to stop all decoders")
start_multi_decode()