Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

Fix support for Windows systems

harry9650def32148
diff --git a/app/config/config.py b/app/config/config.py
index cf90938a..ab4aa6ed 100644
--- a/app/config/config.py
+++ b/app/config/config.py
@@ -1,5 +1,5 @@
import os
-
+import socket
import tomli
from loguru import logger
@@ -12,8 +12,7 @@ with open(config_file, mode="rb") as fp:
app = _cfg.get("app", {})
whisper = _cfg.get("whisper", {})
-
-hostname = os.uname().nodename
+hostname = socket.gethostname()
log_level = _cfg.get("log_level", "DEBUG")
listen_host = _cfg.get("listen_host", "0.0.0.0")
@@ -23,6 +22,10 @@ project_description = _cfg.get("project_description", "MoneyPrinterTurbo\n by
project_version = _cfg.get("project_version", "1.0.0")
reload_debug = False
+imagemagick_path = app.get("imagemagick_path", "")
+if imagemagick_path and os.path.isfile(imagemagick_path):
+ os.environ["IMAGEMAGICK_BINARY"] = imagemagick_path
+
__cfg = {
"hostname": hostname,
"listen_host": listen_host,
diff --git a/app/services/subtitle.py b/app/services/subtitle.py
index 7de62c67..f86db9d8 100644
--- a/app/services/subtitle.py
+++ b/app/services/subtitle.py
@@ -6,14 +6,14 @@ from timeit import default_timer as timer
from loguru import logger
from app.config import config
-from app.models import const
from app.utils import utils
model_size = config.whisper.get("model_size", "large-v3")
device = config.whisper.get("device", "cpu")
compute_type = config.whisper.get("compute_type", "int8")
-model = WhisperModel(model_size_or_path=model_size, device=device, compute_type=compute_type)
+if config.app.get("subtitle_provider") == "whisper":
+ model = WhisperModel(model_size_or_path=model_size, device=device, compute_type=compute_type)
def create(audio_file, subtitle_file: str = ""):
diff --git a/app/services/video.py b/app/services/video.py
index 1f94722d..249279d8 100644
--- a/app/services/video.py
+++ b/app/services/video.py
@@ -17,9 +17,7 @@ def get_bgm_file(bgm_name: str = "random"):
if bgm_name == "random":
suffix = "*.mp3"
song_dir = utils.song_dir()
- # 使用glob.glob获取指定扩展名的文件列表
files = glob.glob(os.path.join(song_dir, suffix))
- # 使用random.choice从列表中随机选择一个文件
return random.choice(files)
file = os.path.join(utils.song_dir(), bgm_name)
@@ -154,11 +152,12 @@ def generate_video(video_path: str,
if not font_name:
font_name = "STHeitiMedium.ttc"
font_path = os.path.join(utils.font_dir(), font_name)
+ if os.name == 'nt':
+ font_path = font_path.replace("\\", "/")
+
logger.info(f"using font: {font_path}")
- # 自定义的生成器函数,包含换行逻辑
def generator(txt):
- # 应用自动换行
wrapped_txt = wrap_text(txt, max_width=video_width - 100,
font=font_path,
fontsize=fontsize) # 调整max_width以适应你的视频
@@ -179,16 +178,14 @@ def generate_video(video_path: str,
clips = [
VideoFileClip(video_path),
- # subtitles.set_position(lambda _t: ('center', position_height))
]
- # Burn the subtitles into the video
+
if subtitle_path and os.path.exists(subtitle_path):
- subtitles = SubtitlesClip(subtitle_path, generator)
+ subtitles = SubtitlesClip(subtitles=subtitle_path, make_textclip=generator, encoding='utf-8')
clips.append(subtitles.set_position(lambda _t: ('center', position_height)))
result = CompositeVideoClip(clips)
- # Add the audio
audio = AudioFileClip(audio_path)
result = result.set_audio(audio)
@@ -210,10 +207,10 @@ def generate_video(video_path: str,
video_clip = video_clip.set_audio(comp_audio)
video_clip = video_clip.set_fps(30)
video_clip = video_clip.set_duration(original_duration)
- # 编码为aac,否则iPhone里面无法播放
+
logger.info(f"encoding audio codec to aac")
video_clip.write_videofile(output_file, audio_codec="aac", threads=threads)
- # delete the temp file
+
os.remove(temp_output_file)
logger.success(f"completed")
diff --git a/config.example.toml b/config.example.toml
index c5f7e570..c6373d52 100644
--- a/config.example.toml
+++ b/config.example.toml
@@ -15,6 +15,11 @@
# If empty, the subtitle will not be generated
subtitle_provider = "edge"
+ # Once you have installed it, ImageMagick will be automatically detected, except on Windows!
+ # On Windows, for example "C:\Program Files (x86)\ImageMagick-7.1.1-Q16-HDRI\magick.exe"
+ # Download from https://imagemagick.org/archive/binaries/ImageMagick-7.1.1-29-Q16-x64-static.exe
+ # imagemagick_path = "C:\\Program Files (x86)\\ImageMagick-7.1.1-Q16\\magick.exe"
+
[whisper]
# Only effective when subtitle_provider is "whisper"
diff --git a/requirements.txt b/requirements.txt
index baf9d602..e61d1163 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,5 +1,5 @@
requests~=2.31.0
-moviepy~=1.0.3
+moviepy~=2.0.0.dev2
openai~=1.13.3
faster-whisper~=1.0.1
edge_tts~=6.1.10
diff --git a/webui.bat b/webui.bat
new file mode 100644
index 00000000..339cbe02
--- /dev/null
+++ b/webui.bat
@@ -0,0 +1,5 @@
+@echo off
+set CURRENT_DIR=%CD%
+echo ***** Current directory: %CURRENT_DIR% *****
+set PYTHONPATH=%CURRENT_DIR%;%PYTHONPATH%
+streamlit run .\webui\Main.py
\ No newline at end of file