Prechádzať zdrojové kódy

1.修正3k分辨率的尺寸以适应gpt-image2模型
2.新增百度海外版seedance素材管理
3.新增百度海外版seedance模型接入和公共方法

lh 1 týždeň pred
rodič
commit
2a4028b854

+ 39 - 10
app/Consts/BaseConst.php

@@ -113,16 +113,45 @@ class BaseConst
     ];
 
     /**
-     * 画面比例配置
+     * 图片生成:分辨率档位(2k/3k/4k)与画面比例对应的尺寸映射表
+     *
+     * 统一入口,所有图片生成入口均应引用本常量,禁止在业务代码中重复维护尺寸表。
      */
-    const IMAGE_RATIOS = [
-        '1:1' => ['width' => 2048, 'height' => 2048],
-        '4:3' => ['width' => 2304, 'height' => 1728],
-        '3:4' => ['width' => 1728, 'height' => 2304],
-        '16:9' => ['width' => 2848, 'height' => 1600],
-        '9:16' => ['width' => 1600, 'height' => 2848],
-        '3:2' => ['width' => 2496, 'height' => 1664],
-        '2:3' => ['width' => 1664, 'height' => 2496],
-        '21:9' => ['width' => 3136, 'height' => 1344],
+    const IMAGE_RESOLUTION_SIZE_MAP = [
+        '2k' => [
+            '1:1' => ['width' => 2048, 'height' => 2048],
+            '4:3' => ['width' => 2304, 'height' => 1728],
+            '3:4' => ['width' => 1728, 'height' => 2304],
+            '16:9' => ['width' => 2848, 'height' => 1600],
+            '9:16' => ['width' => 1600, 'height' => 2848],
+            '3:2' => ['width' => 2496, 'height' => 1664],
+            '2:3' => ['width' => 1664, 'height' => 2496],
+            '21:9' => ['width' => 3136, 'height' => 1344],
+        ],
+        '3k' => [
+            '1:1' => ['width' => 3072, 'height' => 3072],
+            '4:3' => ['width' => 3456, 'height' => 2592],
+            '3:4' => ['width' => 2592, 'height' => 3456],
+            '16:9' => ['width' => 3840, 'height' => 2160],
+            '9:16' => ['width' => 2160, 'height' => 3840],
+            '2:3' => ['width' => 2496, 'height' => 3744],
+            '3:2' => ['width' => 3744, 'height' => 2496],
+            '21:9' => ['width' => 3440, 'height' => 1440],
+        ],
+        '4k' => [
+            '1:1' => ['width' => 4096, 'height' => 4096],
+            '3:4' => ['width' => 3520, 'height' => 4704],
+            '4:3' => ['width' => 4704, 'height' => 3520],
+            '16:9' => ['width' => 5504, 'height' => 3040],
+            '9:16' => ['width' => 3040, 'height' => 5504],
+            '2:3' => ['width' => 3328, 'height' => 4992],
+            '3:2' => ['width' => 4992, 'height' => 3328],
+            '21:9' => ['width' => 6240, 'height' => 2656],
+        ],
     ];
+
+    /**
+     * 画面比例配置(默认 2k 档尺寸)
+     */
+    const IMAGE_RATIOS = self::IMAGE_RESOLUTION_SIZE_MAP['2k'];
 }

+ 44 - 9
app/Http/Controllers/Anime/AnimeController.php

@@ -197,6 +197,35 @@ class AnimeController extends BaseController
                 'ratios' => $commonRatios,
                 'resolutions' => $resolutions(['480p', 'sr_720p', '720p', '1080p']),
             ],
+            // // 海外百度Seedance(dreamina真人素材空间,模型名带baidu-前缀,请求时去掉前缀)
+            // [
+            //     'model' => 'baidu-dreamina-seedance-2-0-260128',
+            //     'name' => 'Seedance 2.0(海外)',
+            //     'duration' => $duration(4, 15),
+            //     'ratios' => $commonRatios,
+            //     'resolutions' => $resolutions(['480p', 'sr_720p', '720p', '1080p', '4k']),
+            // ],
+            // [
+            //     'model' => 'baidu-dreamina-seedance-2-0-fast-260128',
+            //     'name' => 'Seedance 2.0 Fast(海外)',
+            //     'duration' => $duration(4, 15),
+            //     'ratios' => $commonRatios,
+            //     'resolutions' => $resolutions(['480p', 'sr_720p', '720p']),
+            // ],
+            // [
+            //     'model' => 'baidu-dreamina-seedance-2-0-mini-260615',
+            //     'name' => 'Seedance 2.0 Mini(海外)',
+            //     'duration' => $duration(4, 15),
+            //     'ratios' => $commonRatios,
+            //     'resolutions' => $resolutions(['480p', 'sr_720p', '720p']),
+            // ],
+            // [
+            //     'model' => 'baidu-dreamina-seedance-2-5-260628',
+            //     'name' => 'Seedance 2.5(海外)',
+            //     'duration' => $duration(4, 30, -1),
+            //     'ratios' => $commonRatios,
+            //     'resolutions' => $resolutions(['480p', 'sr_720p', '720p', '1080p']),
+            // ],
         ]);
 
         // 快快版
