From acb6a0f5914dd5c7e74470236a460cb49d9e0dbd Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sun, 17 Dec 2023 10:15:56 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9AFFmpeg=E5=8D=95=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- plugins/ffmpegthumb/__init__.py | 31 ++++++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 00e0de0..d489aa3 100644 --- a/package.json +++ b/package.json @@ -322,7 +322,7 @@ "FFmpegThumb": { "name": "FFmpeg缩略图", "description": "TheMovieDb没有背景图片时使用FFmpeg截取视频文件缩略图", - "version": "1.0", + "version": "1.1", "icon": "ffmpeg.png", "author": "jxxghp", "level": 1 diff --git a/plugins/ffmpegthumb/__init__.py b/plugins/ffmpegthumb/__init__.py index b9ebff9..9c8e472 100644 --- a/plugins/ffmpegthumb/__init__.py +++ b/plugins/ffmpegthumb/__init__.py @@ -1,3 +1,4 @@ +import threading from datetime import datetime, timedelta from pathlib import Path from threading import Event as ThreadEvent @@ -16,6 +17,8 @@ from app.schemas import TransferInfo from app.schemas.types import EventType from app.utils.system import SystemUtils +ffmpeg_lock = threading.Lock() + class FFmpegThumb(_PluginBase): # 插件名称 @@ -25,7 +28,7 @@ class FFmpegThumb(_PluginBase): # 插件图标 plugin_icon = "ffmpeg.png" # 插件版本 - plugin_version = "1.0" + plugin_version = "1.1" # 插件作者 plugin_author = "jxxghp" # 作者主页 @@ -328,18 +331,20 @@ class FFmpegThumb(_PluginBase): """ 处理一个文件 """ - try: - thumb_path = file_path.with_name(file_path.stem + "-thumb.jpg") - if thumb_path.exists(): - logger.info(f"缩略图已存在:{thumb_path}") - return - if FfmpegHelper.get_thumb(video_path=str(file_path), - image_path=str(thumb_path), frames=self._timeline): - logger.info(f"{file_path} 缩略图已生成:{thumb_path}") - else: - logger.warn(f"{file_path} 缩略图生成失败!") - except Exception as err: - logger.error(f"FFmpeg处理文件 {file_path} 时发生错误:{str(err)}") + # 单线程处理 + with ffmpeg_lock: + try: + thumb_path = file_path.with_name(file_path.stem + "-thumb.jpg") + if thumb_path.exists(): + logger.info(f"缩略图已存在:{thumb_path}") + return + if FfmpegHelper.get_thumb(video_path=str(file_path), + image_path=str(thumb_path), frames=self._timeline): + logger.info(f"{file_path} 缩略图已生成:{thumb_path}") + else: + logger.warn(f"{file_path} 缩略图生成失败!") + except Exception as err: + logger.error(f"FFmpeg处理文件 {file_path} 时发生错误:{str(err)}") def stop_service(self): """