Просмотр исходного кода

适应性调整seedance2.0视频生成的API参数

lh 3 месяцев назад
Родитель
Сommit
be7a259b80

+ 27 - 11
app/Http/Controllers/Anime/AnimeController.php

@@ -635,7 +635,10 @@ class AnimeController extends BaseController
                 ];
                 
                 // 如果分镜有图片,作为首帧
-                if (!empty($segment->img_url)) {
+                $hasImage = !empty($segment->img_url);
+                $hasVideo = !empty($segment->video_url);
+                
+                if ($hasImage) {
                     $videoParams['first_frame_url'] = $segment->img_url;
                 }
                 
@@ -648,20 +651,33 @@ class AnimeController extends BaseController
                 ];
                 
                 // 如果有首帧图片,添加到content中
-                if (isset($videoParams['first_frame_url'])) {
-                    $videoParams['content'][] = [
-                        'type' => 'image_url',
-                        'image_url' => [
-                            'url' => $videoParams['first_frame_url'],
-                        ],
-                        'role' => 'first_frame',
-                    ];
+                if ($hasImage) {
+                    if (in_array($model, ['doubao-seedance-2-0-260128', 'doubao-seedance-2-0-fast-260128'])) {
+                        $videoParams['content'][] = [
+                            'type' => 'image_url',
+                            'image_url' => [
+                                'url' => $videoParams['first_frame_url'],
+                            ],
+                            'role' => 'reference_image',
+                        ];
+                    }else {
+                        $videoParams['content'][] = [
+                            'type' => 'image_url',
+                            'image_url' => [
+                                'url' => $videoParams['first_frame_url'],
+                            ],
+                            'role' => 'first_frame',
+                        ];
+                    }
                 }
                 
                 // 获取配音音频URL和时长
                 $audioUrl = $segment->audio_url ?? '';
                 $audioDuration = $segment->audio_duration ?? 0;
                 
+                // 音频传入的前提:必须有至少一张图片或一个视频
+                $canUseAudio = ($hasImage || $hasVideo) && !empty($audioUrl);
+                
                 // 根据模型选择不同的视频生成方法
                 if (strpos($model, 'jimeng') !== false) {
                     // 即梦模型参数调整
@@ -679,7 +695,7 @@ class AnimeController extends BaseController
                     $task = $this->AIVideoGenerationService->createKelingOmniTask($videoParams);
                 } else {
                     // 检查是否为 Seedance 2.0 模型,如果是则需要处理配音音频
-                    if (in_array($model, ['doubao-seedance-2-0-260128', 'doubao-seedance-2-0-fast-260128'])) {
+                    if ($canUseAudio && in_array($model, ['doubao-seedance-2-0-260128', 'doubao-seedance-2-0-fast-260128'])) {
                         // 添加配音音频到content中
                         $videoParams['content'][] = [
                             'type' => 'audio_url',
@@ -693,7 +709,7 @@ class AnimeController extends BaseController
                         $audioPrompt = "全程使用音频1作为视频配音。" . $fullPrompt;
                         $videoParams['prompt'] = $audioPrompt;
                         $videoParams['content'][0]['text'] = $audioPrompt;
-                    }else if ($audioDuration) {
+                    } else if ($audioDuration) {
                         // 有音频时长则需将视频时长设置为比音频时长更长的整数
                         $videoParams['video_duration'] = max(2, min(12, ceil($audioDuration)));   // seedance支持2-12s
                     }

+ 1 - 1
app/Services/AIGeneration/AIVideoGenerationService.php

@@ -450,7 +450,7 @@ class AIVideoGenerationService
             if (isset($extraParams['return_last_frame'])) {
                 $apiParams['return_last_frame'] = $extraParams['return_last_frame'];
             }
-            if (!empty($extraParams['service_tier'])) {
+            if (!empty($extraParams['service_tier']) && !in_array($extraParams['model'], ['doubao-seedance-2-0-260128', 'doubao-seedance-2-0-fast-260128'])) {
                 $apiParams['service_tier'] = $extraParams['service_tier'];
             }
             if (!empty($extraParams['execution_expires_after'])) {

+ 41 - 27
app/Services/Anime/AnimeService.php

@@ -2511,7 +2511,10 @@ class AnimeService
         ];
         
         // 如果分镜有图片,作为首帧
-        if (getProp($segment, 'img_url')) {
+        $hasImage = !empty(getProp($segment, 'img_url'));
+        $hasVideo = !empty(getProp($segment, 'video_url'));
+        
+        if ($hasImage) {
             $videoParams['first_frame_url'] = getProp($segment, 'img_url');
         }
         
@@ -2524,19 +2527,32 @@ class AnimeService
         ];
         
         // 如果有首帧图片,添加到content中
-        if (isset($videoParams['first_frame_url'])) {
-            $videoParams['content'][] = [
-                'type' => 'image_url',
-                'image_url' => [
-                    'url' => $videoParams['first_frame_url'],
-                ],
-                'role' => 'first_frame',
-            ];
+        if ($hasImage) {
+            if (in_array($model, ['doubao-seedance-2-0-260128', 'doubao-seedance-2-0-fast-260128'])) {
+                $videoParams['content'][] = [
+                    'type' => 'image_url',
+                    'image_url' => [
+                        'url' => $videoParams['first_frame_url'],
+                    ],
+                    'role' => 'reference_image',
+                ];
+            }else {
+                $videoParams['content'][] = [
+                    'type' => 'image_url',
+                    'image_url' => [
+                        'url' => $videoParams['first_frame_url'],
+                    ],
+                    'role' => 'first_frame',
+                ];
+            }
         }
         
         // 获取配音音频URL
         $audioUrl = getProp($segment, 'audio_url');
         $audioDuration = getProp($segment, 'audio_duration');
+        
+        // 音频传入的前提:必须有至少一张图片或一个视频
+        $canUseAudio = ($hasImage || $hasVideo) && !empty($audioUrl);
 
         // dd($videoParams);
         
@@ -2555,24 +2571,22 @@ class AnimeService
             $task = $this->aiVideoGenerationService->createKelingOmniTask($videoParams);
         } else {
             // 检查是否为 Seedance 2.0 模型,如果是则需要处理配音音频
-            if ($audioUrl) {
-                if (in_array($model, ['doubao-seedance-2-0-260128', 'doubao-seedance-2-0-fast-260128'])) {
-                    // 添加配音音频到content中
-                    $videoParams['content'][] = [
-                        'type' => 'audio_url',
-                        'audio_url' => [
-                            'url' => $audioUrl,
-                        ],
-                        'role' => 'reference_audio',
-                    ];
-                    
-                    // 优化提示词,增加音频相关描述
-                    $audioPrompt = "全程使用音频1作为视频配音。" . $fullPrompt;
-                    $videoParams['prompt'] = $audioPrompt;
-                    $videoParams['content'][0]['text'] = $audioPrompt;
-                }else if ($audioDuration) {    // 有音频时长则需将视频时长设置为比音频时长更长的整数
-                    $videoParams['video_duration'] = max(2, min(12, ceil($audioDuration)));   // seedance支持2-12s
-                }
+            if ($canUseAudio && in_array($model, ['doubao-seedance-2-0-260128', 'doubao-seedance-2-0-fast-260128'])) {
+                // 添加配音音频到content中
+                $videoParams['content'][] = [
+                    'type' => 'audio_url',
+                    'audio_url' => [
+                        'url' => $audioUrl,
+                    ],
+                    'role' => 'reference_audio',
+                ];
+                
+                // 优化提示词,增加音频相关描述
+                $audioPrompt = "全程使用音频1作为视频配音。" . $fullPrompt;
+                $videoParams['prompt'] = $audioPrompt;
+                $videoParams['content'][0]['text'] = $audioPrompt;
+            } else if ($audioDuration) {    // 有音频时长则需将视频时长设置为比音频时长更长的整数
+                $videoParams['video_duration'] = max(2, min(12, ceil($audioDuration)));   // seedance支持2-12s
             }
             // Seedance模型(默认)
             $task = $this->aiVideoGenerationService->createSeedanceTask($videoParams);