@@ -894,7 +923,7 @@ class AnimeController extends BaseController
                 
                 // 如果有首帧图片,添加到content中
                 if ($hasImage) {
-                    if (in_array($model, ['doubao-seedance-2-0-260128', 'doubao-seedance-2-0-fast-260128', 'baidu-doubao-seedance-2-5-260628', 'baidu-doubao-seedance-2-0-260128', 'baidu-doubao-seedance-2-0-fast-260128', 'baidu-doubao-seedance-2-0-mini-260615'])) {
+                    if (in_array($model, ['doubao-seedance-2-0-260128', 'doubao-seedance-2-0-fast-260128', 'baidu-doubao-seedance-2-5-260628', 'baidu-doubao-seedance-2-0-260128', 'baidu-doubao-seedance-2-0-fast-260128', 'baidu-doubao-seedance-2-0-mini-260615', 'baidu-dreamina-seedance-2-0-260128', 'baidu-dreamina-seedance-2-0-fast-260128', 'baidu-dreamina-seedance-2-0-mini-260615', 'baidu-dreamina-seedance-2-5-260628'])) {
                         $videoParams['content'][] = [
                             'type' => 'image_url',
                             'image_url' => [
@@ -985,6 +1014,7 @@ class AnimeController extends BaseController
                 } elseif ($this->AnimeService->isSeedance20SeriesModel($model)) {
                     // 豆包Seedance 2.0(百度AI网关)/ 快快AI Seedance 2.0/2.5:图片需要先上传为素材
                     $isKuaikuai = $this->AnimeService->isKuaikuaiSeedanceModel($model);
+                    $isDreamina = $this->AnimeService->isOverseasBaiduSeedanceModel($model);
                     // 保存原始参考图用于任务记录
                     $videoParams['reference_images'] = $reference_images;
 
@@ -995,10 +1025,12 @@ class AnimeController extends BaseController
                         // 维护ref_image_url字段(参考图URL,JSON数组,与智帧分支保持一致)
                         $videoParams['ref_image_url'] = json_encode($reference_images, 256);
 
-                        // 参考图上传为素材(百度网关/快快AI),上传失败时同步清理提示词中的<图片N>标记
+                        // 参考图上传为素材(国内百度/海外百度dreamina/快快AI),上传失败时同步清理提示词中的<图片N>标记
                         $reference_image_assets = $isKuaikuai
                             ? $this->AIVideoGenerationService->processReferenceImagesToKuaikuaiAssets($reference_images, $videoParams['prompt'])
-                            : $this->AIVideoGenerationService->processReferenceImagesToSeedance20Assets($reference_images, $videoParams['prompt']);
+                            : ($isDreamina
+                                ? $this->AIVideoGenerationService->processReferenceImagesToBaiduDreaminaAssets($reference_images, $videoParams['prompt'])
+                                : $this->AIVideoGenerationService->processReferenceImagesToSeedance20Assets($reference_images, $videoParams['prompt']));
 
                         // 素材上传失败后提示词可能被清理,同步更新视频参数中的提示词
                         $videoParams['prompt'] = trim($videoParams['prompt']);
@@ -1016,7 +1048,7 @@ class AnimeController extends BaseController
                 } else {
                     // Seedance模型(默认)
                     // 检查是否为 Seedance 2.0 模型,如果是则需要处理配音音频
-                    if ($canUseAudio && in_array($model, ['doubao-seedance-2-0-260128', 'doubao-seedance-2-0-fast-260128', 'baidu-doubao-seedance-2-5-260628', 'baidu-doubao-seedance-2-0-260128', 'baidu-doubao-seedance-2-0-fast-260128', 'baidu-doubao-seedance-2-0-mini-260615'])) {
+                    if ($canUseAudio && in_array($model, ['doubao-seedance-2-0-260128', 'doubao-seedance-2-0-fast-260128', 'baidu-doubao-seedance-2-5-260628', 'baidu-doubao-seedance-2-0-260128', 'baidu-doubao-seedance-2-0-fast-260128', 'baidu-doubao-seedance-2-0-mini-260615', 'baidu-dreamina-seedance-2-0-260128', 'baidu-dreamina-seedance-2-0-fast-260128', 'baidu-dreamina-seedance-2-0-mini-260615', 'baidu-dreamina-seedance-2-5-260628'])) {
                         // 添加配音音频到content中
                         $videoParams['content'][] = [
                             'type' => 'audio_url',
@@ -3133,7 +3165,7 @@ class AnimeController extends BaseController
                 
                 // 如果有首帧图片,添加到content中
                 if ($hasImage) {
-                    if (in_array($model, ['doubao-seedance-2-0-260128', 'doubao-seedance-2-0-fast-260128', 'baidu-doubao-seedance-2-5-260628', 'baidu-doubao-seedance-2-0-260128', 'baidu-doubao-seedance-2-0-fast-260128', 'baidu-doubao-seedance-2-0-mini-260615'])) {
+                    if (in_array($model, ['doubao-seedance-2-0-260128', 'doubao-seedance-2-0-fast-260128', 'baidu-doubao-seedance-2-5-260628', 'baidu-doubao-seedance-2-0-260128', 'baidu-doubao-seedance-2-0-fast-260128', 'baidu-doubao-seedance-2-0-mini-260615', 'baidu-dreamina-seedance-2-0-260128', 'baidu-dreamina-seedance-2-0-fast-260128', 'baidu-dreamina-seedance-2-0-mini-260615', 'baidu-dreamina-seedance-2-5-260628'])) {
                         $videoParams['content'][] = [
                             'type' => 'image_url',
                             'image_url' => [
@@ -3220,6 +3252,7 @@ class AnimeController extends BaseController
                 } elseif ($this->AnimeService->isSeedance20SeriesModel($model)) {
                     // 豆包Seedance 2.0(百度AI网关)/ 快快AI Seedance 2.0/2.5:参考图/配音音频需要先上传为素材
                     $isKuaikuai = $this->AnimeService->isKuaikuaiSeedanceModel($model);
+                    $isDreamina = $this->AnimeService->isOverseasBaiduSeedanceModel($model);
                     // 保存原始参考图用于任务记录
                     $videoParams['reference_images'] = $reference_images;
 
@@ -3230,10 +3263,12 @@ class AnimeController extends BaseController
                         // 维护ref_image_url字段(参考图URL,JSON数组,与智帧分支保持一致)
                         $videoParams['ref_image_url'] = json_encode($reference_images, 256);
 
-                        // 参考图上传为素材(百度网关/快快AI),上传失败时同步清理提示词中的<图片N>标记
+                        // 参考图上传为素材(国内百度/海外百度dreamina/快快AI),上传失败时同步清理提示词中的<图片N>标记
                         $reference_image_assets = $isKuaikuai
                             ? $this->AIVideoGenerationService->processReferenceImagesToKuaikuaiAssets($reference_images, $videoParams['prompt'])
-                            : $this->AIVideoGenerationService->processReferenceImagesToSeedance20Assets($reference_images, $videoParams['prompt']);
+                            : ($isDreamina
+                                ? $this->AIVideoGenerationService->processReferenceImagesToBaiduDreaminaAssets($reference_images, $videoParams['prompt'])
+                                : $this->AIVideoGenerationService->processReferenceImagesToSeedance20Assets($reference_images, $videoParams['prompt']));
 
                         // 素材上传失败后提示词可能被清理,同步更新视频参数中的提示词
                         $videoParams['prompt'] = trim($videoParams['prompt']);
@@ -3241,7 +3276,7 @@ class AnimeController extends BaseController
                         $videoParams['reference_image_assets'] = $reference_image_assets;
                     }
 
-                    // 配音音频:快快AI上传为素材;百度/doubao走content audio_url
+                    // 配音音频:快快AI上传为素材;国内百度/海外百度/doubao走content audio_url
                     if ($canUseAudio && $audioUrl) {
                         if ($isKuaikuai) {
                             $reference_audio_assets = $this->AIVideoGenerationService->processReferenceAudiosToKuaikuaiAssets([$audioUrl], $videoParams['prompt']);
@@ -3275,7 +3310,7 @@ class AnimeController extends BaseController
                 } else {
                     // Seedance模型(默认)
                     // 检查是否为 Seedance 2.0 模型,如果是则需要处理配音音频
-                    if ($canUseAudio && in_array($model, ['doubao-seedance-2-0-260128', 'doubao-seedance-2-0-fast-260128', 'baidu-doubao-seedance-2-5-260628', 'baidu-doubao-seedance-2-0-260128', 'baidu-doubao-seedance-2-0-fast-260128', 'baidu-doubao-seedance-2-0-mini-260615'])) {
+                    if ($canUseAudio && in_array($model, ['doubao-seedance-2-0-260128', 'doubao-seedance-2-0-fast-260128', 'baidu-doubao-seedance-2-5-260628', 'baidu-doubao-seedance-2-0-260128', 'baidu-doubao-seedance-2-0-fast-260128', 'baidu-doubao-seedance-2-0-mini-260615', 'baidu-dreamina-seedance-2-0-260128', 'baidu-dreamina-seedance-2-0-fast-260128', 'baidu-dreamina-seedance-2-0-mini-260615', 'baidu-dreamina-seedance-2-5-260628'])) {
                         // 添加配音音频到content中
                         $videoParams['content'][] = [
                             'type' => 'audio_url',

+ 1 - 1
app/Services/PointsService.php

@@ -1351,7 +1351,7 @@ class PointsService
      * 根据图片宽高归一化分辨率档位(1k/2k/4k)
      *
      * 按宽高乘积(面积)分档更准确:各档面积几乎成平方关系——
-     * 1k≈1MP(1024x1024)、2k≈4MP(2048x2048、1600x2848)、3k≈9MP(3072x3072、4096x2304)、4k≈16MP(4096x4096)。
+     * 1k≈1MP(1024x1024)、2k≈4MP(2048x2048、1600x2848)、3k≈9MP(3072x3072、3840x2160)、4k≈16MP(4096x4096)。
      * 目前没有 3k 计费档,3k 尺寸直接按 4k 计费。
      *
      * @param int $width