Showing
3 changed files
with
102 additions
and
10 deletions
| @@ -117,8 +117,8 @@ class FootballReplayMatchLive: | @@ -117,8 +117,8 @@ class FootballReplayMatchLive: | ||
| 117 | asr_text = live_video.get("asr_text", '') | 117 | asr_text = live_video.get("asr_text", '') |
| 118 | live_video_contents = live_video.get("llm_contents", None) | 118 | live_video_contents = live_video.get("llm_contents", None) |
| 119 | if live_video_contents is None: | 119 | if live_video_contents is None: |
| 120 | - event_start = event_utc - timedelta(seconds=10) | ||
| 121 | - event_end = event_utc + timedelta(seconds=5) | 120 | + event_start = event_utc - timedelta(seconds=10) if event_utc is not None else None |
| 121 | + event_end = event_utc + timedelta(seconds=5) if event_utc is not None else None | ||
| 122 | live_video_contents = self.video2frame.to_llm_contents( live_video_path, | 122 | live_video_contents = self.video2frame.to_llm_contents( live_video_path, |
| 123 | cache=self.cache_dir, | 123 | cache=self.cache_dir, |
| 124 | fps=2, | 124 | fps=2, |
| @@ -192,7 +192,7 @@ class FootballReplayMatchLive: | @@ -192,7 +192,7 @@ class FootballReplayMatchLive: | ||
| 192 | if len(live_videos_groups) > 1: | 192 | if len(live_videos_groups) > 1: |
| 193 | match_result = [] | 193 | match_result = [] |
| 194 | for live_videos_group in live_videos_groups: | 194 | for live_videos_group in live_videos_groups: |
| 195 | - g_live = self._match_once(replay_video_contents, live_videos_group, cache_path, record) | 195 | + g_live = self._match_once(replay_video_contents, live_videos_group, record) |
| 196 | if g_live is None: | 196 | if g_live is None: |
| 197 | continue | 197 | continue |
| 198 | match_result.append(g_live) | 198 | match_result.append(g_live) |
| @@ -201,7 +201,7 @@ class FootballReplayMatchLive: | @@ -201,7 +201,7 @@ class FootballReplayMatchLive: | ||
| 201 | else: | 201 | else: |
| 202 | return self._match_batch(replay_video_contents, match_result, max_parallel, cache_path, record) | 202 | return self._match_batch(replay_video_contents, match_result, max_parallel, cache_path, record) |
| 203 | elif len(live_videos_groups) == 1: | 203 | elif len(live_videos_groups) == 1: |
| 204 | - return self._match_once(replay_video_contents, live_videos_groups[0], cache_path, record) | 204 | + return self._match_once(replay_video_contents, live_videos_groups[0], record) |
| 205 | else: | 205 | else: |
| 206 | return None | 206 | return None |
| 207 | 207 | ||
| @@ -252,4 +252,4 @@ class FootballReplayMatchLive: | @@ -252,4 +252,4 @@ class FootballReplayMatchLive: | ||
| 252 | os.makedirs(Path(cache_path).parent, exist_ok=True) | 252 | os.makedirs(Path(cache_path).parent, exist_ok=True) |
| 253 | with open(cache_path, 'w', encoding='utf-8') as f: | 253 | with open(cache_path, 'w', encoding='utf-8') as f: |
| 254 | f.write(json.dumps(record, ensure_ascii=False, indent=4)) | 254 | f.write(json.dumps(record, ensure_ascii=False, indent=4)) |
| 255 | - return result_no_content | 255 | + return result_no_content |
| @@ -87,11 +87,7 @@ class FootballReplayVideoEvent: | @@ -87,11 +87,7 @@ class FootballReplayVideoEvent: | ||
| 87 | cache_path = os.path.join(cache_dir, 'video_event.json') | 87 | cache_path = os.path.join(cache_dir, 'video_event.json') |
| 88 | if cache_path is not None and os.path.exists(cache_path): | 88 | if cache_path is not None and os.path.exists(cache_path): |
| 89 | with open(cache_path, 'r', encoding='utf-8') as f: | 89 | with open(cache_path, 'r', encoding='utf-8') as f: |
| 90 | - return json.loads(f.read()) | ||
| 91 | - | ||
| 92 | - # contents = video_contents(video_path, None, video_name=os.path.basename(video_path), | ||
| 93 | - # fps=2, max_frames=999, sampling_mode="head", max_short_edge=480) | ||
| 94 | - | 90 | + return json.loads(f.read()) |
| 95 | 91 | ||
| 96 | event_start = replay_pack.get("start_utc", None) | 92 | event_start = replay_pack.get("start_utc", None) |
| 97 | event_end = replay_pack.get("end_utc", None) | 93 | event_end = replay_pack.get("end_utc", None) |
| 1 | +from football_replay_match_live import FootballReplayMatchLive | ||
| 2 | +# from qwen_asr_util import QwenAsr | ||
| 3 | +from football_replay_video_event_by_llm import FootballReplayVideoEvent | ||
| 4 | +import os | ||
| 5 | +import json | ||
| 6 | + | ||
| 7 | + | ||
| 8 | +def batch_match(): | ||
| 9 | + cache_dir = "/root/lzw/tmp_0518_replay_cache03" | ||
| 10 | + replay_match_live = FootballReplayMatchLive(base_url="http://192.168.1.59:11434/v1", | ||
| 11 | + model="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf", | ||
| 12 | + temperature=0.7, | ||
| 13 | + cache_dir=cache_dir, | ||
| 14 | + save_frames_enable=True | ||
| 15 | + ) | ||
| 16 | + # qwen_asr = QwenAsr(base_url="http://192.168.1.59:8101/v1", model="Qwen/Qwen3-ASR-1.7B") | ||
| 17 | + fbrv = FootballReplayVideoEvent(base_url="http://192.168.1.59:11434/v1", | ||
| 18 | + model="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf", | ||
| 19 | + temperature=0.7, | ||
| 20 | + cache_dir=cache_dir, | ||
| 21 | + save_frames_enable=True | ||
| 22 | + ) | ||
| 23 | + | ||
| 24 | + videos_dir = rf"/root/lzw/finished" | ||
| 25 | + for video_name in sorted(os.listdir(videos_dir)): | ||
| 26 | + | ||
| 27 | + live_dir = os.path.join(videos_dir, video_name, 'live') | ||
| 28 | + print(f"live_dir: {live_dir}") | ||
| 29 | + | ||
| 30 | + live_video_dir = os.path.join(live_dir, 'videos') | ||
| 31 | + live_asr_dir = os.path.join(live_dir, 'asr') | ||
| 32 | + | ||
| 33 | + live_packs = [] | ||
| 34 | + for live_video_name in sorted(os.listdir(live_video_dir)): | ||
| 35 | + live_video_path = os.path.join(live_video_dir, live_video_name) | ||
| 36 | + live_asr_path = os.path.join(live_asr_dir, f"{live_video_name}.txt") | ||
| 37 | + # live_asr_text = qwen_asr.asr(live_video_path, cache_path=live_asr_path) | ||
| 38 | + live_asr_text = '' | ||
| 39 | + live_packs.append({ | ||
| 40 | + "video_id": os.path.basename(live_video_path), | ||
| 41 | + "url": live_video_path, | ||
| 42 | + "asr_text": live_asr_text | ||
| 43 | + }) | ||
| 44 | + | ||
| 45 | + replays_dir = os.path.join(videos_dir, video_name, 'replays') | ||
| 46 | + replay_videos_dir = os.path.join(replays_dir, 'videos') | ||
| 47 | + replay_goals_dir = os.path.join(replays_dir, 'goals') | ||
| 48 | + replay_asr_dir = os.path.join(replays_dir, 'asr') | ||
| 49 | + replay_matches_dir = os.path.join(replays_dir, 'matches') | ||
| 50 | + | ||
| 51 | + for replay_video_name in sorted(os.listdir(replay_videos_dir)): | ||
| 52 | + replay_video_path = os.path.join(replay_videos_dir, replay_video_name) | ||
| 53 | + # replay_goals_path = os.path.join(replay_goals_dir, f"{replay_video_name}.json") | ||
| 54 | + | ||
| 55 | + # replay_asr_path = os.path.join(replay_asr_dir, f"{replay_video_name}.txt") | ||
| 56 | + # replay_match_path = os.path.join(replay_matches_dir, f"{replay_video_name}.json") | ||
| 57 | + | ||
| 58 | + # print(100*"*") | ||
| 59 | + # print(replay_match_path) | ||
| 60 | + replay_match_path = None | ||
| 61 | + | ||
| 62 | + # replay_asr_text = qwen_asr.asr(replay_video_path, cache_path=replay_asr_path) | ||
| 63 | + replay_asr_text = '' | ||
| 64 | + replay_pack = {"url": "http://video.mam.miguvideo.com/mnt6/fastclip3/wsc/2026/04/29/df760b8d15394cbc9ed0d0a4a9c4b786_1080PS/29133605/vodtmp/3b3e99cf4ca84c3782503d8817242de2.m3u8", | ||
| 65 | + "start_utc": 1777444502543, | ||
| 66 | + "end_utc": 1777444531063, | ||
| 67 | + "asr_text": '无' | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + replay_goals = fbrv.video_event(replay_pack, cache_dir=cache_dir) | ||
| 71 | + if replay_goals['event_name'] == '无进球': | ||
| 72 | + continue | ||
| 73 | + # replay_pack = {"video_path": replay_video_path, "asr_text": replay_asr_text} | ||
| 74 | + | ||
| 75 | + try: | ||
| 76 | + import time | ||
| 77 | + start_time = time.time() | ||
| 78 | + print("Start matching...") | ||
| 79 | + print(f"len(live_packs): {len(live_packs)}") | ||
| 80 | + result = replay_match_live.match_batch(replay_pack, live_packs, max_parallel=2, cache_dir=cache_dir) | ||
| 81 | + end_time = time.time() | ||
| 82 | + print(f"Time taken for matching: {end_time - start_time:.2f} seconds") | ||
| 83 | + print(replay_video_path) | ||
| 84 | + print(result) | ||
| 85 | + break | ||
| 86 | + | ||
| 87 | + except Exception as e: | ||
| 88 | + print(f"Error processing {replay_video_path}: {e}") | ||
| 89 | + | ||
| 90 | + print('-' * 20) | ||
| 91 | + | ||
| 92 | + break | ||
| 93 | + | ||
| 94 | + | ||
| 95 | +if __name__ == '__main__': | ||
| 96 | + batch_match() |
-
Please register or login to post a comment