lizhengwei

jira:NYJ-1540 desc: add video name

... ... @@ -23,9 +23,12 @@ class FootballReplayMatch:
self.videoMatchLive = FootballReplayMatchLive(llm_base_url, model_name, temperature, 'no_key', self.cache_dir, save_frames_enable)
def match_by_time(self, replay, events):
start_utc = replay.get('start_utc')
events = [(start_utc - e.get('event_utc'), e) for e in events]
events = [(start_utc - e.get('event_utc'), e) for e in events if e.get('event_utc') is not None]
if len(events) == 0:
return None
events.sort(key=lambda x: x[0])
target_index = next((i for i, e in enumerate(events) if e[0] > 0), -1) # 找到第一个 event_utc 早于 start_utc 的事件
... ... @@ -80,6 +83,7 @@ class FootballReplayMatch:
goal_live_events = [e for e in live_events if str(e.get('type', '')) == '1']
matched_event = self.match_by_time(replay_info, goal_live_events)
# print(f"{task_id}_match_by_time matched_event: {matched_event}")
if matched_event is None:
replay_det_info = self.det_goal_replay(replay_info, task_id)
replay_event_name = replay_det_info.get('event_name', '')
... ...
... ... @@ -9,7 +9,7 @@ api_test.py - 对 api.py 中 FootballReplayMatch.replay_match_event 的单元测
5. 无进球事件 / events 为空
6. 边界:缺少 replay 键时抛出异常
"""
import time
import unittest
from types import SimpleNamespace
from unittest.mock import MagicMock, patch
... ... @@ -25,7 +25,7 @@ def _fake_settings(match_by_time_threshold: int = 30):
return SimpleNamespace(
match_by_time_threshold=match_by_time_threshold,
llm=SimpleNamespace(base_url="http://192.168.1.59:11434/v1", model_name="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf", temperature=0.7),
common=SimpleNamespace(cache_dir="/root/lzw/tmp_0518_replay_cache0521_07/videos_cache", task_log_dir="/root/lzw/tmp_0518_replay_cache0521_07/tasks_log"),
common=SimpleNamespace(cache_dir="/root/lzw/tmp_0526_replay_cache0526/videos_cache", task_log_dir="/root/lzw/tmp_0526_replay_cache0526/tasks_log"),
save_frames_enable=True,
)
... ... @@ -33,20 +33,32 @@ def _fake_settings(match_by_time_threshold: int = 30):
def _base_data():
"""返回一份基础伪数据,replay.start_utc = 1000(毫秒)。"""
url = "http://video.mam.miguvideo.com/mnt6/fastclip3/wsc/2026/04/29/df760b8d15394cbc9ed0d0a4a9c4b786_1080PS/29133605/vodtmp/3b3e99cf4ca84c3782503d8817242de2.m3u8"
# url = "http://video.mam.miguvideo.com/mnt6/fastclip3/wsc/2026/04/29/df760b8d15394cbc9ed0d0a4a9c4b786_1080PS/29133605/vodtmp/3b3e99cf4ca84c3782503d8817242de2.m3u8"
return {
"id": "task_001",
"match_id": "match_001",
"replay": {
"id": "replay_001",
"url": url,
"start_utc": 1777444502543,
"end_utc": 1777444531063
"url": "/root/lzw/finished/69dd5845dd0412067b8d5587-auto-1776074760653/replays/videos/00_14_32_080-00_15_10_560.mp4",
"start_utc": 5_000,
"end_utc": 21_000
},
"events": [
{"id": "event_001", "type": "1", "url": url, "event_utc": 1777444502543-40000},
{"id": "event_002", "type": "1", "url": url, "event_utc": 1777444502543-20000},
{"id": "event_003", "type": "1", "url": url, "event_utc": 1777444531063+20000}
{"id": "event_001",
"type": "1",
"url": "/root/lzw/finished/69dd5845dd0412067b8d5587-auto-1776074760653/live/videos/00-14-09-052.mp4",
"event_utc": None
},
{"id": "event_002",
"type": "1",
"url": "/root/lzw/finished/69dd5845dd0412067b8d5587-auto-1776074760653/live/videos/00-38-40-052.mp4",
"event_utc": None
},
{"id": "event_003",
"type": "1",
"url": "/root/lzw/finished/69dd5845dd0412067b8d5587-auto-1776074760653/live/videos/01-36-04-972.mp4",
"event_utc": None
}
],
}
... ... @@ -61,7 +73,11 @@ class TestReplayMatchEvent(unittest.TestCase):
frm = FootballReplayMatch(settings)
data = _base_data()
start_time = time.time()
result = frm.replay_match_event(data)
end_time = time.time()
print(f"cost time:{end_time - start_time}")
print(result)
# exit()
... ...
... ... @@ -4,6 +4,7 @@ import subprocess
import sys
from pathlib import Path
from typing import Optional
import os
from urllib.parse import urlparse
import cv2
from aabd.stream_chain import video2frames
... ... @@ -73,9 +74,9 @@ class Video2Frame:
def to_frames(self, url, cache=None, fps=None, start=None, end=None, roi=None, max_px_area=None) -> list:
video_root_path = self.get_root_path(url, cache)
video_root_path = video_root_path / f"{start}-{end}-{'_'.join(roi) if roi else 'None'}-{max_px_area}"
download_video_path = video_root_path / "video.mp4"
video_name = os.path.basename(urlparse(url).path)
video_root_path = video_root_path / f"{video_name}--{start}-{end}-{'_'.join(roi) if roi else 'None'}-{max_px_area}"
download_video_path = video_root_path / video_name
if not download_video_path.exists():
logger.info(f"download_video: {url} -> {download_video_path}")
... ... @@ -86,7 +87,7 @@ class Video2Frame:
cache_dir = video_root_path
cache_frames = cache_dir / "frames"
cache_name = cache_dir / "data.json"
cache_name = cache_dir / f"{video_name}.json"
if cache_name.exists():
logger.info(f"use_cache: {cache_name}")
... ...
... ... @@ -6,7 +6,8 @@ import json
def batch_match():
cache_dir = "/root/lzw/tmp_0518_replay_cache03"
cache_dir = "/root/lzw/tmp_0526_replay_02/videos_cache"
task_log_dir = "/root/lzw/tmp_0526_replay_02/tasks_log"
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,
... ... @@ -61,14 +62,20 @@ def batch_match():
# 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,
# 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_pack = {"url": "/root/lzw/finished/69dd5845dd0412067b8d5587-auto-1776074760653/replays/videos/00_14_32_080-00_15_10_560.mp4",
"start_utc": 5_000,
"end_utc": 21_000,
"asr_text": '无'
}
replay_goals = fbrv.video_event(replay_pack, cache_dir=cache_dir)
if replay_goals['event_name'] == '无进球':
replay_goals = fbrv.video_event(replay_pack, cache_dir=os.path.join(cache_dir, "replays"), task_log_dir=os.path.join(task_log_dir, "task_001"))
if replay_goals['event_name'] == '未进球':
continue
# replay_pack = {"video_path": replay_video_path, "asr_text": replay_asr_text}
... ... @@ -77,7 +84,7 @@ def batch_match():
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)
result = replay_match_live.match_batch(replay_pack, live_packs, max_parallel=2, cache_dir=os.path.join(cache_dir, "events"), task_log_dir=os.path.join(task_log_dir, "task_001"))
end_time = time.time()
print(f"Time taken for matching: {end_time - start_time:.2f} seconds")
print(replay_video_path)
... ...