优化首帧功能,如果没传入首帧,则提取首帧。
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
import base64
|
||||
import os
|
||||
import time
|
||||
from asyncio import Future
|
||||
from asyncio import Queue, sleep
|
||||
from io import BytesIO
|
||||
@@ -14,6 +15,7 @@ from pymediainfo import MediaInfo
|
||||
import pysilk
|
||||
from pydub import AudioSegment
|
||||
|
||||
from utils.video_utils import _get_first_frame
|
||||
from wechat_ipad import UserLoggedOut
|
||||
from wechat_ipad.client.base import WechatAPIClientBase
|
||||
|
||||
@@ -214,8 +216,7 @@ class MessageMixin(WechatAPIClientBase):
|
||||
ValueError: 视频或图片参数都为空或都不为空时
|
||||
根据error_handler处理错误
|
||||
"""
|
||||
if not image:
|
||||
image = Path(os.path.join(Path(__file__).resolve().parent, "fallback.png"))
|
||||
|
||||
# get video base64 and duration
|
||||
if isinstance(video, str):
|
||||
vid_base64 = video
|
||||
@@ -235,6 +236,9 @@ class MessageMixin(WechatAPIClientBase):
|
||||
file_len = len(video_bytes)
|
||||
vid_base64 = base64.b64encode(video_bytes).decode()
|
||||
media_info = MediaInfo.parse(video_path)
|
||||
first_frame = _get_first_frame(video_path, f"dify_frame_{int(time.time())}.jpg")
|
||||
if first_frame:
|
||||
image = first_frame
|
||||
else:
|
||||
raise ValueError("video should be str, bytes, or path")
|
||||
# 获取视频时长
|
||||
@@ -246,7 +250,8 @@ class MessageMixin(WechatAPIClientBase):
|
||||
if duration is None:
|
||||
duration = 1
|
||||
self.logging.error(f"无法从视频文件获取时长: {video}")
|
||||
|
||||
if not image:
|
||||
image = Path(os.path.join(Path(__file__).resolve().parent, "fallback.png"))
|
||||
# get image base64
|
||||
if isinstance(image, str):
|
||||
image_base64 = image
|
||||
|
||||
Reference in New Issue
Block a user