|
@@ -8,6 +8,7 @@ import traceback
|
|
|
import requests
|
|
|
|
|
|
from pymysql.cursors import DictCursor
|
|
|
+from torch.fft import ifftshift
|
|
|
from tqdm import tqdm
|
|
|
|
|
|
from applications.api import GoogleAIAPI
|
|
@@ -83,6 +84,36 @@ class GenerateTextFromVideo(object):
|
|
|
)
|
|
|
print(affected_rows)
|
|
|
|
|
|
+ def roll_back_processing_videos(self):
|
|
|
+ """
|
|
|
+ 回滚长时间处于处理中的视频
|
|
|
+ """
|
|
|
+ sql = f"""
|
|
|
+ select id, status_update_timestamp
|
|
|
+ from video_content_understanding
|
|
|
+ where status in ({const.VIDEO_UNDERSTAND_PROCESSING_STATUS, const.VIDEO_LOCK});
|
|
|
+ """
|
|
|
+ task_list = self.db.fetch(sql, cursor_type=DictCursor)
|
|
|
+ now_timestamp = int(time.time())
|
|
|
+ id_list = []
|
|
|
+ for task in tqdm(task_list):
|
|
|
+ if now_timestamp - task['status_update_timestamp'] >= const.MAX_PROCESSING_TIME:
|
|
|
+ id_list.append(task['id'])
|
|
|
+
|
|
|
+ if id_list:
|
|
|
+ update_sql = f"""
|
|
|
+ update video_content_understanding
|
|
|
+ set status = %s
|
|
|
+ where id in %s;
|
|
|
+ """
|
|
|
+ self.db.save(
|
|
|
+ query=update_sql,
|
|
|
+ params=(
|
|
|
+ const.VIDEO_UNDERSTAND_INIT_STATUS,
|
|
|
+ tuple(id_list)
|
|
|
+ )
|
|
|
+ )
|
|
|
+
|
|
|
def update_video_status(self, ori_status, new_status, pq_vid):
|
|
|
"""
|
|
|
更新视频状态
|
|
@@ -192,6 +223,7 @@ class GenerateTextFromVideo(object):
|
|
|
"""
|
|
|
处理视频转文本任务
|
|
|
"""
|
|
|
+ self.roll_back_processing_videos()
|
|
|
task_list = self.get_tasks()
|
|
|
while task_list:
|
|
|
for task in tqdm(task_list, desc="convert video to text"):
|