优化首帧功能,如果没传入首帧,则提取首帧。
This commit is contained in:
@@ -216,6 +216,9 @@ class MessageMixin(WechatAPIClientBase):
|
|||||||
ValueError: 视频或图片参数都为空或都不为空时
|
ValueError: 视频或图片参数都为空或都不为空时
|
||||||
根据error_handler处理错误
|
根据error_handler处理错误
|
||||||
"""
|
"""
|
||||||
|
has_image = False
|
||||||
|
if not image:
|
||||||
|
image = Path(os.path.join(Path(__file__).resolve().parent, "fallback.png"))
|
||||||
|
|
||||||
# get video base64 and duration
|
# get video base64 and duration
|
||||||
if isinstance(video, str):
|
if isinstance(video, str):
|
||||||
@@ -236,6 +239,8 @@ class MessageMixin(WechatAPIClientBase):
|
|||||||
file_len = len(video_bytes)
|
file_len = len(video_bytes)
|
||||||
vid_base64 = base64.b64encode(video_bytes).decode()
|
vid_base64 = base64.b64encode(video_bytes).decode()
|
||||||
media_info = MediaInfo.parse(video_path)
|
media_info = MediaInfo.parse(video_path)
|
||||||
|
# 如果没有传入首帧,则自己提取一次
|
||||||
|
if not has_image:
|
||||||
first_frame = _get_first_frame(video_path, f"dify_frame_{int(time.time())}.jpg")
|
first_frame = _get_first_frame(video_path, f"dify_frame_{int(time.time())}.jpg")
|
||||||
if first_frame:
|
if first_frame:
|
||||||
image = first_frame
|
image = first_frame
|
||||||
@@ -250,8 +255,6 @@ class MessageMixin(WechatAPIClientBase):
|
|||||||
if duration is None:
|
if duration is None:
|
||||||
duration = 1
|
duration = 1
|
||||||
self.logging.error(f"无法从视频文件获取时长: {video}")
|
self.logging.error(f"无法从视频文件获取时长: {video}")
|
||||||
if not image:
|
|
||||||
image = Path(os.path.join(Path(__file__).resolve().parent, "fallback.png"))
|
|
||||||
# get image base64
|
# get image base64
|
||||||
if isinstance(image, str):
|
if isinstance(image, str):
|
||||||
image_base64 = image
|
image_base64 = image
|
||||||
|
|||||||
Reference in New Issue
Block a user