使用 Nano Banana (Gemini 图像) 生成 AI 背景
高级
这是一个自动化工作流,包含 35 个节点。主要使用 If, Set, Code, Wait, Merge 等节点。 使用Gemini和VideoBGRemover创建带有AI生成背景的视频
前置要求
- •HTTP Webhook 端点(n8n 会自动生成)
- •Google Drive API 凭证
- •可能需要目标 API 的认证凭证
分类
-
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"name": "使用 Nano Banana (Gemini 图像) 生成 AI 背景",
"nodes": [
{
"id": "c7388890-0c23-4122-bd5d-252650bc1bcc",
"name": "📋 概述",
"type": "n8n-nodes-base.stickyNote",
"position": [
-3360,
-144
],
"parameters": {
"width": 520,
"height": 580,
"content": "## 🎨 AI 背景生成"
},
"typeVersion": 1,
"notesTextSize": "large",
"notesBackgroundColor": 4
},
{
"id": "4cea6533-3c98-4416-9590-55d59fa384c1",
"name": "🔑 API 密钥设置",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2784,
-160
],
"parameters": {
"width": 380,
"height": 380,
"content": "## 🔑 API 密钥设置(必需)"
},
"typeVersion": 1
},
{
"id": "e78fbba9-30f1-4195-b186-7b0e1089592f",
"name": "📥 输入",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2240,
-144
],
"parameters": {
"width": 380,
"height": 320,
"content": "## 📥 所需输入"
},
"typeVersion": 1
},
{
"id": "0c554823-6fe3-4ab1-8ff8-ae6ea3d6e369",
"name": "🎨 Nano Banana",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1680,
-144
],
"parameters": {
"width": 380,
"height": 380,
"content": "## 🎨 Nano Banana (Gemini 图像)"
},
"typeVersion": 1
},
{
"id": "c644eeb5-59d2-4423-8ae4-78843e8c17b6",
"name": "🔄 处理",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1120,
-144
],
"parameters": {
"width": 380,
"height": 320,
"content": "## 🔄 处理流程"
},
"typeVersion": 1
},
{
"id": "6cf6aa8c-213e-454b-acc4-86c8331cbb25",
"name": "💾 Google Drive",
"type": "n8n-nodes-base.stickyNote",
"position": [
-560,
-144
],
"parameters": {
"width": 380,
"height": 280,
"content": "## 💾 Google Drive 设置"
},
"typeVersion": 1
},
{
"id": "6961e968-3b00-468d-8109-f9ce3c2ebaa4",
"name": "🚀 使用",
"type": "n8n-nodes-base.stickyNote",
"position": [
16,
-144
],
"parameters": {
"width": 380,
"height": 380,
"content": "## 🚀 使用方法"
},
"typeVersion": 1
},
{
"id": "827a2d53-0d00-492c-b2d4-095bf01a9dc2",
"name": "Webhook 触发器",
"type": "n8n-nodes-base.webhook",
"position": [
-2800,
272
],
"webhookId": "ai-background-gen",
"parameters": {
"path": "ai-background-gen",
"options": {},
"httpMethod": "POST",
"responseMode": "responseNode"
},
"typeVersion": 1.1
},
{
"id": "d0af9917-1f4f-4357-bf89-2ab33bdc329c",
"name": "手动触发器",
"type": "n8n-nodes-base.manualTrigger",
"position": [
-2800,
432
],
"parameters": {},
"typeVersion": 1
},
{
"id": "525d4ab1-81c3-4194-8428-8eba04186dbb",
"name": "部分:Gemini",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2368,
512
],
"parameters": {
"width": 900,
"height": 100,
"content": "## 🎨 GEMINI AI 图像生成部分"
},
"typeVersion": 1,
"notesBackgroundColor": 5
},
{
"id": "2619d740-a101-489c-b2a0-0b6bcd3371e5",
"name": "📸 输入",
"type": "n8n-nodes-base.stickyNote",
"position": [
-3360,
704
],
"parameters": {
"width": 416,
"height": 748,
"content": "## 📸 示例:输入"
},
"typeVersion": 1,
"notesBackgroundColor": 4
},
{
"id": "0e05ad57-00a1-48f6-8a2a-15583cd04750",
"name": "提取 Webhook 数据",
"type": "n8n-nodes-base.set",
"position": [
-2640,
272
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"name": "video_url",
"type": "string",
"value": "={{ $json.body?.video_url ?? $json.video_url }}"
},
{
"name": "background_prompt",
"type": "string",
"value": "={{ $json.body?.background_prompt ?? $json.background_prompt }}"
},
{
"name": "aspect_ratio",
"type": "string",
"value": "={{ $json.body?.aspect_ratio ?? $json.aspect_ratio ?? '1:1' }}"
},
{
"name": "source",
"type": "string",
"value": "webhook"
}
]
}
},
"typeVersion": 3.3
},
{
"id": "e1149727-5f4b-4d18-93c8-2607c069b2f4",
"name": "示例输入(在此编辑)",
"type": "n8n-nodes-base.set",
"position": [
-2640,
432
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"name": "video_url",
"type": "string",
"value": "https://videos.videobgremover.com/public-videos/assets/ai-actor.mp4"
},
{
"name": "background_prompt",
"type": "string",
"value": "A modern minimalist office with floor-to-ceiling windows overlooking a vibrant city skyline at golden hour. Warm sunlight streams through the glass, casting soft shadows on a polished concrete floor. In the background, sleek wooden desks and green plants create a professional yet inviting atmosphere. The lighting is natural and diffused, creating a calm, productive mood. Photorealistic, architectural photography style."
},
{
"name": "aspect_ratio",
"type": "string",
"value": "16:9"
},
{
"name": "source",
"type": "string",
"value": "manual"
}
]
}
},
"typeVersion": 3.3
},
{
"id": "65c2e215-a254-4514-a5bd-c36bd6d344ca",
"name": "合并触发器",
"type": "n8n-nodes-base.merge",
"position": [
-2480,
352
],
"parameters": {
"mode": "append"
},
"typeVersion": 2.1
},
{
"id": "6483a5c1-fd4e-42ee-8ad8-219aded66c30",
"name": "1. 生成背景图像 (Gemini)",
"type": "n8n-nodes-base.httpRequest",
"position": [
-2320,
352
],
"parameters": {
"url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent",
"method": "POST",
"options": {
"response": {
"response": {
"neverError": true,
"responseFormat": "json"
}
}
},
"jsonBody": "={\n \"contents\": [{\n \"parts\": [\n {\"text\": \"{{ $json.background_prompt }}\"}\n ]\n }],\n \"generationConfig\": {\n \"responseModalities\": [\"Image\"],\n \"imageConfig\": {\n \"aspectRatio\": \"{{ $json.aspect_ratio }}\"\n }\n }\n}",
"sendBody": true,
"sendHeaders": true,
"specifyBody": "json",
"headerParameters": {
"parameters": [
{
"name": "x-goog-api-key",
"value": "={{ $vars.GEMINI_KEY }}"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
}
},
"typeVersion": 4.1
},
{
"id": "157c8a70-af96-4353-9fe8-8104d1f2073e",
"name": "提取图像数据",
"type": "n8n-nodes-base.code",
"position": [
-2080,
352
],
"parameters": {
"jsCode": "// Extract base64 image from Gemini response\nconst imageData = $input.item.json.candidates[0].content.parts[0].inlineData.data;\nconst mimeType = $input.item.json.candidates[0].content.parts[0].inlineData.mimeType;\n\n// Convert base64 to binary for temporary storage\nconst buffer = Buffer.from(imageData, 'base64');\n\n// Create a data URL for VideoBGRemover API\nconst dataUrl = `data:${mimeType};base64,${imageData}`;\n\nreturn {\n json: {\n background_image_data: imageData,\n background_image_mime: mimeType,\n background_image_url: dataUrl\n },\n binary: {\n data: {\n data: buffer,\n mimeType: mimeType,\n fileName: 'generated_background.png'\n }\n }\n};"
},
"typeVersion": 2
},
{
"id": "0ba0480a-ace4-447e-8698-1dc854205011",
"name": "2. 保存背景图像到 Drive",
"type": "n8n-nodes-base.googleDrive",
"position": [
-1840,
352
],
"parameters": {
"name": "=ai_bg_{{ $('Merge Triggers').item.json.background_prompt.substring(0, 30).replace(/[^a-zA-Z0-9]/g, '_') }}_{{ new Date().getTime() }}.png",
"driveId": {
"__rl": true,
"mode": "list",
"value": "My Drive"
},
"options": {
"simplifyOutput": true
},
"folderId": {
"__rl": true,
"mode": "list",
"value": "root"
}
},
"typeVersion": 3
},
{
"id": "68810993-3dbf-4f53-a27c-a461653f8f7f",
"name": "3. 将背景图像设为公开",
"type": "n8n-nodes-base.googleDrive",
"position": [
-1600,
352
],
"parameters": {
"fileId": "={{ $json.id }}",
"options": {},
"operation": "share",
"permissionsUi": {
"permissionsValues": {
"role": "reader",
"type": "anyone"
}
}
},
"typeVersion": 3
},
{
"id": "2dd106d4-9f8e-4a22-8da7-c5f245fbf0f5",
"name": "📸 已生成",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2800,
704
],
"parameters": {
"width": 432,
"height": 700,
"content": "## 📸 示例:已生成"
},
"typeVersion": 1,
"notesBackgroundColor": 6
},
{
"id": "6bcc43e4-4de5-4c73-9dba-610e91d0a23f",
"name": "部分:VideoBGRemover",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1360,
512
],
"parameters": {
"width": 1020,
"height": 100,
"content": "## 🎬 VIDEOBGREMOVER 合成部分"
},
"typeVersion": 1,
"notesBackgroundColor": 2
},
{
"id": "639e12d4-7275-4353-9bbd-5a4a62138ada",
"name": "4. 创建任务(上传视频)",
"type": "n8n-nodes-base.httpRequest",
"position": [
-1360,
592
],
"parameters": {
"url": "https://api.videobgremover.com/api/v1/jobs",
"method": "POST",
"options": {
"response": {
"response": {
"neverError": true,
"responseFormat": "json"
}
}
},
"jsonBody": "={ \"video_url\": \"{{ $('Merge Triggers').item.json.video_url }}\" }",
"sendBody": true,
"sendHeaders": true,
"specifyBody": "json",
"headerParameters": {
"parameters": [
{
"name": "X-API-Key",
"value": "={{ $vars.VIDEOBGREMOVER_KEY }}"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
}
},
"typeVersion": 4.1
},
{
"id": "aef3cf73-31dc-429e-9f61-083338ca1520",
"name": "5. 开始合成(AI 背景)",
"type": "n8n-nodes-base.httpRequest",
"position": [
-1120,
592
],
"parameters": {
"url": "=https://api.videobgremover.com/api/v1/jobs/{{ $json.id }}/start",
"method": "POST",
"options": {
"response": {
"response": {
"neverError": true,
"responseFormat": "json"
}
}
},
"jsonBody": "={\n \"background\": {\n \"type\": \"composition\",\n \"composition\": {\n \"template\": \"centered\",\n \"background_type\": \"image\",\n \"background_url\": \"https://drive.google.com/uc?id={{ $('2. Save Background Image to Drive').item.json.id }}\",\n \"export_format\": \"h264\",\n \"export_preset\": \"medium\"\n }\n }\n}",
"sendBody": true,
"sendHeaders": true,
"specifyBody": "json",
"headerParameters": {
"parameters": [
{
"name": "X-API-Key",
"value": "={{ $vars.VIDEOBGREMOVER_KEY }}"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
}
},
"typeVersion": 4.1
},
{
"id": "e3a43a09-01ad-4618-ba17-b16429bfe3b4",
"name": "6. 检查任务状态",
"type": "n8n-nodes-base.httpRequest",
"position": [
-880,
592
],
"parameters": {
"url": "=https://api.videobgremover.com/api/v1/jobs/{{ $('4. Create Job (Upload Video)').item.json.id }}/status",
"options": {
"response": {
"response": {
"neverError": true,
"responseFormat": "json"
}
}
},
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "X-API-Key",
"value": "={{ $vars.VIDEOBGREMOVER_KEY }}"
}
]
}
},
"typeVersion": 4.1
},
{
"id": "249577e0-7159-4945-92fd-ad3a7bfbb9a1",
"name": "是否完成?",
"type": "n8n-nodes-base.if",
"position": [
-640,
592
],
"parameters": {
"options": {},
"conditions": {
"options": {
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "is_completed_condition",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.status }}",
"rightValue": "completed"
}
]
}
},
"typeVersion": 2
},
{
"id": "b0b6b36f-284c-446e-894b-1bacfae40264",
"name": "部分:输出",
"type": "n8n-nodes-base.stickyNote",
"position": [
-400,
512
],
"parameters": {
"width": 840,
"height": 100,
"content": "## 💾 输出部分"
},
"typeVersion": 1,
"notesBackgroundColor": 3
},
{
"id": "4acc452e-2286-4db8-92b0-799fda21f6de",
"name": "7. 下载视频",
"type": "n8n-nodes-base.httpRequest",
"position": [
-400,
752
],
"parameters": {
"url": "={{ $json.processed_video_url }}",
"options": {
"response": {
"response": {
"responseFormat": "file"
}
}
}
},
"typeVersion": 4.1
},
{
"id": "432d20ce-1e25-400c-86a7-789e8447c323",
"name": "8. 上传视频到 Drive",
"type": "n8n-nodes-base.googleDrive",
"position": [
-160,
752
],
"parameters": {
"name": "=ai_bg_video_{{ $('4. Create Job (Upload Video)').item.json.id }}_{{ new Date().getTime() }}.mp4",
"driveId": {
"__rl": true,
"mode": "list",
"value": "My Drive"
},
"options": {
"simplifyOutput": true
},
"folderId": {
"__rl": true,
"mode": "list",
"value": "root"
}
},
"typeVersion": 3
},
{
"id": "ac59da0a-0526-4f25-ab9c-fe42a3a353d1",
"name": "📸 最终",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2240,
704
],
"parameters": {
"width": 320,
"height": 676,
"content": "## 📸 示例:最终"
},
"typeVersion": 1,
"notesBackgroundColor": 4
},
{
"id": "06d9ffa9-5ea1-4f76-b7c0-72ee3f9561a0",
"name": "构建成功响应",
"type": "n8n-nodes-base.set",
"position": [
96,
752
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"name": "final_result",
"type": "object",
"value": "={{ {\n success: true,\n job_id: $('4. Create Job (Upload Video)').item.json.id,\n export_id: $('5. Start Composition (AI Background)').item.json.export_id,\n video: {\n google_drive_id: $('8. Upload Video to Drive').item.json.id,\n google_drive_url: $('8. Upload Video to Drive').item.json.webViewLink,\n download_url: $('6. Check Job Status').item.json.processed_video_url,\n filename: $('8. Upload Video to Drive').item.json.name,\n length_seconds: $('6. Check Job Status').item.json.length_seconds\n },\n background_image: {\n google_drive_id: $('2. Save Background Image to Drive').item.json.id,\n google_drive_url: $('2. Save Background Image to Drive').item.json.webViewLink,\n public_url: 'https://drive.google.com/uc?id=' + $('2. Save Background Image to Drive').item.json.id,\n filename: $('2. Save Background Image to Drive').item.json.name,\n prompt: $('Merge Triggers').item.json.background_prompt,\n aspect_ratio: $('Merge Triggers').item.json.aspect_ratio\n },\n message: 'Video composed with AI-generated background successfully. Both video and background image saved to Google Drive',\n source: $('Merge Triggers').item.json.source\n} }}"
}
]
}
},
"typeVersion": 3.3
},
{
"id": "4c13c1eb-3d12-444d-821a-9cce21a9356f",
"name": "是否失败?",
"type": "n8n-nodes-base.if",
"position": [
-640,
832
],
"parameters": {
"options": {},
"conditions": {
"options": {
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "is_failed_condition",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.status }}",
"rightValue": "failed"
}
]
}
},
"typeVersion": 2
},
{
"id": "710a1000-eda6-4f22-be7c-618f875b2579",
"name": "等待 20 秒",
"type": "n8n-nodes-base.wait",
"position": [
-400,
992
],
"parameters": {
"amount": 20
},
"typeVersion": 1.1
},
{
"id": "afc2bd32-fe3a-4e16-a6ae-2d75575582c8",
"name": "构建错误响应",
"type": "n8n-nodes-base.set",
"position": [
-640,
992
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"name": "final_result",
"type": "object",
"value": "={{ {\n success: false,\n job_id: $('4. Create Job (Upload Video)').item.json.id,\n error: $json.error || 'Video composition with AI background failed',\n status: $json.status,\n message: 'Failed to compose video with AI-generated background',\n source: $('Merge Triggers').item.json.source\n} }}"
}
]
}
},
"typeVersion": 3.3
},
{
"id": "006453e6-d202-4b10-9feb-544b6be77f52",
"name": "来自 Webhook?",
"type": "n8n-nodes-base.if",
"position": [
336,
752
],
"parameters": {
"options": {},
"conditions": {
"options": {
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "is_webhook_condition",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.final_result?.source ?? $json.source }}",
"rightValue": "webhook"
}
]
}
},
"typeVersion": 2
},
{
"id": "a6ba3383-2e3b-4497-8e88-a9d2e96561c1",
"name": "响应 Webhook",
"type": "n8n-nodes-base.respondToWebhook",
"position": [
576,
672
],
"parameters": {
"options": {}
},
"typeVersion": 1.1
},
{
"id": "a30e6cda-335b-4a68-afbd-d492beb28c60",
"name": "手动测试完成",
"type": "n8n-nodes-base.set",
"position": [
576,
832
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"name": "final_result",
"type": "object",
"value": "={{ $json.final_result ?? $json }}"
}
]
}
},
"typeVersion": 3.3
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"connections": {
"Wait 20s": {
"main": [
[
{
"node": "6. Check Job Status",
"type": "main",
"index": 0
}
]
]
},
"Has Failed?": {
"main": [
[
{
"node": "Build Error Response",
"type": "main",
"index": 0
}
],
[
{
"node": "Wait 20s",
"type": "main",
"index": 0
}
]
]
},
"Is Complete?": {
"main": [
[
{
"node": "7. Download Video",
"type": "main",
"index": 0
}
],
[
{
"node": "Has Failed?",
"type": "main",
"index": 0
}
]
]
},
"From Webhook?": {
"main": [
[
{
"node": "Respond to Webhook",
"type": "main",
"index": 0
}
],
[
{
"node": "Manual Test Complete",
"type": "main",
"index": 0
}
]
]
},
"Manual Trigger": {
"main": [
[
{
"node": "Sample Inputs (Edit Here)",
"type": "main",
"index": 0
}
]
]
},
"Merge Triggers": {
"main": [
[
{
"node": "1. Generate Background Image (Gemini)",
"type": "main",
"index": 0
}
]
]
},
"Webhook Trigger": {
"main": [
[
{
"node": "Extract Webhook Data",
"type": "main",
"index": 0
}
]
]
},
"7. Download Video": {
"main": [
[
{
"node": "8. Upload Video to Drive",
"type": "main",
"index": 0
}
]
]
},
"Extract Image Data": {
"main": [
[
{
"node": "2. Save Background Image to Drive",
"type": "main",
"index": 0
}
]
]
},
"6. Check Job Status": {
"main": [
[
{
"node": "Is Complete?",
"type": "main",
"index": 0
}
]
]
},
"Build Error Response": {
"main": [
[
{
"node": "From Webhook?",
"type": "main",
"index": 0
}
]
]
},
"Extract Webhook Data": {
"main": [
[
{
"node": "Merge Triggers",
"type": "main",
"index": 0
}
]
]
},
"Build Success Response": {
"main": [
[
{
"node": "From Webhook?",
"type": "main",
"index": 0
}
]
]
},
"8. Upload Video to Drive": {
"main": [
[
{
"node": "Build Success Response",
"type": "main",
"index": 0
}
]
]
},
"Sample Inputs (Edit Here)": {
"main": [
[
{
"node": "Merge Triggers",
"type": "main",
"index": 1
}
]
]
},
"4. Create Job (Upload Video)": {
"main": [
[
{
"node": "5. Start Composition (AI Background)",
"type": "main",
"index": 0
}
]
]
},
"3. Make Background Image Public": {
"main": [
[
{
"node": "4. Create Job (Upload Video)",
"type": "main",
"index": 0
}
]
]
},
"2. Save Background Image to Drive": {
"main": [
[
{
"node": "3. Make Background Image Public",
"type": "main",
"index": 0
}
]
]
},
"5. Start Composition (AI Background)": {
"main": [
[
{
"node": "6. Check Job Status",
"type": "main",
"index": 0
}
]
]
},
"1. Generate Background Image (Gemini)": {
"main": [
[
{
"node": "Extract Image Data",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
UGC - 截图→Gemini→Sora2→VBR(竖版)
使用Gemini、Sora 2和VideoBGRemover从应用录屏制作UGC广告
If
Set
Code
+8
39 节点Paul Roussel
移除视频背景并在自定义背景上合成(使用Google Drive)
移除视频背景并在自定义视频背景上合成(使用Google Drive)
If
Set
Wait
+7
25 节点Paul Roussel
使用 Google Drive 移除视频背景并合成到自定义图像背景
视频背景移除与图像合成,集成Google Drive
If
Set
Wait
+7
25 节点Paul Roussel
使用AI将Reddit帖子转换为短视频
使用AI将Reddit帖子转换为短视频
If
Set
Code
+11
43 节点Artur
人工智能
在可视化参考库中探索n8n节点
在可视化参考库中探索n8n节点
If
Ftp
Set
+93
113 节点I versus AI
其他
AI智能助手:与Supabase存储和Google Drive文件对话
AI智能助手:与Supabase存储和Google Drive文件对话
If
Set
Wait
+20
62 节点Mark Shcherbakov
工程