lizhengwei

jira:NYJ-1540 desc: split videos_cache and tasks_log

... ... @@ -26,4 +26,5 @@ llm:
temperature: 0.7
common:
cache_dir: ./cache
\ No newline at end of file
cache_dir: ./videos_cache
task_log_dir: ./tasks_log
\ No newline at end of file
... ...
... ... @@ -16,6 +16,7 @@ class FootballReplayMatch:
model_name = value_or_default(settings.llm.model_name, None)
temperature = value_or_default(settings.llm.temperature, 0.7)
self.cache_dir = value_or_default(settings.common.cache_dir, None)
self.task_log_dir = value_or_default(settings.common.task_log_dir, None)
save_frames_enable = value_or_default(settings.save_frames_enable, False)
self.videoEventRecognition = FootballReplayVideoEvent(llm_base_url, model_name, temperature, 'no_key', self.cache_dir, save_frames_enable)
... ... @@ -39,11 +40,11 @@ class FootballReplayMatch:
return None
def det_goal_replay(self, replay, task_id):
return self.videoEventRecognition.video_event(replay, cache_dir=os.path.join(self.cache_dir, task_id, "replay"))
return self.videoEventRecognition.video_event(replay, cache_dir=os.path.join(self.cache_dir, "replays"), task_log_dir=os.path.join(self.task_log_dir, task_id))
def match_by_llm(self, replay, events, task_id):
return self.videoMatchLive.match_batch(replay, events, max_parallel=2, cache_dir=os.path.join(self.cache_dir, task_id, "envents"))
return self.videoMatchLive.match_batch(replay, events, max_parallel=2, cache_dir=os.path.join(self.cache_dir, "events"), task_log_dir=os.path.join(self.task_log_dir, task_id))
def replay_match_event(self, data):
"""
... ...
... ... @@ -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_01"),
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"),
save_frames_enable=True,
)
... ... @@ -45,8 +45,8 @@ def _base_data():
},
"events": [
{"id": "event_001", "type": "1", "url": url, "event_utc": 1777444502543-40000},
{"id": "event_001", "type": "1", "url": url, "event_utc": 1777444502543-20000},
{"id": "event_001", "type": "1", "url": url, "event_utc": 1777444531063+20000}
{"id": "event_002", "type": "1", "url": url, "event_utc": 1777444502543-20000},
{"id": "event_003", "type": "1", "url": url, "event_utc": 1777444531063+20000}
],
}
... ...
... ... @@ -102,10 +102,6 @@ class FootballReplayMatchLive:
record.append({"live": live, "llm_result": None, 'live_list': [live]})
return live
user_contents = []
# replay_video_contents = video_contents(replay_video["video_path"], "\n【回放片段信息】\n",
# prompt_end=f"\n回放解说内容:{replay_video['asr_text']}\n",
# video_name=os.path.basename(replay_video["video_path"]),
# fps=2, max_frames=999, sampling_mode="head", max_short_edge=480)
live_videos_contents = []
live_map = {}
live_records = {}
... ... @@ -208,10 +204,10 @@ class FootballReplayMatchLive:
else:
return None
def match_batch(self, replay_video: dict, live_videos: list[dict], max_parallel: int = 3, cache_dir=None):
def match_batch(self, replay_video: dict, live_videos: list[dict], max_parallel: int = 3, cache_dir=None, task_log_dir=None):
self.cache_dir = cache_dir
cache_path = os.path.join(cache_dir, 'match_live.json')
cache_path = os.path.join(task_log_dir, 'match_live.json')
if cache_path is not None and os.path.exists(cache_path):
try:
with open(cache_path, 'r', encoding='utf-8') as f:
... ... @@ -223,7 +219,7 @@ class FootballReplayMatchLive:
event_start = replay_video.get("start_utc", None)
event_end = replay_video.get("end_utc", None)
replay_video_contents = self.video2frame.to_llm_contents(replay_video_path,
cache=os.path.join(os.path.dirname(cache_dir), "replay"),
cache=os.path.join(os.path.dirname(cache_dir), "replays"),
fps=2,
start=event_start,
end=event_end,
... ...
... ... @@ -81,10 +81,10 @@ class FootballReplayVideoEvent:
self.video2frame = Video2Frame(cache_dir=cache_dir, save_frames_enable=save_frames_enable)
def video_event(self, replay_pack: dict, asr_text: str = '无', cache_dir=None):
def video_event(self, replay_pack: dict, asr_text: str = '无', cache_dir=None, task_log_dir=None):
replay_video_path = replay_pack.get("url", None)
cache_path = os.path.join(cache_dir, 'video_event.json')
cache_path = os.path.join(task_log_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())
... ...
... ... @@ -74,6 +74,7 @@ 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"
if not download_video_path.exists():
... ... @@ -81,7 +82,9 @@ class Video2Frame:
video_root_path.mkdir(parents=True, exist_ok=True)
download_to_mp4(url, str(download_video_path), duration=None)
logger.info(f"video_path: {download_video_path}")
cache_dir = video_root_path / 'caches' / f"{start}-{end}-{'_'.join(roi) if roi else 'None'}-{max_px_area}"
cache_dir = video_root_path
cache_frames = cache_dir / "frames"
cache_name = cache_dir / "data.json"
... ...