利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.
Python ai-video-generatorcontent-creationffmpeginstagram-reelsllmpythonshort-videosubtitlestext-to-speechtiktokvideo-automationvideo-workflowworkflow-automationyoutube-shorts
fix(video): apply the sibling clip-duration rules to Seedance and OFox
c020627a1ee2a121e7b
diff --git a/app/services/ofox.py b/app/services/ofox.pyindex 95ffef60..c8ab66df 100644--- a/app/services/ofox.py+++ b/app/services/ofox.py@@ -224,7 +224,10 @@ def generate_videos(aspect = VideoAspect(video_aspect)video_width, video_height = aspect.to_resolution()- requested_duration = max(int(minimum_duration), 1)+ try:+ requested_duration = max(int(minimum_duration), 1)+ except (TypeError, ValueError, OverflowError) as exc:+ raise OFoxError("OFox clip duration must be a positive integer") from excminimum, maximum = _duration_bounds()duration = min(max(requested_duration, minimum), maximum)if duration != requested_duration:diff --git a/app/services/volcengine_seedance.py b/app/services/volcengine_seedance.pyindex 9566550d..94dbf28c 100644--- a/app/services/volcengine_seedance.py+++ b/app/services/volcengine_seedance.py@@ -224,9 +224,23 @@ def generate_videos(raise VolcEngineSeedanceError("Seedance search term must not be empty")aspect = VideoAspect(video_aspect)- requested_duration = max(int(minimum_duration), 1)+ try:+ requested_duration = max(int(minimum_duration), 1)+ except (TypeError, ValueError, OverflowError) as exc:+ raise VolcEngineSeedanceError(+ "Seedance clip duration must be a positive integer"+ ) from excminimum, maximum = _duration_bounds()duration = min(max(requested_duration, minimum), maximum)+ if duration != requested_duration:+ # 生成比请求更长不会影响成片:剪辑流程仍按片段时长裁剪;生成比请求+ # 更短只发生在请求超过模型上限时,此时也只能收敛到上限。其它付费视频源+ # 都会说明这次收敛,否则用户无法解释成片片段为何比配置值短。+ logger.info(+ "Seedance clip duration clamped to the configured model range: "+ f"requested={requested_duration}s, using={duration}s "+ f"(configured {minimum}-{maximum}s)"+ )resolution = _resolution()payload = {"model": _model_id(),diff --git a/test/services/test_ofox.py b/test/services/test_ofox.pyindex 9146219e..81f228d0 100644--- a/test/services/test_ofox.py+++ b/test/services/test_ofox.py@@ -149,6 +149,16 @@ class TestOFoxService(unittest.TestCase):config.app["ofox_resolution"] = " 480p "self.assertEqual(ofox._resolution(), "480p")+ def test_invalid_clip_duration_raises_ofox_error_without_paid_submission(self):+ for invalid in (None, "bad", ""):+ with self.subTest(invalid=invalid):+ with patch.object(ofox.requests, "post") as post:+ with self.assertRaises(ofox.OFoxError) as raised:+ ofox.generate_videos("sunrise", invalid)++ self.assertIn("clip duration", str(raised.exception))+ post.assert_not_called()+def test_provider_pinning_defaults_to_byteplus_and_stays_configurable(self):# 未配置时默认钉定国际厂商 byteplus(内容政策一致、路由可预期)。submit = self._response({"id": "vid-route", "status": "queued"}, 202)diff --git a/test/services/test_volcengine_seedance.py b/test/services/test_volcengine_seedance.pyindex 5f416598..5c854610 100644--- a/test/services/test_volcengine_seedance.py+++ b/test/services/test_volcengine_seedance.py@@ -4,6 +4,7 @@ from types import SimpleNamespacefrom unittest.mock import patchimport requests+from loguru import loggerfrom app.config import configfrom app.models.schema import MaterialInfo, VideoAspect, VideoParams@@ -230,6 +231,91 @@ class TestVolcEngineSeedanceService(unittest.TestCase):self.assertEqual(payload["resolution"], "720p")self.assertTrue(payload["watermark"])+ def test_clamped_clip_duration_is_reported_before_paid_submission(self):+ config.app.update(+ {+ "volcengine_seedance_min_duration": 4,+ "volcengine_seedance_max_duration": 8,+ }+ )+ submit = self._response({"id": "cgt-clamped"})+ completed = self._response(+ {+ "id": "cgt-clamped",+ "status": "succeeded",+ "content": {"video_url": "https://cdn.example.com/clamped.mp4"},+ }+ )+ messages: list[str] = []+ handler_id = logger.add(+ lambda message: messages.append(message.record["message"]),+ level="INFO",+ )+ try:+ with (+ patch.object(seedance.requests, "post", return_value=submit),+ patch.object(seedance.requests, "get", return_value=completed),+ ):+ result = seedance.generate_videos("city", 99)+ finally:+ logger.remove(handler_id)++ # 用户请求 99 秒、实际提交 8 秒。其它付费视频源都会说明这次收敛,因此+ # 日志必须同时带上请求值和提交值,否则成片片段比配置值短时无法解释。+ self.assertEqual(result[0].duration, 8)+ self.assertTrue(+ any(+ "clamped" in message+ and "requested=99s" in message+ and "using=8s" in message+ for message in messages+ ),+ messages,+ )++ def test_clip_duration_inside_the_configured_range_is_not_reported_as_clamped(self):+ config.app.update(+ {+ "volcengine_seedance_min_duration": 4,+ "volcengine_seedance_max_duration": 8,+ }+ )+ submit = self._response({"id": "cgt-inside"})+ completed = self._response(+ {+ "id": "cgt-inside",+ "status": "succeeded",+ "content": {"video_url": "https://cdn.example.com/inside.mp4"},+ }+ )+ messages: list[str] = []+ handler_id = logger.add(+ lambda message: messages.append(message.record["message"]),+ level="INFO",+ )+ try:+ with (+ patch.object(seedance.requests, "post", return_value=submit),+ patch.object(seedance.requests, "get", return_value=completed),+ ):+ seedance.generate_videos("city", 6)+ finally:+ logger.remove(handler_id)++ self.assertFalse(+ [message for message in messages if "clamped" in message], messages+ )++ def test_invalid_clip_duration_raises_seedance_error_without_paid_submission(self):+ for invalid in (None, "bad", ""):+ with self.subTest(invalid=invalid):+ with patch.object(seedance.requests, "post") as post:+ with self.assertRaises(seedance.VolcEngineSeedanceError) as raised:+ seedance.generate_videos("city", invalid)++ self.assertIn("clip duration", str(raised.exception))+ post.assert_not_called()+def test_rejected_submission_raises_clear_error_without_polling(self):rejected = self._response({