{
  "name": "Clips, voice-over and captions into one MP4 with Coco",
  "nodes": [
    {
      "id": "6f1c2a00-0001-4c1e-9a10-000000000001",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -720,
        -80
      ],
      "parameters": {
        "content": "## Clips, voice-over and captions into one MP4 with Coco\n\nDo you need to join AI clips, a voice-over and captions into one video on n8n Cloud, where you have no Execute Command node and no ffmpeg? This workflow sends your links to the Coco API. You get back one vertical MP4 (1080x1920) with word-by-word captions burned in. Coco writes the captions from the voice-over, so you need no SRT file.\n\n### How it works\n- **Your video** holds the clip links, the voice-over link, an optional music link and an optional title.\n- **Build template and vars** turns them into a Coco template and the values for one render.\n- The first run saves the template in your Coco account. Later runs find it and use it again.\n- **Render the video** starts the render. The loop asks Coco every 10 s until the MP4 is ready.\n- **Your MP4** gives the link. The link works for 7 days.\n\n### Set up (about 5 minutes)\n1. Sign in at https://compositor.video/app/ with Google. The free plan needs no card.\n2. Open **API keys**, make a key and copy it. Coco shows it once.\n3. In n8n, make a **Header Auth** credential called `Coco API key`. Name: `Authorization`. Value: `Bearer sk_live_...`\n4. Select that credential in the four Coco HTTP nodes.\n5. Click **Execute workflow**. The sample links make a 12 s test video.\n\n### Cost\nThe free plan gives 10 render minutes a month and 60 minutes of caption transcription. A 30 s video uses half a minute. A failed render uses nothing. Paid plans start at $19 for 300 minutes: https://compositor.video/#pricing\n\n### Your media\n- Each link starts with `https://` and is public. Google Drive (\"Anyone with the link\") and Dropbox share links work.\n- Use MP3 for the voice-over. Coco does not read FLAC files.\n- Each clip plays for `seconds_per_clip` seconds. Set it to the length of your clips (Kling and Runway clips are 5 s). A shorter clip holds its last frame.\n- The video lasts clips x `seconds_per_clip`. A longer voice-over is cut at the end.\n- The clips play muted, the voice is levelled, and the music plays at 25 %. Change `LOOK` in **Build template and vars**.\n\nSample media: MDN flower clip (CC0), test-videos.co.uk jellyfish, Big Buck Bunny (CC BY 3.0, Blender Foundation), JFK inaugural address (public domain), SoundHelix example song.\n",
        "width": 560,
        "height": 1180,
        "color": 4
      }
    },
    {
      "id": "6f1c2a00-0001-4c1e-9a10-000000000002",
      "name": "Step 1 note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -100,
        -80
      ],
      "parameters": {
        "content": "### 1. Your video\nEdit the JSON in **Your video** and run the workflow from the editor.\n\nOr use the form: activate the workflow and open the form link. Put one clip link on each line.\n",
        "width": 500,
        "height": 760,
        "color": 7
      }
    },
    {
      "id": "6f1c2a00-0001-4c1e-9a10-000000000003",
      "name": "Step 2 note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        440,
        -80
      ],
      "parameters": {
        "content": "### 2. Save the template once\nThe first run saves a template in your Coco account. Its name ends in a hash of the look, so a change to `LOOK` saves a new template on the next run.\n\nYou can open the template in the Coco editor to see the layout.\n",
        "width": 900,
        "height": 760,
        "color": 7
      }
    },
    {
      "id": "6f1c2a00-0001-4c1e-9a10-000000000004",
      "name": "Step 3 note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1380,
        -80
      ],
      "parameters": {
        "content": "### 3. Render and wait\nCoco fetches your links, writes the captions from the voice-over, then renders. A 30 s video takes about a minute.\n\nThe loop asks every 10 s and stops after 15 minutes.\n",
        "width": 700,
        "height": 760,
        "color": 7
      }
    },
    {
      "id": "6f1c2a00-0001-4c1e-9a10-000000000005",
      "name": "Step 4 note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        2120,
        -80
      ],
      "parameters": {
        "content": "### 4. Your MP4\n`video_url` works for 7 days.\n\nConnect your next step here: upload to YouTube, save to Google Drive or post to Slack.\n",
        "width": 420,
        "height": 760,
        "color": 7
      }
    },
    {
      "id": "6f1c2a00-0002-4c1e-9a10-000000000001",
      "name": "Run from the editor",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -40,
        200
      ],
      "parameters": {}
    },
    {
      "id": "6f1c2a00-0002-4c1e-9a10-000000000002",
      "name": "Your video",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        180,
        200
      ],
      "parameters": {
        "mode": "raw",
        "jsonOutput": "{\n  \"clips\": [\n    \"https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4\",\n    \"https://test-videos.co.uk/vids/jellyfish/mp4/h264/720/Jellyfish_720_10s_1MB.mp4\",\n    \"https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/720/Big_Buck_Bunny_720_10s_1MB.mp4\"\n  ],\n  \"voiceover_url\": \"https://raw.githubusercontent.com/ggml-org/whisper.cpp/master/samples/jfk.mp3\",\n  \"music_url\": \"https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3\",\n  \"title\": \"Ask not\",\n  \"seconds_per_clip\": 4\n}\n",
        "options": {}
      }
    },
    {
      "id": "6f1c2a00-0002-4c1e-9a10-000000000003",
      "name": "Or fill in a form",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        -40,
        440
      ],
      "webhookId": "4b8e1f52-7d0a-4c3e-9f61-2a5c8d9e0b13",
      "parameters": {
        "formTitle": "Make a video with Coco",
        "formDescription": "Clips, a voice-over and burned-in captions into one vertical MP4.",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Clip URLs",
              "fieldType": "textarea",
              "placeholder": "One https:// link on each line",
              "requiredField": true
            },
            {
              "fieldLabel": "Voice-over URL",
              "placeholder": "https://.../voice.mp3",
              "requiredField": true
            },
            {
              "fieldLabel": "Music URL",
              "placeholder": "Optional"
            },
            {
              "fieldLabel": "Title",
              "placeholder": "Optional, at most 60 characters"
            },
            {
              "fieldLabel": "Seconds per clip",
              "fieldType": "number",
              "placeholder": "5",
              "requiredField": true
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "6f1c2a00-0002-4c1e-9a10-000000000004",
      "name": "Build template and vars",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        500,
        320
      ],
      "parameters": {
        "jsCode": "// Change the look here. Any change saves a new template on the next run.\nconst LOOK = {\n  width: 1080, height: 1920, fps: 30,\n  captions: { size: 80, edge: 'bottom', color: '#FFFFFF', highlight: '#FFD60A', max_words: 3, max_lines: 2 },\n  title: { size: 72, edge: 'top' },\n  clipSound: 0,\n  musicLevel: 0.25,\n};\n\nconst input = $input.first().json;\nconst urls = v => (Array.isArray(v) ? v : String(v ?? '').split(/[\\s,]+/))\n  .map(s => String(s).trim()).filter(Boolean);\nconst text = v => String(v ?? '').trim();\n\nconst clips = urls(input.clips ?? input['Clip URLs']);\nconst voice = text(input.voiceover_url ?? input['Voice-over URL']);\nconst music = text(input.music_url ?? input['Music URL']);\nconst title = text(input.title ?? input['Title']);\nconst sec = Number(input.seconds_per_clip ?? input['Seconds per clip'] ?? 5);\n\nconst problems = [];\nif (clips.length < 1 || clips.length > 20) problems.push(`Give 1 to 20 clip URLs. You gave ${clips.length}.`);\nif (!voice) problems.push('Give a voice-over URL.');\nfor (const u of [...clips, voice, music].filter(Boolean)) {\n  if (!/^https:\\/\\//.test(u)) problems.push(`Coco fetches https:// addresses only: ${u}`);\n}\nif (!(sec >= 1 && sec <= 30)) problems.push('seconds_per_clip is a number from 1 to 30.');\nif (clips.length * sec > 300) problems.push(`${clips.length} clips x ${sec} s is over the 300 s limit of one video.`);\nif (title.length > 60) problems.push('The title has at most 60 characters.');\nif (problems.length) throw new Error(problems.join(' '));\n\nconst variables = {\n  clips: {\n    type: 'list', min: 1, max: Math.min(20, Math.floor(300 / sec)),\n    section: { start: 0, dur: sec },\n    fields: { video: { type: 'video', required: true } },\n  },\n  voice: { type: 'audio', required: true },\n};\nconst tracks = [\n  { id: 'V1', kind: 'video', clips: [\n    { id: 'shot', kind: 'video', src: '{{clips.video}}', start: 0, dur: sec, gain: LOOK.clipSound },\n  ] },\n  { id: 'C1', kind: 'caption', clips: [\n    { id: 'words', kind: 'caption', src: '{{voice}}', start: 0, dur: sec, ...LOOK.captions },\n  ] },\n  { id: 'A1', kind: 'audio', clips: [\n    { id: 'voice', kind: 'audio', src: '{{voice}}', start: 0, dur: sec, gain: 1, normalize: true },\n  ] },\n];\nconst vars = { clips: clips.map(url => ({ video: { url } })), voice: { url: voice } };\n\nif (music) {\n  variables.music = { type: 'audio', required: true };\n  tracks.push({ id: 'A2', kind: 'audio', clips: [\n    { id: 'music', kind: 'audio', src: '{{music}}', start: 0, dur: sec, gain: LOOK.musicLevel, normalize: true, anim: 'fade_out' },\n  ] });\n  vars.music = { url: music };\n}\nif (title) {\n  variables.title = { type: 'text', max: 60 };\n  tracks.push({ id: 'T1', kind: 'text', clips: [\n    { id: 'title', kind: 'text', src: '{{title}}', start: 0, dur: sec, ...LOOK.title },\n  ] });\n  vars.title = title;\n}\n\nconst template = {\n  canvas: { w: LOOK.width, h: LOOK.height, fps: LOOK.fps, duration: sec },\n  variables,\n  tracks,\n};\n\n// The name carries a hash of the template, so the workflow finds its own saved copy.\nlet h = 0x811c9dc5;\nfor (const ch of JSON.stringify(template)) { h ^= ch.charCodeAt(0); h = Math.imul(h, 0x01000193) >>> 0; }\nconst parts = [`${sec} s per clip`, music && 'music', title && 'title'].filter(Boolean).join(', ');\ntemplate.name = `n8n clips + voice-over + captions (${parts}) #${h.toString(16).padStart(8, '0')}`;\n\nreturn [{ json: { name: template.name, template, vars, seconds: clips.length * sec } }];\n"
      }
    },
    {
      "id": "6f1c2a00-0002-4c1e-9a10-000000000005",
      "name": "Find saved template",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        720,
        320
      ],
      "parameters": {
        "method": "GET",
        "url": "https://api.compositor.video/v1/templates",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {
          "response": {
            "response": {
              "responseFormat": "text",
              "outputPropertyName": "data"
            }
          }
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "cocoApiKey000001",
          "name": "Coco API key"
        }
      }
    },
    {
      "id": "6f1c2a00-0002-4c1e-9a10-000000000006",
      "name": "Pick saved template",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        940,
        320
      ],
      "parameters": {
        "jsCode": "const body = $input.first().json.data;\nconst saved = typeof body === 'string' ? JSON.parse(body) : body;\nconst want = $('Build template and vars').first().json.name;\nconst hit = (saved.templates ?? []).find(t => t.name === want);\nreturn [{ json: { template: hit ? hit.template : '' } }];\n"
      }
    },
    {
      "id": "6f1c2a00-0002-4c1e-9a10-000000000007",
      "name": "Saved already?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1160,
        320
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.template }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ]
        }
      }
    },
    {
      "id": "6f1c2a00-0002-4c1e-9a10-000000000008",
      "name": "Save the template",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1160,
        540
      ],
      "parameters": {
        "method": "POST",
        "url": "https://api.compositor.video/v1/templates",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {},
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($(\"Build template and vars\").first().json.template) }}"
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "cocoApiKey000001",
          "name": "Coco API key"
        }
      }
    },
    {
      "id": "6f1c2a00-0002-4c1e-9a10-000000000009",
      "name": "Render the video",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1440,
        320
      ],
      "parameters": {
        "method": "POST",
        "url": "https://api.compositor.video/v1/renders",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Idempotency-Key",
              "value": "=n8n-{{ $workflow.id }}-{{ $execution.id }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ template: $json.template, vars: $(\"Build template and vars\").first().json.vars }) }}"
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "cocoApiKey000001",
          "name": "Coco API key"
        }
      }
    },
    {
      "id": "6f1c2a00-0002-4c1e-9a10-000000000010",
      "name": "Wait 10 s",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        1660,
        320
      ],
      "webhookId": "9d2c6a71-3e84-4f0b-b5a2-7c1e0f9d4a68",
      "parameters": {
        "amount": 10,
        "unit": "seconds"
      }
    },
    {
      "id": "6f1c2a00-0002-4c1e-9a10-000000000011",
      "name": "Check the render",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1880,
        320
      ],
      "parameters": {
        "method": "GET",
        "url": "=https://api.compositor.video/v1/renders/{{ $(\"Render the video\").first().json.id }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "cocoApiKey000001",
          "name": "Coco API key"
        }
      }
    },
    {
      "id": "6f1c2a00-0002-4c1e-9a10-000000000012",
      "name": "Finished?",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        2100,
        320
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "done",
              "renameOutput": true,
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "s1",
                    "leftValue": "={{ $json.state }}",
                    "rightValue": "succeeded",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              }
            },
            {
              "outputKey": "failed",
              "renameOutput": true,
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "s2",
                    "leftValue": "={{ $json.state }}",
                    "rightValue": "failed",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              }
            },
            {
              "outputKey": "gave up",
              "renameOutput": true,
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "s3",
                    "leftValue": "={{ $runIndex + 1 }}",
                    "rightValue": 90,
                    "operator": {
                      "type": "number",
                      "operation": "gte"
                    }
                  }
                ]
              }
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "still working"
        }
      }
    },
    {
      "id": "6f1c2a00-0002-4c1e-9a10-000000000013",
      "name": "Your MP4",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        2340,
        160
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "o1",
              "name": "video_url",
              "type": "string",
              "value": "={{ $json.outputs[0].url }}"
            },
            {
              "id": "o2",
              "name": "link_expires",
              "type": "string",
              "value": "={{ $json.outputs[0].expires }}"
            },
            {
              "id": "o3",
              "name": "duration_seconds",
              "type": "number",
              "value": "={{ $json.duration }}"
            },
            {
              "id": "o4",
              "name": "render_id",
              "type": "string",
              "value": "={{ $json.id }}"
            }
          ]
        }
      }
    },
    {
      "id": "6f1c2a00-0002-4c1e-9a10-000000000014",
      "name": "Render failed",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        2340,
        360
      ],
      "parameters": {
        "errorMessage": "=Coco render {{ $json.id }} failed. {{ $json.error.code }}: {{ $json.error.message }}"
      }
    },
    {
      "id": "6f1c2a00-0002-4c1e-9a10-000000000015",
      "name": "Gave up waiting",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        2340,
        560
      ],
      "parameters": {
        "errorMessage": "=Render {{ $json.id }} is still {{ $json.state }} after 15 minutes. Read it later with GET https://api.compositor.video/v1/renders/{{ $json.id }}"
      }
    }
  ],
  "connections": {
    "Run from the editor": {
      "main": [
        [
          {
            "node": "Your video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Your video": {
      "main": [
        [
          {
            "node": "Build template and vars",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Or fill in a form": {
      "main": [
        [
          {
            "node": "Build template and vars",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build template and vars": {
      "main": [
        [
          {
            "node": "Find saved template",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find saved template": {
      "main": [
        [
          {
            "node": "Pick saved template",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pick saved template": {
      "main": [
        [
          {
            "node": "Saved already?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Saved already?": {
      "main": [
        [
          {
            "node": "Render the video",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Save the template",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save the template": {
      "main": [
        [
          {
            "node": "Render the video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Render the video": {
      "main": [
        [
          {
            "node": "Wait 10 s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 10 s": {
      "main": [
        [
          {
            "node": "Check the render",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check the render": {
      "main": [
        [
          {
            "node": "Finished?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Finished?": {
      "main": [
        [
          {
            "node": "Your MP4",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Render failed",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Gave up waiting",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait 10 s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  }
}
