Skip to content

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

fix(video): use normal narration volume for nullable requests

Rudy Celekli4869219a7e31
diff --git a/app/services/video.py b/app/services/video.py
index 3662be48..107af43a 100644
--- a/app/services/video.py
+++ b/app/services/video.py
@@ -1742,7 +1742,7 @@ def generate_video(
voice_source_clip = clip_stack.enter_context(AudioFileClip(audio_path))
video_clip = source_video_clip
audio_clip = voice_source_clip.with_effects(
- [afx.MultiplyVolume(params.voice_volume)]
+ [afx.MultiplyVolume(1.0 if params.voice_volume is None else params.voice_volume)]
)
def make_textclip(text):
diff --git a/test/services/test_nullable_narration_volume.py b/test/services/test_nullable_narration_volume.py
new file mode 100644
index 00000000..5ccac2cc
--- /dev/null
+++ b/test/services/test_nullable_narration_volume.py
@@ -0,0 +1,26 @@
+import shutil
+import subprocess
+
+import numpy as np
+import pytest
+
+from app.models.schema import TaskVideoRequest
+from app.services import video
+
+
[email protected]("volume, audible", [(None, True), (1.0, True), (0.0, False)])
+def test_valid_nullable_volume_renders_without_losing_mute(tmp_path, volume, audible):
+ if not shutil.which("ffmpeg"):
+ pytest.skip("native FFmpeg required")
+ footage, speech, output = (tmp_path / name for name in ("input.mp4", "speech.wav", "final.mp4"))
+ base = ["ffmpeg", "-nostdin", "-v", "error", "-y", "-threads", "1"]
+ subprocess.run([*base, "-f", "lavfi", "-i", "color=c=red:s=64x64:r=10:d=0.2", "-c:v", "libx264", "-pix_fmt", "yuv420p", str(footage)], check=True)
+ subprocess.run([*base, "-f", "lavfi", "-i", "sine=frequency=440:duration=0.2", str(speech)], check=True)
+ request = TaskVideoRequest(video_subject="Narration", voice_volume=volume, subtitle_enabled=False, bgm_type="", n_threads=1)
+ assert video.generate_video(str(footage), str(speech), "", str(output), request)
+ decoded = subprocess.run([*base, "-i", str(output), "-map", "0:a:0", "-f", "f32le", "-acodec", "pcm_f32le", "-"], capture_output=True, check=True)
+ peak = float(np.max(np.abs(np.frombuffer(decoded.stdout, dtype="<f4"))))
+ if audible:
+ assert peak > 0.02
+ else:
+ assert peak < 0.001