Skip to content

This workflow accepts a video via HTTP upload, verifies it’s a valid video, extracts a thumbnail frame at the 5-second mark using FFmpeg (auto-installs a static build if missing), uploads the image to a specified Google Drive folder and returns a structured JSON response containing the new file’s details.

License

Notifications You must be signed in to change notification settings

weblineindia/n8n-Automate-Video-Uploads-to-Thumbnails-with-FFmpeg-and-Google-Drive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

n8n-Automate-Video-Uploads-to-Thumbnails-with-FFmpeg-and-Google-Drive

This n8n workflow accepts a video via HTTP upload, validates it, extracts a thumbnail at the 5-second mark using FFmpeg, uploads it to a Google Drive folder, and responds with structured JSON metadata.
It auto-installs a static FFmpeg build if one is not available.


👤 Who’s It For

  • Marketing / Social Teams → Quickly generate ready-to-publish thumbnails.
  • Developers → Lightweight API-first thumbnail service without extra infra.
  • Agencies / Creators → Centralize standardized thumbnails in shared Drive.

⚙️ How It Works

  1. Accept Video Upload (Webhook)

    • Endpoint: POST /webhook/mediaUpload
    • Receives multipart/form-data with file field media.
    • Response deferred until the final node.
  2. Validate Upload (IF Node)

    • Checks: {{$binary.media.mimeType}} contains video/.
    • Non-video → return HTTP 400 Bad Request.
  3. Persist Upload (Write Binary File)

    • Saves file to /tmp/<originalFilename>.mp4.
  4. Extract Thumbnail (Execute Command)

    • Uses system ffmpeg or downloads static build to /tmp/ffmpeg.
    • Command run:
      ffmpeg -y -ss 5 -i <video> -frames:v 1 -q:v 2 /tmp/thumbnail.jpg
  5. Load Thumbnail (Read Binary File)

    • Reads /tmp/thumbnail.jpg into workflow binary as thumbnail.
  6. Upload to Drive (Google Drive Node)

    • Saves file as <original>-thumb.jpg in target folder.
  7. Respond to Webhook

    • Returns JSON response with file details:
      {
        "id": "drive_file_id",
        "name": "sample-thumb.jpg",
        "mimeType": "image/jpeg",
        "size": 12345,
        "webViewLink": "https://drive.google.com/...",
        "webContentLink": "https://drive.google.com/..."
      }

🛠️ How to Set Up

1. Import Workflow

  • Load the provided workflow JSON into your n8n instance.

2. Google Drive Setup

  • Create or choose a target folder in Drive.
  • Copy its Folder ID.
  • Add Google Drive OAuth2 credentials in n8n.
  • Select the credential in the Drive node and configure the folder.

3. Webhook Setup

  • Endpoint: POST /webhook/mediaUpload
  • Example test with curl:
    curl -X POST https://YOUR-N8N-URL/webhook/mediaUpload \
      -F "media=@/path/to/video.mp4"

4. FFmpeg

  • Nothing to install manually: the Execute Command node auto-installs a static ffmpeg if it’s not present.
  • (Optional) If running n8n in Docker and you want permanence, use an image that includes ffmpeg.

5. Response body

  • The Respond node returns JSON with file metadata. You can customize the fields as needed.

6. (Optional) Non-video branch

  • On the IF node’s false output, add a Respond node with HTTP 400 and a helpful message.

✅ Requirements

  • n8n instance with Execute Command node enabled (self-hosted/container/VM).
  • Outbound network access (to fetch static FFmpeg if not installed).
  • Google Drive OAuth2 credential with permission to the destination folder.
  • Adequate temporary space in /tmp for the uploaded video and generated thumbnail.

🎨 How to Customize

Timestamp

  • Change -ss 5 to another second, or make it dynamic via request param (e.g., timestamp=15).

Multiple Thumbnails

  • Duplicate the FFmpeg + Read steps with -ss 5, -ss 15, -ss 30.
  • Use suffixes like -thumb-5.jpg, -thumb-15.jpg.

File Naming

  • Add upload time or Drive File ID in the file name:
    {{ base + '-' + $now + '-thumb.jpg' }}
    
    

Public sharing: add a Drive → Permission: Create node (Role: reader, Type: anyone) and return webViewLink.

Output target: replace the Drive node with S3 Upload or Zoho WorkDrive (HTTP Request) if needed.

Validation: enforce max file size/MIME whitelist in a small Function node before writing to disk.

Logging: append a row to Google Sheets/Notion with sourceFile, thumbId, size, duration, status.

Add-ons

  • Slack / Teams notification with the uploaded thumbnail link.
  • Image optimization (e.g., convert to WebP or resize variants).
  • Retry & alerts via error trigger workflow.
  • Audit log to a database (e.g., Postgres) for observability.

Use Case Examples

  • CMS ingestion: Editors upload videos; workflow returns a thumbnail URL to store alongside the article.
  • Social scheduling: Upload longform to generate a quick hero image for a post.
  • Client portals: Clients drop raw footage; you keep thumbnails uniform in one Drive folder.

Common troubleshooting

🧰 Common Troubleshooting

Issue Possible Cause Solution
ffmpeg: not found System lacks ffmpeg and static build couldn’t download Ensure outbound HTTPS is allowed; keep auto-installer lines intact; or use a Docker image with ffmpeg pre-installed.
Webhook returns 400 “not a video” Wrong field name or invalid MIME type Upload the file in media field; ensure MIME type is video/*.
Drive upload fails (403) OAuth scope issue or account lacks folder access Reconnect Google Drive credentials; verify destination Folder ID and permissions.
Response missing webViewLink / webContentLink Drive node not returning link fields Enable link fields in the Drive node or construct URLs manually from the returned file ID.
413 Payload Too Large (reverse proxy) Proxy limits on upload size Increase body size limits in your proxy (e.g., set client_max_body_size in Nginx).
Disk full / ENOSPC Large uploads filling /tmp Increase temp storage; add cleanup steps; enforce file size caps and reject oversized files early.
Corrupt or black frame thumbnail FFmpeg timestamp hit a black frame Adjust -ss parameter (e.g., use 1–3 seconds) or move -ss before -i.
Slow extraction Large or remote files; cold FFmpeg install Pre-bundle ffmpeg in Docker image; warm the container; host workflow close to upload source.
Duplicate outputs Same file uploaded multiple times Add a de-duplication check (query Drive for existing <base>-thumb.jpg before upload).

🤝 Need Help?

Looking to extend this workflow? We can help you:

  • Wire the output to S3 or Zoho WorkDrive instead of Google Drive.
  • Generate multiple thumbnails at custom timestamps.
  • Enable public sharing links automatically.
  • Add logging, retry strategies, and monitoring for production.

👉 Contact WeblineIndia Automation Experts to turn this into a robust video asset pipeline.

About

This workflow accepts a video via HTTP upload, verifies it’s a valid video, extracts a thumbnail frame at the 5-second mark using FFmpeg (auto-installs a static build if missing), uploads the image to a specified Google Drive folder and returns a structured JSON response containing the new file’s details.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published