[to #42322933] Fix bug for demo service

在demo service场景,同时调用同一个视频文件,会导致ffmpeg处理同名视频的冲突。通过uuid生成唯一的文件名解决这个冲突。
        Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/10518178
This commit is contained in:
lllcho.lc
2022-10-25 20:31:53 +08:00
committed by yingda.chen
parent 62339161cd
commit 41b35619e8

View File

@@ -4,6 +4,7 @@ import os
import os.path as osp
import shutil
import subprocess
import uuid
import cv2
import numpy as np
@@ -84,7 +85,9 @@ class ActionDetONNX(Model):
def forward_video(self, video_name, scale):
min_size, max_size = self._get_sizes(scale)
tmp_dir = osp.join(self.tmp_dir, osp.basename(video_name)[:-4])
tmp_dir = osp.join(
self.tmp_dir,
str(uuid.uuid1()) + '_' + osp.basename(video_name)[:-4])
if osp.exists(tmp_dir):
shutil.rmtree(tmp_dir)
os.makedirs(tmp_dir)
@@ -110,6 +113,7 @@ class ActionDetONNX(Model):
len(frame_names) * self.temporal_stride,
self.temporal_stride))
batch_imgs = [self.parse_frames(names) for names in frame_names]
shutil.rmtree(tmp_dir)
N, _, T, H, W = batch_imgs[0].shape
scale_min = min_size / min(H, W)
@@ -128,7 +132,6 @@ class ActionDetONNX(Model):
'timestamp': t,
'actions': res
} for t, res in zip(timestamp, results)]
shutil.rmtree(tmp_dir)
return results
def forward(self, video_name):