lizhengwei

jira:NYJ-1540 desc: match_live_test

... ... @@ -117,8 +117,8 @@ class FootballReplayMatchLive:
asr_text = live_video.get("asr_text", '')
live_video_contents = live_video.get("llm_contents", None)
if live_video_contents is None:
event_start = event_utc - timedelta(seconds=10)
event_end = event_utc + timedelta(seconds=5)
event_start = event_utc - timedelta(seconds=10) if event_utc is not None else None
event_end = event_utc + timedelta(seconds=5) if event_utc is not None else None
live_video_contents = self.video2frame.to_llm_contents( live_video_path,
cache=self.cache_dir,
fps=2,
... ... @@ -192,7 +192,7 @@ class FootballReplayMatchLive:
if len(live_videos_groups) > 1:
match_result = []
for live_videos_group in live_videos_groups:
g_live = self._match_once(replay_video_contents, live_videos_group, cache_path, record)
g_live = self._match_once(replay_video_contents, live_videos_group, record)
if g_live is None:
continue
match_result.append(g_live)
... ... @@ -201,7 +201,7 @@ class FootballReplayMatchLive:
else:
return self._match_batch(replay_video_contents, match_result, max_parallel, cache_path, record)
elif len(live_videos_groups) == 1:
return self._match_once(replay_video_contents, live_videos_groups[0], cache_path, record)
return self._match_once(replay_video_contents, live_videos_groups[0], record)
else:
return None
... ... @@ -252,4 +252,4 @@ class FootballReplayMatchLive:
os.makedirs(Path(cache_path).parent, exist_ok=True)
with open(cache_path, 'w', encoding='utf-8') as f:
f.write(json.dumps(record, ensure_ascii=False, indent=4))
return result_no_content
return result_no_content
\ No newline at end of file
... ...
... ... @@ -87,11 +87,7 @@ class FootballReplayVideoEvent:
cache_path = os.path.join(cache_dir, 'video_event.json')
if cache_path is not None and os.path.exists(cache_path):
with open(cache_path, 'r', encoding='utf-8') as f:
return json.loads(f.read())
# contents = video_contents(video_path, None, video_name=os.path.basename(video_path),
# fps=2, max_frames=999, sampling_mode="head", max_short_edge=480)
return json.loads(f.read())
event_start = replay_pack.get("start_utc", None)
event_end = replay_pack.get("end_utc", None)
... ...
from football_replay_match_live import FootballReplayMatchLive
# from qwen_asr_util import QwenAsr
from football_replay_video_event_by_llm import FootballReplayVideoEvent
import os
import json
def batch_match():
cache_dir = "/root/lzw/tmp_0518_replay_cache03"
replay_match_live = FootballReplayMatchLive(base_url="http://192.168.1.59:11434/v1",
model="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf",
temperature=0.7,
cache_dir=cache_dir,
save_frames_enable=True
)
# 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,
cache_dir=cache_dir,
save_frames_enable=True
)
videos_dir = rf"/root/lzw/finished"
for video_name in sorted(os.listdir(videos_dir)):
live_dir = os.path.join(videos_dir, video_name, 'live')
print(f"live_dir: {live_dir}")
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),
"url": 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")
# print(100*"*")
# print(replay_match_path)
replay_match_path = None
# replay_asr_text = qwen_asr.asr(replay_video_path, cache_path=replay_asr_path)
replay_asr_text = ''
replay_pack = {"url": "http://video.mam.miguvideo.com/mnt6/fastclip3/wsc/2026/04/29/df760b8d15394cbc9ed0d0a4a9c4b786_1080PS/29133605/vodtmp/3b3e99cf4ca84c3782503d8817242de2.m3u8",
"start_utc": 1777444502543,
"end_utc": 1777444531063,
"asr_text": '无'
}
replay_goals = fbrv.video_event(replay_pack, cache_dir=cache_dir)
if replay_goals['event_name'] == '无进球':
continue
# replay_pack = {"video_path": replay_video_path, "asr_text": replay_asr_text}
try:
import time
start_time = time.time()
print("Start matching...")
print(f"len(live_packs): {len(live_packs)}")
result = replay_match_live.match_batch(replay_pack, live_packs, max_parallel=2, cache_dir=cache_dir)
end_time = time.time()
print(f"Time taken for matching: {end_time - start_time:.2f} seconds")
print(replay_video_path)
print(result)
break
except Exception as e:
print(f"Error processing {replay_video_path}: {e}")
print('-' * 20)
break
if __name__ == '__main__':
batch_match()
... ...