feat(新功能): pose transform 部署

fix(修复bug):
docs(文档变更):
refactor(重构):
test(增加测试):
This commit is contained in:
zchengrong
2025-04-08 12:36:44 +08:00
parent 635b506c4d
commit 7d12fcc98c
2 changed files with 23 additions and 34 deletions

View File

@@ -2,15 +2,14 @@ import io
import logging
import cv2
import imageio
import numpy as np
import skvideo.io
# import boto3
from minio import Minio
from app.core.config import *
from app.service.utils.new_oss_client import oss_upload_image
# minio 配置
MINIO_URL = "www.minio.aida.com.hk:12024"
MINIO_ACCESS = 'vXKFLSJkYeEq2DrSZvkB'
@@ -50,18 +49,8 @@ def upload_gif(gif_buffer, user_id, category, file_name):
def upload_video(frames, user_id, category, file_name):
try:
ndarray_to_video(frames, file_name)
object_name = f'{user_id}/{category}/{file_name}'
# 创建视频写入器
fps = 1 # 帧率
fourcc = cv2.VideoWriter.fourcc(*'avc1')
video_writer = cv2.VideoWriter(file_name, fourcc, fps, (512, 768))
# 逐帧写入
for frame in frames:
video_writer.write(cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)) # OpenCV需BGR格式
video_writer.release()
minio_client.fput_object(
"aida-users",
object_name,
@@ -70,29 +59,29 @@ def upload_video(frames, user_id, category, file_name):
)
print(file_name)
return f"aida-users/{object_name}"
# # 生成内存中的视频字节流
# video_buffer = io.BytesIO()
# with imageio.get_writer(video_buffer, format="mp4", fps=24) as writer:
# for img in frames:
# writer.append_data(img)
# writer.close()
# video_bytes = video_buffer.getvalue()
#
# object_name = f'{user_id}/{category}/{file_name}'
# # 上传视频流到MinIO
# minio_client.put_object(
# bucket_name="aida-users",
# object_name=object_name,
# data=io.BytesIO(video_bytes),
# length=len(video_bytes),
# content_type="video/mp4"
# )
# return f"aida-users/{object_name}"
except Exception as e:
logging.warning(f"upload_video runtime exception : {e}")
def ndarray_to_video(images, output_path, frame_size=(512, 768), fps=1):
# 初始化视频写入器
writer = skvideo.io.FFmpegWriter(
output_path,
inputdict={'-r': str(fps)},
outputdict={'-r': str(fps), '-vcodec': 'libx264'}
)
# 逐帧写入
for frame in images:
# 调整尺寸(可选)
resized_frame = cv2.resize(frame, frame_size)
# 转换颜色通道(若需从 BGR 转 RGB
rgb_frame = cv2.cvtColor(resized_frame, cv2.COLOR_BGR2RGB)
writer.writeFrame(rgb_frame)
# 关闭写入器
writer.close()
if __name__ == '__main__':
images = np.random.randint(0, 256, size=(10, 768, 512, 3), dtype=np.uint8)
print(upload_video(images, user_id=89, category='test', file_name="1123123.mp4"))
images = np.random.randint(0, 256, size=(4, 768, 512, 3), dtype=np.uint8)
print(upload_video(images, user_id=89, category='pose_transform_video', file_name="1123123.mp4"))

Binary file not shown.