54 lines
2.1 KiB
Python
Raw Normal View History

2026-02-09 20:47:46 +08:00
from sophon_chakcy.utils.multi_decoder_manager import MultiDecoderManager, TaskArgs
import sophon_chakcy.sail as sail
2025-10-17 14:11:33 +08:00
2026-02-03 21:32:23 +08:00
def main():
2026-02-09 20:47:46 +08:00
hand = sail.Handle(0)
input_output_path = [
# (f"resources/datasets/test_car_person_1080P_{i}.mp4",
(f"rtsp://192.168.137.1:8554/stream",
# f"./results/output{i}.mp4")
f"rtsp://192.168.137.1:8554/stream{i}")
for i in range(8)
]
with MultiDecoderManager() as decoder_manager:
decoder_manager.set_local_flag(True)
try:
for input_path, output_path in input_output_path:
decoder_manager.add_channel(
input_path,
frame_skip_num=20,
loopnum=0,
output=output_path,
task_args=TaskArgs(
task_name=f"task_{input_path.split('/')[-1]}",
algorithms=["yolo_example"],
handle=hand
)
)
while True:
for bmimg, channel_idx in decoder_manager.read_frame_all_channels():
encoder = decoder_manager.get_encoder(channel_idx)
algorithms_list = decoder_manager.get_algorithms(channel_idx)
if encoder is None or bmimg is None:
continue
# if decoder_manager.is_channel_eof(channel_idx):
# decoder_manager.remove_channel(channel_idx)
if algorithms_list is not None:
for algorithm in algorithms_list:
filtered_detections = algorithm.detect(bmimg)
bmimg = algorithm.draw_detections(bmimg, filtered_detections, None)
encoder.video_write(bmimg.data())
if len(decoder_manager.get_active_channels()) == 0:
break
except:
pass
finally:
decoder_manager.cleanup()
2026-02-03 21:32:23 +08:00
2025-10-17 14:11:33 +08:00
if __name__ == "__main__":
2026-02-09 20:47:46 +08:00
main()