match_live_test.py 3 KB
from football_replay_match.core.football_replay_match_live import FootballReplayMatchLive
from qwen_asr_util import QwenAsr
from football_replay_match.core.football_replay_video_event_by_llm import FootballReplayVideoEvent
import os


def batch_match():
    replay_match_live = FootballReplayMatchLive(base_url="http://192.168.1.59:11434/v1", model="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf")
    qwen_asr = QwenAsr(base_url="http://192.168.1.59:8101/v1", model="Qwen/Qwen3-ASR-1.7B")
    fbrv = FootballReplayVideoEvent(base_url="http://192.168.1.59:11434/v1", model="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf", temperature=0.7)

    videos_dir = rf"R:\wdx\202604\20260420_download_football_video\finished"
    for video_name in sorted(os.listdir(videos_dir)):

        live_dir = os.path.join(videos_dir, video_name, 'live')
        live_video_dir = os.path.join(live_dir, 'videos')
        live_asr_dir = os.path.join(live_dir, 'asr')

        live_packs = []
        for live_video_name in sorted(os.listdir(live_video_dir)):
            live_video_path = os.path.join(live_video_dir, live_video_name)
            live_asr_path = os.path.join(live_asr_dir, f"{live_video_name}.txt")
            # live_asr_text = qwen_asr.asr(live_video_path, cache_path=live_asr_path)
            live_asr_text = ''
            live_packs.append({
                "video_id": os.path.basename(live_video_path),
                "video_path": live_video_path,
                "asr_text": live_asr_text
            })

        replays_dir = os.path.join(videos_dir, video_name, 'replays')
        replay_videos_dir = os.path.join(replays_dir, 'videos')
        replay_goals_dir = os.path.join(replays_dir, 'goals')
        replay_asr_dir = os.path.join(replays_dir, 'asr')
        replay_matches_dir = os.path.join(replays_dir, 'matches')

        for replay_video_name in sorted(os.listdir(replay_videos_dir)):
            replay_video_path = os.path.join(replay_videos_dir, replay_video_name)
            replay_goals_path = os.path.join(replay_goals_dir, f"{replay_video_name}.json")

            replay_asr_path = os.path.join(replay_asr_dir, f"{replay_video_name}.txt")
            replay_match_path = os.path.join(replay_matches_dir, f"{replay_video_name}.json")

            # replay_asr_text = qwen_asr.asr(replay_video_path, cache_path=replay_asr_path)
            replay_asr_text = ''

            replay_goals = fbrv.video_event(replay_video_path, cache_path=replay_goals_path)
            if replay_goals['event_name'] == '无进球':
                continue
            replay_pack = {"video_path": replay_video_path, "asr_text": replay_asr_text}

            try:
                result = replay_match_live.match_batch(replay_pack, live_packs, max_parallel=2,
                                                       cache_path=replay_match_path)
                print(replay_video_path)
                print(result)

            except Exception as e:
                print(f"Error processing {replay_video_path}: {e}")

            print('-' * 20)


if __name__ == '__main__':
    batch_match()