优化代码

This commit is contained in:
liuwei
2025-06-09 17:48:41 +08:00
parent 0d5140a894
commit df5ccc4ae8
3 changed files with 27 additions and 65 deletions

View File

@@ -1,13 +1,11 @@
import io
import os
import tempfile
import cv2
from loguru import logger
def _get_first_frame(video_path, output_path):
def get_first_frame(video_path, output_path):
"""
提取视频的第一帧并保存为图片
:param video_path: 视频文件路径
@@ -50,7 +48,7 @@ def _get_first_frame(video_path, output_path):
cap.release()
def _get_first_frame_bytes(video_bytes, output_path):
def get_first_frame_bytes(video_bytes, output_path):
"""
提取视频的第一帧并保存为图片
:param video_bytes: 视频文件流
@@ -65,7 +63,7 @@ def _get_first_frame_bytes(video_bytes, output_path):
temp_file.write(video_bytes)
temp_file_path = temp_file.name # 获取临时文件路径
# 打开视频文件
return _get_first_frame(temp_file_path, output_path)
return get_first_frame(temp_file_path, output_path)
except Exception as e:
logger.error(f"提取视频首帧时出错: {e}")
return None